/* ============================================================================
   DANBLE - shell stylesheet.
   Owned by: shell (public/index.html, app.js, net.js, style.css).

   Everything shared lives here: palette, typography, buttons, inputs, pills,
   bars, disks, the screen-transition system and the deep-sea backdrop.
   `game.css` should only carry rules that are specific to the play screen.

   Colours are lifted verbatim from mockups/design/Main.dc.html and mockups/design/Shop.dc.html.
   Sizes that come from src/protocol.js (DISK, ROOM_CODE_LEN, MAX_NAME_LEN) are
   NOT written here - app.js sets them as custom properties at boot so that no
   protocol constant is duplicated. See --disk-own / --disk-centre below.
   ========================================================================= */

:root {
  /* ---------------------------------------------------------- surfaces */
  --bg:            #04131c;   /* page / deepest water                    */
  --bg-panel:      #081f2b;   /* top strip                               */
  --bg-raised:     #0d2937;   /* cards, list rows                        */
  --bg-sunk:       #061a24;   /* inputs, wells                           */
  --line:          #16394b;   /* hairline dividers                       */
  --line-soft:     rgba(255,255,255,.07);
  --scrim:         rgba(4,19,28,.72);

  /* ---------------------------------------------------------- text */
  --text:          #dceef8;
  --text-dim:      #7aa6bd;
  --text-faint:    #5f93ad;
  --text-mute:     #4d7f99;
  --text-ghost:    #33566b;
  --text-off:      #41647a;   /* disabled glyph                          */

  /* ---------------------------------------------------------- accents */
  --teal:          #2dd4bf;
  --teal-bright:   #5eead4;
  --teal-deep:     #0f766e;
  --cyan:          #7fd4ee;   /* icon stroke                             */
  --red:           #ef4a51;
  --red-sunk:      rgba(72,20,26,.95);
  --gold:          #f6c453;
  --gold-deep:     #b8862a;
  --gold-dim:      #6b6247;

  /* ---------------------------------------------------------- disks */
  --disk-face:     #f2f6f9;
  --disk-rim:      #cbd9e3;

  /* ---------------------------------------------------------- controls */
  --btn-face:      #133445;
  --btn-edge:      #2b6a86;
  --btn-face-off:  rgba(12,34,46,.9);
  --btn-edge-off:  #1a3d51;

  /* ---------------------------------------------------------- type */
  --font-display: 'Archivo Black', 'Archivo', system-ui, sans-serif;
  --font-body:    'Archivo', system-ui, -apple-system, sans-serif;
  --fs-label:     11px;
  --ls-label:     .18em;
  --ls-display:   -.01em;

  /* ---------------------------------------------------------- metrics */
  --pad:           22px;      /* screen side gutter, from the mockups    */
  --gap:           14px;
  --tap:           44px;      /* hard floor for every hit target         */
  --thumb:         78px;      /* the bottom-right round button           */
  --node:          58px;      /* a sabotage node in the shop arc         */
  --strip-pad:     18px 22px 16px;
  --dock-h:        132px;
  --bar-h:         6px;

  --r-pill:        999px;
  --r-lg:          18px;
  --r-md:          12px;
  --r-sm:          8px;

  /* ---------------------------------------------------------- depth */
  --shadow-disk:   0 10px 30px rgba(0,0,0,.55),
                   0 0 0 3px var(--disk-rim) inset,
                   0 0 0 6px rgba(255,255,255,.06);
  --shadow-thumb:  0 8px 26px rgba(0,0,0,.6);
  --shadow-node:   0 6px 18px rgba(0,0,0,.55);
  --shadow-lift:   0 10px 28px rgba(0,0,0,.45);
  --glow-teal:     0 8px 30px rgba(45,212,191,.24);

  /* ---------------------------------------------------------- motion */
  --dur-screen:    280ms;
  --dur-fast:      140ms;
  --ease:          cubic-bezier(.22,.7,.24,1);

  /* ---------------------------------------------------------- layers */
  --z-sea:         0;
  --z-screen:      1;
  --z-overlay:     40;
  --z-toast:       60;

  /* ---------------------------------------------------------- insets */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

/* ============================================================ reset ==== */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

/* ============================================================ type ==== */

.disp {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: var(--ls-display);
}

.lab {
  font-size: var(--fs-label);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
  line-height: 1;
}
.lab--faint { color: var(--text-faint); }
.lab--mute  { color: var(--text-mute); }
.lab--ghost { color: var(--text-ghost); }

.num { font-family: var(--font-display); line-height: 1; letter-spacing: var(--ls-display); }

/* ================================================= deep-sea backdrop ==== */

.sea {
  position: fixed;
  inset: 0;
  z-index: var(--z-sea);
  background:
    radial-gradient(130% 78% at 50% -12%, #0d3a52 0%, #08273a 34%, #051a26 62%, var(--bg) 88%),
    var(--bg);
}

/* light shafts falling from the surface */
.sea::before {
  content: '';
  position: absolute;
  inset: -20% -30%;
  background:
    linear-gradient(102deg, transparent 34%, rgba(127,212,238,.055) 40%, transparent 45%),
    linear-gradient(96deg,  transparent 52%, rgba(127,212,238,.040) 57%, transparent 62%),
    linear-gradient(110deg, transparent 68%, rgba(45,212,191,.038) 73%, transparent 79%);
  animation: shafts 26s ease-in-out infinite alternate;
  pointer-events: none;
}

/* suspended particles */
.sea::after {
  content: '';
  position: absolute;
  inset: -40px;
  background-image:
    radial-gradient(circle, rgba(127,212,238,.15) 1px, transparent 1.4px),
    radial-gradient(circle, rgba(45,212,191,.10) 1px, transparent 1.6px);
  background-size: 74px 74px, 121px 121px;
  background-position: 0 0, 26px 40px;
  animation: motes 44s linear infinite;
  pointer-events: none;
}

@keyframes shafts {
  from { transform: translate3d(-3%, 0, 0) skewX(0deg); }
  to   { transform: translate3d(3%, 0, 0)  skewX(-2deg); }
}
@keyframes motes {
  from { background-position: 0 0, 26px 40px; }
  to   { background-position: -40px -240px, -80px -320px; }
}

/* a floor vignette so the dock always has something to sit on */
.sea-floor {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 34vh;
  z-index: var(--z-sea);
  background: linear-gradient(180deg, rgba(4,19,28,0) 0%, rgba(4,19,28,.85) 62%, var(--bg) 100%);
  pointer-events: none;
}

/* ============================================ screens + transitions ==== */

#app {
  position: relative;
  z-index: var(--z-screen);
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  --dir: 1;                 /* 1 = forward, -1 = going back */
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--sat) + 8px) calc(var(--pad) + var(--sar))
           calc(var(--sab) + 18px) calc(var(--pad) + var(--sal));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(0, calc(16px * var(--dir)), 0) scale(.99);
  transition: opacity var(--dur-screen) var(--ease),
              transform var(--dur-screen) var(--ease),
              visibility 0s linear var(--dur-screen);
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition-delay: 50ms, 50ms, 0s;
}

