/* 沙池大工地：深色、安靜的控制介面，顏色只留給大按鈕（安全黃）。字型用系統字。 */

:root {
  --bg: #141618;
  --solid: #1e2124;
  --panel: rgba(18, 20, 22, .76);
  --line: #353a3f;
  --text: #ece8df;
  --muted: #a3a8ae;
  --soft: #c9c6bf;
  --yellow: #f2b705;
  --ink: #17181a;
  --warn: #8c2f23;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app { height: 100vh; height: 100dvh; }

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------------------------------------------------------------- pages: home and the plain ones */

.page {
  box-sizing: border-box;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: calc(24px + var(--safe-t)) calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l));
}

.home { justify-content: space-between; }
.title { text-align: center; margin-top: 7vh; }
.title h1 { margin: 0 0 6px; font-size: 36px; letter-spacing: .1em; }
.title p { margin: 0; color: var(--muted); }
.title::after {
  content: "";
  display: block;
  width: 216px;
  height: 10px;
  margin: 18px auto 0;
  border-radius: 3px;
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 10px, var(--ink) 10px 20px);
}

.choices { display: flex; flex-direction: column; gap: 14px; width: min(100%, 340px); }

.big {
  min-height: 60px;
  padding: 0 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--solid);
  font-size: 20px;
  font-weight: 700;
}
.big.primary { border-color: var(--yellow); background: var(--yellow); color: var(--ink); }
.big:disabled { opacity: .6; }

.home-error { min-height: 3em; margin: 0; color: #ffb4a2; font-size: 15px; line-height: 1.5; text-align: center; }

.links { display: flex; gap: 28px; }
.link { padding: 10px; border: 0; background: none; color: var(--muted); font-size: 16px; text-decoration: underline; text-underline-offset: 4px; }

.note { justify-content: center; text-align: center; }
.note h2 { margin: 0; font-size: 26px; }
.note p, .note li { max-width: 30em; color: var(--soft); line-height: 1.7; }
.note ul, .note ol { margin: 0; padding-left: 1.4em; text-align: left; }
.note .big { min-width: 200px; flex: none; }

@media (orientation: landscape) and (max-height: 560px) {
  .home {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "title choices" "links choices";
    align-content: center;
    align-items: center;
    justify-items: center;
    column-gap: 32px;
  }
  .home .title { grid-area: title; margin: 0; }
  .home .choices { grid-area: choices; gap: 10px; }
  .home .links { grid-area: links; }
  .home .big { min-height: 52px; }
}

/* ---------------------------------------------------------------- the play screen, upright */

.play {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: #101112;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.view { position: relative; flex: 1 1 auto; min-height: 0; }
.game-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

.hud-top {
  position: absolute;
  z-index: 3;
  top: calc(8px + var(--safe-t));
  left: calc(8px + var(--safe-l));
  right: calc(8px + var(--safe-r));
  display: grid;
  grid-template-columns: 1fr auto 1fr;          /* the chip stays in the middle whatever is beside it */
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.hud-top > :first-child { justify-self: start; }
.hud-top > :last-child { justify-self: end; }
.hud-group { display: flex; gap: 6px; }
.hud.mute { min-width: 44px; padding: 0 10px; }
.mute svg { width: 22px; height: 22px; }
.mute[aria-pressed="true"] { color: var(--muted); }
.hud, .chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: 10px;
  background: var(--panel);
  font-size: 15px;
}
.hud { min-width: 64px; }
.hud-top .invite[hidden] { display: inline-flex !important; visibility: hidden; }   /* keeps the room chip in the middle */
.hud.armed { background: var(--warn); }
.chip { font-variant-numeric: tabular-nums; letter-spacing: .06em; pointer-events: none !important; }

.notes {
  position: absolute;
  z-index: 3;
  top: calc(56px + var(--safe-t));
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(360px, calc(100% - 16px));
  transform: translateX(-50%);
  pointer-events: none;
}
.notes > * { pointer-events: auto; }
.banner { margin: 0; padding: 6px 16px; border-radius: 999px; background: var(--panel); font-size: 14px; }

/* the first-time help (lesson and first room game): what to do now, under the top bar or (upright, when it would hide
   the circle or the place to go) at the bottom of the picture; an arrow at the edge toward a place out of sight */
.coach {
  position: absolute;
  z-index: 3;
  top: calc(64px + var(--safe-t));
  left: 50%;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1px 10px;
  width: min(360px, calc(100% - 16px));
  padding: 8px 10px 8px 14px;
  border: 2px solid var(--yellow);
  border-radius: 12px;
  background: rgba(20, 22, 24, .9);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  transform: translateX(-50%);
  pointer-events: none;           /* the stick or the picture under it still takes the touch */
}
/* sideways the bottom corners are the stick and the big button: the card stays at the top (coach-view.js too) */
@media (orientation: portrait) { .coach.low { top: auto; bottom: 8px; } }
.coach-step { grid-column: 1; color: var(--yellow); font-size: 12px; font-weight: 700; letter-spacing: .04em; }
.coach-text { grid-column: 1; margin: 0; font-size: 17px; font-weight: 700; line-height: 1.4; }
.coach-close { grid-column: 2; grid-row: 1 / span 2; pointer-events: auto; }
.coach-arrow {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  color: var(--yellow);
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .7));
  pointer-events: none;
}
.coach-arrow svg { display: block; width: 40px; height: 40px; }

/* a new achievement: a note for a few seconds over the top bar of whatever screen is up (taps go through), where it hides
   nothing the game needs */
