/* ==========================================================================
   base.css — foundation: reset, screen system, layout, and the diag panel.
   Mobile-first. Dark neutral palette. System font stack (no web font fetch,
   keeps Phase 1 zero-dependency and fast on GitHub Pages + iframe embeds).
   ========================================================================== */

:root {
  color-scheme: dark;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono",
    Menlo, monospace;

  --color-bg: #14151a;
  --color-bg-raised: #1d1f26;
  --color-bg-card: #24262f;
  --color-border: #34364280;
  --color-text: #e8e9ee;
  --color-text-dim: #9a9caa;
  --color-accent: #5da9ff;
  --color-ok: #3ecf8e;
  --color-fail: #ff6b6b;
  --color-info: #c9a8ff;

  --radius-sm: 6px;
  --radius-md: 12px;
  --touch-min: 44px;
}

/* ---- Reset ------------------------------------------------------------- */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1,
h2,
h3,
p,
ul,
form {
  margin: 0;
}

ul {
  list-style: none;
  padding: 0;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* iOS Safari touch hardening:
   - touch-action: manipulation disables the 300ms double-tap-to-zoom delay on
     taps, so board pits + buttons feel instant and a fast double-tap can't zoom
     the page mid-game.
   - -webkit-tap-highlight-color transparent removes the grey flash iOS paints
     over tapped elements (we provide our own :active affordances). */
button,
input,
.pit,
.store,
[role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

/* ---- Screen show/hide system -------------------------------------------
   Exactly one `.screen` is visible at a time; main.js toggles the `hidden`
   attribute. Native [hidden] already applies display:none, this rule just
   defines the *visible* layout for whichever screen is shown. */

/* iOS Safari: 100vh overcounts by the collapsing URL-bar height, which pushes
   the board/board-stage taller than the visible viewport and causes the whole
   screen to feel "off". dvh (dynamic viewport height) tracks the *actual*
   visible area as the URL bar shows/hides. vh stays as the fallback for
   browsers without dvh support (progressive enhancement — the dvh line simply
   overrides it where supported). */
#app {
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
}

.screen[hidden] {
  display: none;
}

/* ---- Diag panel ---------------------------------------------------------- */

.diag-card {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.diag-title {
  font-size: 1.15rem;
  font-weight: 600;
  padding-top: 0.5rem;
}

.diag-subtitle {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.diag-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.diag-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  grid-template-areas:
    "icon label"
    "detail detail";
  align-items: start;
  gap: 0.15rem 0.5rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.75rem;
}

.diag-row[data-status="ok"] {
  border-color: color-mix(in srgb, var(--color-ok) 45%, var(--color-border));
}

.diag-row[data-status="fail"] {
  border-color: color-mix(in srgb, var(--color-fail) 45%, var(--color-border));
}

.diag-icon {
  grid-area: icon;
  font-size: 1.05rem;
  line-height: 1.4;
}

.diag-label {
  grid-area: label;
  font-weight: 600;
}

.diag-detail {
  grid-area: detail;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-text-dim);
  word-break: break-word;
}

/* ---- Diag chat / echo test ---------------------------------------------- */

.diag-chat {
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.diag-chat-log {
  height: 140px;
  overflow-y: auto;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.diag-chat-line--self {
  color: var(--color-accent);
}

.diag-chat-who {
  color: var(--color-text-dim);
  margin-right: 0.35em;
}

.diag-chat-form {
  display: flex;
  gap: 0.5rem;
}

.diag-chat-input {
  flex: 1;
  min-width: 0;
  min-height: var(--touch-min);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 0.75rem;
}

.diag-btn {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  padding: 0 1rem;
  background: var(--color-accent);
  color: #0b1220;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
}

.diag-btn-secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  align-self: flex-start;
}

.diag-ping-result {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-text-dim);
  min-height: 1.1em;
}

.diag-footer {
  text-align: center;
  color: var(--color-text-dim);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.5rem 0 1.5rem;
}

/* ---- Small screen niceties ---------------------------------------------- */

@media (min-width: 480px) {
  .diag-title {
    font-size: 1.3rem;
  }
}

/* ==========================================================================
   Shared game-UI components (menu / lobby / wait / over screens).
   Added in Phase 4. Diag styles above are untouched.
   ========================================================================== */

/* ==========================================================================
   ARCADE 2000s FLASH-GAME SKIN for the menu / lobby / wait / over screens
   (Task 4). Club Penguin / flash-game direction: azure→royal-blue backdrop,
   chunky glossy white-framed panels with a subtle radial burst, big bold
   outlined italic title, oversized glossy rounded buttons. Pure CSS — no
   images. Palette mirrors docs/default-skin-reference.md + themes.css arcade.
   ========================================================================== */

/* Shared arcade palette (kept local so these screens don't depend on #board's
   theme attribute being present). */
.screen--centered,
#screen-lobby {
  --arc-sky-1: #34c0f4;
  --arc-sky-2: #0f9ee8;
  --arc-sky-3: #0b5fb0;
  --arc-gold-1: #ffe27a;
  --arc-gold-2: #f8c200;
  --arc-gold-3: #d98e00;
  --arc-gold-edge: #a86400;
  --arc-navy: #0a2e5c;
  --arc-frame: #ffffff;
  --arc-frame-edge: #0a4f96;
}

