@font-face {
  font-family: "BOCD Mono Light";
  src: url("fonts/BOCDMono-Light.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "MingLiU";
  src: url("fonts/mingliu-latin.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "DejaVu Sans";
  src: url("fonts/DejaVuSans.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: #fff;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  touch-action: none;
  background: #000;
  container-type: size;
}

#field,
#sprite-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#field {
  z-index: 0;
}

#sprites {
  position: absolute;
  inset: 0;
  z-index: 3;
  container-type: size;
  pointer-events: none;
  touch-action: none;
}

#sprite-canvas {
  pointer-events: none;
  background: transparent;
}

#sprites.live .well,
#sprites.live .action {
  pointer-events: auto;
}

.well {
  position: absolute;
  top: 61.7%;
  height: 21.1%;
  aspect-ratio: 1;
  transform: translateY(-50%);
  border-radius: 50%;
  touch-action: none;
}

#stick-left { left: 9.8%; }
#stick-right { right: 8.8%; }

#btn-mid {
  position: absolute;
  left: 50%;
  top: 82%;
  width: 5.65cqh;
  height: 5.65cqh;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: none;
}

#outlines {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  perspective: 900px;
}

.wire {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(96cqw, 90cqh);
  height: min(96cqw, 90cqh);
  translate: -50% -50%;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
  transform-style: preserve-3d;
}

.wire span {
  position: absolute;
  inset: 9%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
}

#horizon {
  position: absolute;
  left: 20%;
  right: 20%;
  top: 48%;
  z-index: 2;
  height: 1px;
  background: rgba(255, 255, 255, 0.38);
  pointer-events: none;
  transform-origin: center;
}

#draw-guide {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  width: max-content;
  max-width: none;
  margin: 0;
  transform: translate(-50%, -50%);
  color: #fff;
  font-family: "MingLiU", serif;
  font-weight: 400;
  font-size: calc(0.82rem * 1.1);
  line-height: 1;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

#draw-guide[hidden] {
  display: none !important;
}

#guide {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr auto;
  pointer-events: none;
  padding:
    calc(10cqh + env(safe-area-inset-top))
    env(safe-area-inset-right)
    calc(9cqh + env(safe-area-inset-bottom))
    env(safe-area-inset-left);
}

#guide[hidden] {
  display: none !important;
}

#guide p {
  margin: 0;
  width: 100%;
  color: #fff;
  font: 400 clamp(0.72rem, 2.15vw, 1.05rem)/1.2 "BOCD Mono Light", monospace;
  letter-spacing: 0.08em;
  text-align: center;
}

#guide .tl { grid-column: 1; grid-row: 1; }
#guide .tr { grid-column: 2; grid-row: 1; }
#guide .bl { grid-column: 1; grid-row: 3; }
#guide .br { grid-column: 2; grid-row: 3; }

#text-page {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: #000;
}

#text-preview {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: block;
}

#text-input {
  flex: 0 0 auto;
  margin: 0.6rem;
  min-height: 4.8rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid #246;
  border-radius: 2px;
  background: #000;
  color: #b7fbff;
  font: 400 1rem/1.3 "BOCD Mono Light", monospace;
  letter-spacing: 0.06em;
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}

#text-input::placeholder {
  color: rgba(183, 251, 255, 0.55);
  opacity: 1;
}

#text-page[hidden],
#help-page[hidden],
#qr-page[hidden] {
  display: none !important;
}

#qr-page {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: #000;
}

#qr-preview {
  width: 100%;
  height: 100%;
  display: block;
}

#help-page {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  color: #fff;
}

#help-columns {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: start;
  width: 94%;
  font-family: "BOCD Mono Light", monospace;
  font-weight: 400;
  font-style: normal;
  line-height: 1;
  text-transform: uppercase;
}

#help-columns > div {
  min-width: 0;
}

#help-columns p {
  margin: 0;
}

.help-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 1.2em;
  overflow: hidden;
  white-space: nowrap;
  line-height: 1;
}

.help-line span {
  flex: none;
  white-space: pre;
  font-family: "BOCD Mono Light", monospace;
}

.help-line span.ming {
  font-family: "MingLiU", serif;
}

#qr {
  flex: 0 0 auto;
  margin-left: auto;
}

.bar {
  --bar-h: 2.75rem;
  position: relative;
  z-index: 6;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2.6ch;
  min-height: var(--bar-h);
  padding:
    0.35rem
    calc(0.85rem + env(safe-area-inset-right))
    0.35rem
    calc(0.85rem + env(safe-area-inset-left));
  background: #000;
  color: #fff;
  font-family: "BOCD Mono Light", monospace;
  font-size: calc(0.82rem * 1.1);
  font-weight: 400;
  font-style: normal;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#topbar {
  padding-top: calc(0.35rem + env(safe-area-inset-top));
}

#bar {
  padding-bottom: calc(0.35rem + env(safe-area-inset-bottom));
}

.bar button {
  appearance: none;
  position: relative;
  min-height: 0;
  margin: 0;
  padding: 0.14em 0.28em;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  line-height: 1;
}

.bar button::before {
  content: "";
  position: absolute;
  top: -0.7rem;
  bottom: -0.7rem;
  left: -0.75ch;
  right: -0.75ch;
}

.bar button .glyph {
  position: relative;
  display: inline-block;
  line-height: 1;
}

.bar button:disabled {
  opacity: 1;
  color: #fff;
  -webkit-text-fill-color: #fff;
}

.bar button[aria-pressed="true"] {
  background: #fff;
  color: #000;
  -webkit-text-fill-color: #000;
}

.bar button[hidden] {
  display: none;
}

#status {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0 0 0 auto;
  color: #fff;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#error {
  position: absolute;
  inset: 1rem;
  z-index: 3;
  margin: 0;
  color: #fff;
  font: 400 0.95rem/1.4 "BOCD Mono Light", monospace;
}