.screen.is-leaving {
  visibility: visible;
  transform: translate3d(0, calc(-16px * var(--dir)), 0) scale(.99);
}

/* the play screen is handed to game.js whole - no shell padding */
.screen--bleed { padding: 0; }

/* ============================================================ layout ==== */

.stack     { display: flex; flex-direction: column; gap: var(--gap); }
.stack--lg { gap: 18px; }
.grow      { flex: 1 1 auto; min-height: 0; }
.center    { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.row       { display: flex; align-items: center; gap: 10px; }
.row--base { align-items: baseline; }
.spread    { justify-content: space-between; }

/* ============================================================ buttons ==== */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 22px;
  border-radius: var(--r-md);
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text);
  background: var(--bg-raised);
  border: 2px solid var(--btn-edge);
  transition: transform var(--dur-fast) var(--ease),
              opacity var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.btn:active:not(:disabled) { transform: translateY(2px) scale(.99); }
.btn:disabled { opacity: .34; cursor: default; }
.btn:focus-visible { outline: 3px solid var(--teal-bright); outline-offset: 3px; }

.btn--lg   { min-height: 66px; font-size: 20px; letter-spacing: .12em; border-radius: var(--r-lg); }
.btn--md   { min-height: 56px; font-size: 17px; letter-spacing: .10em; border-radius: var(--r-lg); }
.btn--full { width: 100%; }