.toasts {
  position: fixed;
  z-index: 31;
  top: calc(4px + var(--safe-t));
  left: 50%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(320px, calc(100% - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border: 1px solid var(--yellow);
  border-radius: 12px;
  background: #1b1d20;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55);
  animation: toast-in .25s ease-out;
}
.toast-icon { color: var(--yellow); }
.toast-icon svg { width: 22px; height: 22px; }
.toast-words { display: flex; flex-direction: column; }
.toast-words strong { font-size: 15px; line-height: 1.35; }
.toast-words span { color: var(--soft); font-size: 13px; line-height: 1.35; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
.knocks { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.knocks:empty { display: none; }
.knock, .link-box {
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
}
.knock p { flex: 1 1 100%; margin: 0; font-weight: 700; text-align: center; overflow-wrap: anywhere; }
.link-title { flex: 1 1 100%; margin: 0; color: var(--soft); font-size: 14px; text-align: center; }
.link-row { display: flex; gap: 6px; width: 100%; }
.link-text {
  flex: 1;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e0f10;
  font-size: 16px;
  user-select: text;
  -webkit-user-select: text;
}
.small {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--solid);
  font-size: 14px;
  white-space: nowrap;
}
.small.primary { border-color: var(--yellow); background: var(--yellow); color: var(--ink); font-weight: 700; }
.small.quiet { background: transparent; }

.say-panel {
  position: absolute;
  z-index: 4;
  bottom: 8px;
  left: 50%;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 6px;
  width: min(360px, calc(100% - 16px));
  padding: 8px;
  border-radius: 14px;
  background: rgba(18, 20, 22, .9);
  transform: translateX(-50%);
}
.saying, .reaction { border: 1px solid var(--line); border-radius: 10px; background: var(--solid); padding: 0; }
.saying { grid-column: span 4; min-height: 42px; font-size: 15px; }
.reaction { grid-column: span 3; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 52px; }
.reaction svg { width: 26px; height: 26px; }
.reaction .label { color: var(--muted); font-size: 13px; }

.deck {
  position: relative;
  z-index: 2;
  box-sizing: border-box;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  column-gap: 6px;
  height: calc(196px + var(--safe-b));
  padding: 0 8px var(--safe-b);
  border-top: 1px solid #2c3034;
  background: #181a1c;
}

.stick {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  width: min(40vw, 160px);
  aspect-ratio: 1;
  border: 2px solid #3d4248;
  border-radius: 50%;
  background: radial-gradient(circle, #2b2f33 0 54%, #212427 55%);
  touch-action: none;
}
.stick::before {                          /* the four directions */
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 3%, #6c737a 0 3px, transparent 4px),
    radial-gradient(circle at 97% 50%, #6c737a 0 3px, transparent 4px),
    radial-gradient(circle at 50% 97%, #6c737a 0 3px, transparent 4px),
    radial-gradient(circle at 3% 50%, #6c737a 0 3px, transparent 4px);
  pointer-events: none;
}
.stick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46%;
  height: 46%;
  margin: -23% 0 0 -23%;
  border-radius: 50%;
  background: linear-gradient(#e7e2d6, #b9b3a5);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .45);
  pointer-events: none;
}
.stick.held { border-color: var(--yellow); }

.side { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; gap: 6px; }
.round {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 1px solid #3d4248;
  border-radius: 50%;
  background: #23262a;
  touch-action: none;
}
.round svg { width: 22px; height: 22px; }
.round .label { color: #bdbab2; font-size: 13px; line-height: 1.15; }
.round.held { border-color: var(--yellow); background: #393d42; }

.act {
  grid-column: 3;
  grid-row: 1;
  width: min(33vw, 128px);
  aspect-ratio: 1;
  padding: 4px;
  border: 5px solid #8a6800;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  font-size: 26px;
  font-weight: 800;
  line-height: 1.2;
  touch-action: none;
}
.act.held { transform: scale(.94); filter: brightness(.9); }
.act.off { border-color: #2c3034; background: #3a3e42; color: #868b91; }

/* ---------------------------------------------------------------- sideways: the site fills the screen, controls on it */

@media (orientation: landscape) {
  .play { display: block; }
  .view { position: absolute; inset: 0; }
  .deck {
    position: absolute;
    inset: 0;
    display: block;
    height: auto;
    padding: 0;
    border: 0;
    background: none;
    pointer-events: none;
  }
  .deck > * { pointer-events: auto; }
  .stick {
    position: absolute;
    left: calc(18px + var(--safe-l));
    bottom: calc(14px + var(--safe-b));
    width: min(42vh, 156px);
    background: radial-gradient(circle, rgba(43, 47, 51, .7) 0 54%, rgba(28, 31, 34, .62) 55%);
  }
  .act {
    position: absolute;
    right: calc(18px + var(--safe-r));
    bottom: calc(18px + var(--safe-b));
    width: min(33vh, 124px);
  }
  .side {
    position: absolute;
    right: calc(18px + var(--safe-r) + min(33vh, 124px) + 14px);
    bottom: calc(16px + var(--safe-b));
    flex-direction: row;
  }
  .round { background: rgba(32, 35, 39, .82); }
  .say-panel { top: calc(56px + var(--safe-t)); bottom: auto; }
  /* the help card on the left, off the middle where the machine and its circle are */
  .coach { left: calc(8px + var(--safe-l)); width: min(340px, 42%); transform: none; }
}

/* a small phone sideways: the sayings fit between the stick and the big button */
@media (orientation: landscape) and (max-width: 600px) {
  .say-panel { width: 256px; }
  .saying { font-size: 14px; }
}

/* ---------------------------------------------------------------- the cover: connecting, waiting at the door, out */

.overlay {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 11, 12, .55);
}
.overlay.gl-lost { position: fixed; z-index: 40; }          /* over every screen, the share sheet and the knock too */
.card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(320px, 86vw);
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #1c1f22;
  text-align: center;
}
.card p { margin: 0; font-size: 18px; line-height: 1.6; }