/* Screens that center a single card — now over an azure→royal arcade sky. */
.screen--centered {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(255, 255, 255, 0.25), transparent 60%),
    linear-gradient(180deg, var(--arc-sky-1) 0%, var(--arc-sky-2) 45%, var(--arc-sky-3) 100%);
}

/* Chunky glossy arcade panel used by menu/lobby/wait/over cards. Thick pale
   frame + navy outer edge, big rounded corners, inner top highlight, and a
   faint radial burst behind the content for that flash-game sheen. */
.panel {
  position: relative;
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(255, 255, 255, 0.16), transparent 60%),
    linear-gradient(180deg, #1f2634 0%, #171c28 100%);
  border: 4px solid var(--arc-frame);
  outline: 3px solid var(--arc-frame-edge);
  border-radius: 22px;
  box-shadow:
    0 10px 0 rgba(4, 30, 60, 0.45),
    0 18px 36px rgba(0, 0, 0, 0.45),
    inset 0 3px 0 rgba(255, 255, 255, 0.18);
  padding: 1.4rem 1.25rem 1.25rem;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

/* Subtle diagonal candy-stripe wash on the menu panel only (behind content). */
.menu-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: repeating-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.05) 0 14px,
    rgba(255, 255, 255, 0) 14px 28px);
}
.menu-card > * { position: relative; z-index: 1; }

.app-title {
  font-family: "Lilita One", system-ui, sans-serif;
  font-size: clamp(2.6rem, 13vw, 3.6rem);
  text-align: center;
  color: var(--arc-gold-2);
  letter-spacing: 0.5px;
  /* Bold outlined italic look: navy stroke + stacked drop shadow for depth. */
  -webkit-text-stroke: 2px var(--arc-navy);
  text-shadow:
    0 2px 0 var(--arc-navy),
    0 4px 0 var(--arc-navy),
    0 6px 0 rgba(4, 30, 60, 0.6),
    0 8px 14px rgba(0, 0, 0, 0.5);
  transform: skewX(-8deg) rotate(-1.5deg);
  margin: 0 0 0.1rem;
  paint-order: stroke fill;
}

.app-tagline {
  text-align: center;
  color: #eaf6ff;
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: -0.35rem;
  text-shadow: 0 1px 2px rgba(4, 30, 60, 0.5);
}

/* ---- Form fields --------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  border: 0;
  padding: 0;
  margin: 0;
}
.field-label {
  font-size: 0.82rem;
  font-weight: 800;
  color: #bfe4ff;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 1px rgba(4, 30, 60, 0.5);
}
.field-hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  opacity: 0.8;
}
.text-input {
  min-height: 48px;
  background: #0e1420;
  border: 2px solid #0a4f96;
  border-radius: 12px;
  padding: 0 0.85rem;
  color: var(--color-text);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.45);
}
.text-input::placeholder { color: #7f93ad; }
.text-input:focus-visible {
  outline: 3px solid var(--arc-gold-2, #f8c200);
  outline-offset: 1px;
  border-color: var(--arc-gold-2, #f8c200);
}
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--touch-min);
  font-size: 0.98rem;
  font-weight: 600;
  color: #eaf6ff;
}
.checkbox-field input {
  width: 1.3rem;
  height: 1.3rem;
  accent-color: var(--arc-gold-2, #f8c200);
}
.create-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  padding: 0.95rem;
  background: rgba(10, 79, 150, 0.18);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.08);
}

/* ---- Buttons (chunky glossy arcade pills) -------------------------------- */
.btn {
  min-height: var(--touch-min);
  padding: 0 1.2rem;
  border-radius: 999px;
  border: 3px solid transparent;
  font-family: "Lilita One", system-ui, sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: transform 0.06s ease, filter 0.1s ease;
}
.btn:hover { filter: brightness(1.05); }