.btn--primary {
  color: #04131c;
  background: linear-gradient(180deg, var(--teal-bright) 0%, var(--teal) 62%, #17b7a4 100%);
  border-color: rgba(94,234,212,.55);
  box-shadow: var(--glow-teal), inset 0 -3px 0 rgba(4,19,28,.22);
}
.btn--primary:disabled { box-shadow: none; }

.btn--ghost {
  background: rgba(19,52,69,.55);
  border-color: var(--btn-edge);
  color: var(--text);
}

.btn--danger {
  background: var(--red-sunk);
  border-color: var(--red);
  color: #ffd9da;
}

.btn--quiet {
  background: none;
  border-color: transparent;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-weight: 600;
  letter-spacing: .06em;
}
.btn--quiet:hover { color: var(--text); }

/* circular icon buttons - the shop thumb and the back chevron */
.btn-round {
  display: grid;
  place-items: center;
  width: var(--thumb);
  height: var(--thumb);
  border-radius: 50%;
  background: var(--btn-face);
  border: 2.5px solid var(--btn-edge);
  box-shadow: var(--shadow-thumb);
  color: var(--cyan);
}
.btn-round--sm { width: var(--tap); height: var(--tap); border-width: 2px; box-shadow: none; }
.btn-round--armed { background: var(--red-sunk); border-color: var(--red); color: #ffd9da; }
.btn-round:active { transform: translateY(2px); }

/* the shop arc node (view uses this too) */
.node {
  position: relative;
  width: var(--node);
  height: var(--node);
  border-radius: 50%;
  background: rgba(19,52,69,.97);
  border: 2px solid var(--btn-edge);
  display: grid;
  place-items: center;
  color: var(--text);
  box-shadow: var(--shadow-node);
}
.node.is-off { background: var(--btn-face-off); border-color: var(--btn-edge-off); color: var(--text-off); }

.node__price {
  position: absolute;
  right: -4px;
  bottom: -3px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--bg);
  border: 1.5px solid var(--gold);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 11px;
  line-height: 1;
  color: var(--gold);
}
.node.is-off .node__price { border-color: var(--gold-dim); color: var(--gold-dim); }

/* ============================================================ pills ==== */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px 8px 12px;
  border-radius: var(--r-pill);
  background: rgba(255,255,255,.05);
  border: 1.5px solid var(--line);
}
.pill--coin {
  background: rgba(246,196,83,.10);
  border-color: rgba(246,196,83,.30);
}
.pill--coin .num { font-size: 26px; color: var(--gold); }

/* ============================================================ bars ==== */

.bar {
  height: var(--bar-h);
  border-radius: var(--r-pill);
  background: var(--line-soft);
  overflow: hidden;
}
.bar__fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--teal);
  transition: width 220ms var(--ease);
}
.bar__fill--them { background: var(--red); }

/* ================================================ strip / dock chrome ==== */

.strip {
  padding: var(--strip-pad);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}

.dock {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--dock-h);
  background: linear-gradient(180deg, rgba(4,19,28,0) 0%, var(--bg) 40%);
  pointer-events: none;
}
.dock > * { pointer-events: auto; }

/* the session scoreboard: name above score, p1 left, p2 right.
   The play screen renders this; the shell only owns the look. */
