/* Shared design tokens, reset, top bar, buttons, and sheets for every page. */

@font-face {
  font-family: 'Nunito';
  src: url('/shared/fonts/nunito.woff2') format('woff2');
  font-weight: 200 1000;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #efeae0;
  --ink: #1d2433;
  --muted: #5f6878;
  --line: #ddd5c6;
  --accent: #2f5fc4;
  --accent-ink: #ffffff;
  --danger: #c2372f;
  --blue: #2563eb;
  --red: #dc2626;
  --paper: #fbfaf5;
  --paper-grid: rgb(70 110 200 / 0.13);
  --backdrop: rgb(10 14 24 / 0.45);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 6px 18px rgb(0 0 0 / 0.08);

  --radius: 14px;
  --tap: 44px;
  --topbar-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --surface: #1c212c;
    --surface-2: #262c3a;
    --ink: #eef1f6;
    --muted: #9ba4b6;
    --line: #333a4b;
    --accent: #5b8cff;
    --accent-ink: #0d1220;
    --danger: #f0716a;
    --blue: #6aa5ff;
    --red: #ff7a7a;
    --paper: #151a23;
    --paper-grid: rgb(140 170 230 / 0.09);
    --backdrop: rgb(0 0 0 / 0.6);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 18px rgb(0 0 0 / 0.35);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

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

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

h1,
h2 {
  line-height: 1.15;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85em;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Game page layout ---- */

body.game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body.game > main {
  flex: 1;
  min-height: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

body.paper {
  background-color: var(--paper);
  background-image: linear-gradient(var(--paper-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-grid) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: center top;
}

/* ---- Top bar ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 6px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.topbar-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  justify-self: start;
  min-height: var(--tap);
  padding: 0 10px 0 4px;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
  gap: 2px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.icon-btn:active {
  background: var(--surface-2);
}

.topbar svg {
  width: 24px;
  height: 24px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  transition: transform 80ms ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.btn.danger {
  background: var(--danger);
  border-color: transparent;
  color: #fff;
}

.btn.small {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.9rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---- Sheets (bottom dialogs) ---- */

dialog.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: auto;
}

dialog.sheet[open] {
  animation: sheet-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

dialog.sheet::backdrop {
  background: var(--backdrop);
}

@keyframes sheet-in {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

@media (min-width: 600px) {
  dialog.sheet {
    margin: auto;
    border-radius: 22px;
  }
}

.sheet-body {
  margin: 0;
  padding: 20px 20px calc(16px + env(safe-area-inset-bottom));
}

.sheet-title {
  margin: 0 0 12px;
  font-size: 1.35rem;
  font-weight: 900;
}

.sheet-content > :first-child {
  margin-top: 0;
}

.sheet-content ol {
  padding-left: 1.3em;
}

.sheet-content li + li {
  margin-top: 6px;
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.sheet-actions.stack {
  flex-direction: column;
  align-items: stretch;
  margin-top: 4px;
}

/* Segmented choice groups used by setup sheets. */
.seg {
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.seg legend {
  margin-bottom: 6px;
  padding: 0;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--muted);
}

.seg-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seg-opt {
  position: relative;
  flex: 1 1 auto;
}

.seg-opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg-opt span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.seg-opt input:checked + span {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.seg-opt input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Stats ---- */

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.stats-table th,
.stats-table td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.stats-table thead th {
  font-size: 0.8rem;
  color: var(--muted);
}

.stats-table tbody th {
  text-align: left;
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 100;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 160ms, transform 160ms;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

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