/* Primary = oversized glossy GOLD button (the reference's hero button). */
.btn--primary {
  min-height: 52px;
  color: #5a3600;
  border-color: #ffffff;
  background:
    radial-gradient(120% 90% at 50% 12%, rgba(255, 255, 255, 0.75), transparent 55%),
    linear-gradient(180deg, #ffe27a 0%, #f8c200 48%, #e8a000 100%);
  box-shadow:
    0 5px 0 #a86400,
    0 9px 16px rgba(0, 0, 0, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
.btn--primary:active { transform: translateY(4px); box-shadow: 0 1px 0 #a86400, inset 0 2px 0 rgba(255, 255, 255, 0.7); }

/* Secondary = glossy sky-blue pill. */
.btn--secondary {
  color: #eaf6ff;
  border-color: #ffffff;
  background:
    radial-gradient(120% 90% at 50% 12%, rgba(255, 255, 255, 0.45), transparent 55%),
    linear-gradient(180deg, #4fc3f7 0%, #2a95e0 50%, #1c74c4 100%);
  box-shadow:
    0 5px 0 #0a4f96,
    0 9px 16px rgba(0, 0, 0, 0.3),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
  text-shadow: 0 1px 2px rgba(4, 30, 60, 0.6);
}
.btn--secondary:active { transform: translateY(4px); box-shadow: 0 1px 0 #0a4f96, inset 0 2px 0 rgba(255, 255, 255, 0.5); }

.btn--ghost {
  background: transparent;
  color: #eaf6ff;
  border-color: transparent;
  box-shadow: none;
  text-shadow: 0 1px 2px rgba(4, 30, 60, 0.6);
}
.btn--ghost:active { transform: translateY(1px); }

.btn--danger {
  color: #fff;
  border-color: #ffffff;
  background:
    radial-gradient(120% 90% at 50% 12%, rgba(255, 255, 255, 0.45), transparent 55%),
    linear-gradient(180deg, #ff6b6b 0%, #e23b3b 55%, #c22 100%);
  box-shadow:
    0 5px 0 #7d1414,
    0 9px 16px rgba(0, 0, 0, 0.3),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
}
.btn--danger:active { transform: translateY(4px); box-shadow: 0 1px 0 #7d1414, inset 0 2px 0 rgba(255, 255, 255, 0.4); }
.btn--back { padding-left: 0.6rem; box-shadow: none; }
.btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* ---- Theme picker (menu) ------------------------------------------------- */
.theme-picker {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.theme-preview {
  height: 72px;
  border-radius: 16px;
  border: 4px solid var(--tp-edge, #a86e00);
  background: var(--tp-board, radial-gradient(120% 140% at 50% 0%, #ffe066, #f2c400 45%, #d99e00));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.3);
}
.theme-preview .tp-stone {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--tp-stone-outline, #1a1a2e);
  background:
    radial-gradient(circle at 32% 28%, var(--tp-stone-spec, #fff) 0%, transparent 40%),
    radial-gradient(circle at 50% 55%, var(--tp-hue, #e02a2a), color-mix(in srgb, var(--tp-hue, #e02a2a) 70%, #000));
}
.theme-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.theme-row-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #bfe4ff;
  width: 3.5rem;
  flex: 0 0 auto;
  text-shadow: 0 1px 1px rgba(4, 30, 60, 0.5);
}
.swatch-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.swatch {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 3px solid rgba(255, 255, 255, 0.5);
  padding: 0;
  overflow: hidden;
  position: relative;
  box-shadow: 0 3px 0 rgba(4, 30, 60, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.35);
}
.swatch[aria-checked="true"] {
  border-color: var(--arc-gold-2, #f8c200);
  box-shadow: 0 0 0 3px var(--arc-gold-2, #f8c200), 0 3px 0 rgba(4, 30, 60, 0.35);
}
.swatch-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 0.55rem;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  text-align: center;
  padding: 1px 0;
}

/* ---- Lobby (matching arcade skin) ---------------------------------------- */
#screen-lobby {
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(255, 255, 255, 0.22), transparent 60%),
    linear-gradient(180deg, var(--arc-sky-1) 0%, var(--arc-sky-2) 45%, var(--arc-sky-3) 100%);
}
.lobby-wrap {
  max-width: 640px;
  margin: 0 auto;
  min-height: unset;
}
.screen-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.screen-title {
  font-family: "Lilita One", system-ui, sans-serif;
  font-size: 1.9rem;
  color: var(--arc-gold-2, #f8c200);
  transform: skewX(-6deg);
  -webkit-text-stroke: 1.5px var(--arc-navy, #0a2e5c);
  paint-order: stroke fill;
  text-shadow: 0 2px 0 var(--arc-navy, #0a2e5c), 0 4px 8px rgba(0, 0, 0, 0.4);
}
.lobby-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.lobby-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem 0.75rem;
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(255, 255, 255, 0.08), transparent 60%),
    linear-gradient(180deg, #222a3a 0%, #1a2130 100%);
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 0.7rem 0.85rem;
  box-shadow: 0 3px 0 rgba(4, 30, 60, 0.35);
}
.lobby-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}
.lobby-host {
  font-weight: 800;
  font-size: 1.05rem;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.lobby-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.75rem;
  color: var(--color-text-dim);
}
.theme-chip {
  font-size: 0.7rem;
  padding: 0.1em 0.5em;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  color: var(--color-text-dim);
  background: var(--color-bg);
}
.status-chip {
  font-size: 0.7rem;
  padding: 0.1em 0.5em;
  border-radius: 999px;
}
.status-chip--open { color: var(--color-ok); }
.status-chip--playing { color: var(--color-info); }
.lobby-actions {
  display: flex;
  gap: 0.4rem;
}
/* Compact the row action buttons so a lobby row stays tidy (still ≥44px tap). */
.lobby-actions .btn {
  min-height: 44px;
  font-size: 0.95rem;
  padding: 0 1rem;
}
.lobby-actions .btn--primary { min-height: 44px; }
.lobby-empty {
  text-align: center;
  color: var(--color-text-dim);
  padding: 2rem 1rem;
  font-style: italic;
}

/* ---- Wait screen --------------------------------------------------------- */
.wait-card {
  align-items: center;
  text-align: center;
}
.wait-label { color: var(--color-text-dim); font-size: 0.9rem; }
.wait-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--color-text-dim);
  min-height: 1.4em;
}
.wait-elapsed {
  color: var(--color-text-dim);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  opacity: 0.8;
}

/* Retry panel shown when a join times out (see ui.js showWaitingRetry). */
.wait-retry {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
  align-items: center;
}
.wait-retry[hidden] { display: none; }
.wait-retry-msg {
  color: var(--color-text);
  font-size: 0.95rem;
  text-align: center;
}
.wait-retry-actions {
  display: flex;
  gap: 0.6rem;
  width: 100%;
}
.wait-retry-actions .btn { flex: 1; }
.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}

/* Pulsing-dots "thinking" indicator for the waiting screen. Pure CSS, no JS
   timers involved — each dot's animation-delay staggers the pulse. */
.wait-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin: 0;
}
.wait-dots span {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--color-accent);
  opacity: 0.3;
  animation: wait-dot-pulse 1.2s ease-in-out infinite;
}
.wait-dots span:nth-child(2) { animation-delay: 0.2s; }
.wait-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes wait-dot-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .wait-dots span { animation: none; opacity: 0.8; }
}

/* ---- Game over ----------------------------------------------------------- */
.over-card {
  align-items: center;
  text-align: center;
}
.over-banner {
  font-family: "Lilita One", system-ui, sans-serif;
  font-size: clamp(1.8rem, 9vw, 3rem);
  transform: skewX(-6deg);
  text-shadow: 0 3px 0 #0a2e5c;
}
.over-banner--win { color: #ffd54a; }
.over-banner--lose { color: var(--color-text-dim); }
.over-banner--tie { color: var(--color-info); }
.over-score {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: var(--font-mono);
}
.over-resign-note {
  color: var(--color-text-dim);
  font-size: 0.95rem;
  font-style: italic;
}
.over-actions {
  display: flex;
  gap: 0.6rem;
  width: 100%;
}
.over-actions .btn { flex: 1; }