.scorebar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.scorebar__side { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.scorebar__side--them { align-items: flex-end; text-align: right; }
.scorebar__name {
  font-size: 12px; font-weight: 700; letter-spacing: .04em;
  color: var(--text-dim);
  max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.scorebar__score { font-family: var(--font-display); font-size: 28px; line-height: 1; }
.scorebar__side--you  .scorebar__score { color: var(--teal); }
.scorebar__side--them .scorebar__score { color: var(--red); }

/* ============================================================ disks ==== */

/* The white Dobble disk. Diameter comes from protocol.js DISK via app.js. */
.disk {
  position: relative;
  border-radius: 50%;
  background: var(--disk-face);
  box-shadow: var(--shadow-disk);
  overflow: hidden;
}
.disk--own    { width: var(--disk-own);    height: var(--disk-own); }
.disk--centre { width: var(--disk-centre); height: var(--disk-centre); }

/* face-down: the DANBLE card back fills the disk, no white showing */
.disk--back { background: #061a26; }
.disk--back > svg { width: 100%; height: 100%; }

.card-back { display: block; }
.card-back__word { font-family: var(--font-display); }

/* ============================================================ inputs ==== */

.field { display: flex; flex-direction: column; gap: 10px; }

.input {
  width: 100%;
  min-height: 64px;
  padding: 0 18px;
  border-radius: var(--r-lg);
  background: var(--bg-sunk);
  border: 2px solid var(--line);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: .04em;
  text-align: center;
  user-select: text;
  -webkit-user-select: text;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.input::placeholder { color: var(--text-ghost); font-family: var(--font-body); letter-spacing: .06em; }
.input:focus { outline: none; border-color: var(--teal); background: #082430; }

/* four-digit room code entry: real <input> underneath, cells on top */
.code {
  position: relative;
  display: flex;
  width: 100%;
  gap: 10px;
  justify-content: center;
}
.code__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  background: none;
  font-size: 32px;          /* >=16px so iOS does not zoom the page */
  letter-spacing: 1em;
  text-align: center;
  caret-color: transparent;
  z-index: 2;
  user-select: text;
  -webkit-user-select: text;
}
.code__cell {
  flex: 1 1 0;
  max-width: 82px;
  aspect-ratio: 3 / 4;
  min-height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: var(--bg-sunk);
  border: 2px solid var(--line);
  font-family: var(--font-display);
  font-size: clamp(30px, 9vw, 40px);
  line-height: 1;
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.code__cell:empty::before { content: '\00b7'; color: var(--text-ghost); }
.code.is-focused .code__cell.is-next {
  border-color: var(--teal);
  background: #082430;
  animation: caret 1.1s steps(1) infinite;
}
@keyframes caret { 50% { border-color: var(--btn-edge); } }

/* the same cells, read-only and larger, showing the room code in the lobby */
.code--display { gap: 8px; pointer-events: none; }
.code--display .code__cell {
  max-width: none;
  aspect-ratio: 5 / 6;
  background: rgba(45,212,191,.07);
  border-color: rgba(45,212,191,.28);
  color: var(--teal-bright);
  font-size: clamp(38px, 12vw, 54px);
}

/* ============================================================ lists ==== */

.seat {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 68px;
  padding: 0 18px;
  border-radius: var(--r-lg);
  background: var(--bg-raised);
  border: 1.5px solid var(--line);
}
.seat--empty { background: rgba(13,41,55,.4); border-style: dashed; }
.seat--you   { border-color: rgba(45,212,191,.45); background: rgba(45,212,191,.07); }

.seat__dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 4px rgba(45,212,191,.16);
  flex: 0 0 auto;
}
.seat--empty .seat__dot { background: var(--text-ghost); box-shadow: none; animation: breathe 1.8s var(--ease) infinite; }
@keyframes breathe { 0%,100% { opacity: .3 } 50% { opacity: 1 } }

.seat__name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.seat--empty .seat__name { color: var(--text-ghost); font-weight: 600; }
.seat__tag { flex: 0 0 auto; }

/* ============================================================ result ==== */

.verdict {
  font-family: var(--font-display);
  font-size: clamp(40px, 13vw, 58px);
  line-height: .95;
  letter-spacing: var(--ls-display);
  text-align: center;
}
.verdict--win  { color: var(--teal-bright); text-shadow: 0 6px 34px rgba(45,212,191,.35); }
.verdict--lose { color: var(--red); text-shadow: 0 6px 34px rgba(239,74,81,.28); }

.tally {
  display: flex;
  align-items: stretch;
  gap: 12px;
  width: 100%;
}
.tally__side {
  flex: 1 1 0;
  min-width: 0;
  padding: 16px 14px;
  border-radius: var(--r-lg);
  background: var(--bg-raised);
  border: 1.5px solid var(--line);
  text-align: center;
}
.tally__side--you { border-color: rgba(45,212,191,.4); }
.tally__name {
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tally__score { font-family: var(--font-display); font-size: 46px; line-height: 1; margin-top: 6px; }
.tally__side--you  .tally__score { color: var(--teal); }
.tally__side--them .tally__score { color: var(--text); }
.tally__dash { align-self: center; color: var(--text-ghost); font-family: var(--font-display); font-size: 20px; }

/* ============================================================ wordmark ==== */

.wordmark {
  font-family: var(--font-display);
  font-size: clamp(54px, 18vw, 78px);
  line-height: .9;
  letter-spacing: .01em;
  background: linear-gradient(180deg, #ffffff 0%, var(--teal-bright) 46%, var(--teal) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 10px 34px rgba(45,212,191,.30));
  text-align: center;
}
.wordmark__rule {
  width: 64px; height: 3px; border-radius: var(--r-pill);
  background: linear-gradient(90deg, transparent, var(--teal), transparent);
  margin: 16px auto 12px;
}

/* ============================================================ misc ==== */

.hint { font-size: 13px; line-height: 1.45; color: var(--text-mute); text-align: center; }

.spinner {
  width: 18px; height: 18px; flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid rgba(127,212,238,.25);
  border-top-color: var(--cyan);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* toast strip for connection state and server errors */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--sat) + 12px);
  transform: translate(-50%, -140%);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: var(--r-pill);
  background: rgba(8,31,43,.96);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-lift);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text);
  transition: transform 260ms var(--ease), opacity 260ms var(--ease);
  opacity: 0;
  pointer-events: none;
}
.toast.is-up { transform: translate(-50%, 0); opacity: 1; }
.toast--bad  { border-color: rgba(239,74,81,.55); color: #ffd9da; }
.toast--warn { border-color: rgba(246,196,83,.5);  color: var(--gold); }

/* full-screen overlay - used by the shell for connecting, by the view for
   the 3-2-1 countdown */
.overlay {
  position: absolute;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .screen { transform: none !important; }
}
