/* Shared design tokens and components for all pages. */

@font-face {
  font-family: 'Fredoka Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url(/fonts/fredoka-latin-ext-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Fredoka Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url(/fonts/fredoka-latin-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: dark;
  --font: 'Fredoka Variable', ui-rounded, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --bg: #15122e;
  --bg-2: #1b1740;
  --surface: #241f4d;
  --surface-2: #2f2963;
  --surface-3: #3b3478;
  --line: rgba(255, 255, 255, 0.1);
  --text: #ffffff;
  --muted: #b9b2e6;
  --faint: #7d76b3;

  --accent: #ffcc33;
  --accent-ink: #2a1d00;
  --accent-2: #ff5c8a;
  --accent-3: #4fd1ff;
  --ok: #2ed47a;
  --ok-ink: #04281a;
  --bad: #ff5a5a;
  --warn: #ff9f1c;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --shadow: 0 10px 30px rgba(5, 3, 20, 0.45);
  --shadow-sm: 0 3px 10px rgba(5, 3, 20, 0.35);
  --canvas-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.06);

  --tap: 44px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

/* Game pages: no scrolling, zooming, selecting or callouts. */
body.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

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

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

a {
  color: var(--accent-3);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.icon {
  flex: none;
  display: block;
}

[hidden] {
  display: none !important;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s var(--ease), background-color 0.15s, opacity 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
}
.btn:hover {
  background: var(--surface-3);
}
.btn:active {
  transform: scale(0.96);
}
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.4;
  pointer-events: none;
}
.btn:focus-visible,
.icon-btn:focus-visible,
.chip:focus-visible {
  outline: 3px solid var(--accent-3);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 0 #c99a12;
}
.btn-primary:hover {
  background: #ffd659;
}
.btn-ok {
  background: var(--ok);
  color: var(--ok-ink);
  box-shadow: 0 4px 0 #1e9a57;
}
.btn-ok:hover {
  background: #4be08e;
}
.btn-bad {
  background: var(--bad);
  color: #fff;
  box-shadow: 0 4px 0 #b73232;
}
.btn-bad:hover {
  background: #ff7070;
}
.btn-ghost {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--line);
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}
.btn-lg {
  min-height: 56px;
  padding: 0 26px;
  font-size: 19px;
}
.btn-block {
  width: 100%;
}

.icon-btn {
  appearance: none;
  border: 0;
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s var(--ease), background-color 0.15s, opacity 0.15s;
  touch-action: manipulation;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}
.icon-btn.active,
.icon-btn[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

.chip {
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 550;
  cursor: pointer;
}
.chip.active,
.chip[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
}

.team-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--team, #888);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
  flex: none;
}

/* ---------- Form fields ---------- */

.field {
  display: grid;
  gap: 6px;
}
.field > span {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
.input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font-size: 17px;
  outline: none;
}
.input:focus {
  border-color: var(--accent-3);
}

/* ---------- Board (shared/board.js) ---------- */

.board-host {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}
.board-frame {
  position: relative;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--canvas-shadow);
  touch-action: none;
}
.board-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- Sheets / dialogs (shared/ui.js) ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 6, 24, 0.55);
  opacity: 0;
  transition: opacity 0.2s;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.sheet-backdrop.show {
  opacity: 1;
}
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100% - 40px - var(--safe-top));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
  padding: 8px 18px calc(16px + var(--safe-bottom));
  transform: translateY(30px);
  transition: transform 0.25s var(--ease);
}
.sheet-backdrop.show .sheet {
  transform: none;
}
.sheet::before {
  content: '';
  display: block;
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: var(--surface-3);
  margin: 2px auto 8px;
  flex: none;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex: none;
}
.sheet-title {
  flex: 1;
  font-size: 21px;
}
.sheet-close {
  margin-right: -8px;
}
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  min-height: 0;
  flex: 1 1 auto;
}
.sheet-text {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 17px;
}
.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex: none;
}
.sheet-actions .btn {
  flex: 1;
}

@media (min-width: 700px) and (min-height: 600px) {
  .sheet-backdrop {
    align-items: center;
  }
  .sheet {
    border-radius: var(--radius-lg);
    padding-bottom: 18px;
    transform: scale(0.96);
  }
  .sheet::before {
    display: none;
  }
}

/* Portrait party monitor (1080 × 1920): host dialogs must be readable from a few steps away. */
@media (min-width: 1000px) and (max-aspect-ratio: 3/4) {
  .display .sheet {
    zoom: 1.6;
  }
}

/* ---------- Toasts ---------- */

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  top: calc(10px + var(--safe-top));
  z-index: 200;
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: min(92vw, 480px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text);
  font-weight: 550;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s, transform 0.25s var(--ease);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: none;
}
.toast-ok {
  background: var(--ok);
  color: var(--ok-ink);
}
.toast-bad {
  background: var(--bad);
}

/* ---------- Connection status pill ---------- */

.conn {
  position: fixed;
  left: 50%;
  width: max-content;
  max-width: calc(100vw - 24px);
  bottom: calc(14px + var(--safe-bottom));
  z-index: 150;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--warn);
  color: #2a1600;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

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