/* Shared styles for the home page and the score keeper. */
:root {
  color-scheme: dark;
  --bg: #0d1120;
  --bg-2: #141a2e;
  --surface: #1a2139;
  --surface-2: #232b48;
  --line: #2f3859;
  --fg: #eef1fb;
  --muted: #98a2c3;
  --accent: #ffb627;
  --accent-2: #ffc95c;
  --accent-fg: #221600;
  --danger: #ff5c63;
  --ok: #34d399;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --shape-outline: rgba(255, 255, 255, .5);
  --radius: 18px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Light theme: follows the system unless the user picked a theme on this device (see js/theme.js). */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f1ec;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #eeebe4;
  --line: #dcd7cc;
  --fg: #171a26;
  --muted: #5f6577;
  --accent: #f5a000;
  --accent-2: #ffb627;
  --accent-fg: #1e1400;
  --danger: #d9363e;
  --ok: #0f9f6e;
  --shadow: 0 8px 24px rgba(40, 30, 10, .12);
  --shape-outline: rgba(0, 0, 0, .55);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f1ec;
    --bg-2: #ffffff;
    --surface: #ffffff;
    --surface-2: #eeebe4;
    --line: #dcd7cc;
    --fg: #171a26;
    --muted: #5f6577;
    --accent: #f5a000;
    --accent-2: #ffb627;
    --accent-fg: #1e1400;
    --danger: #d9363e;
    --ok: #0f9f6e;
    --shadow: 0 8px 24px rgba(40, 30, 10, .12);
    --shape-outline: rgba(0, 0, 0, .55);
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; line-height: 1.15; }
p { margin: 0; }
a { color: inherit; }
[hidden] { display: none !important; }

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Buttons ---------------------------------------------------------------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55em;
  min-height: 50px;
  padding: .7em 1.15em;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--fg);
  font-weight: 650;
  font-size: 1.02rem;
  line-height: 1.2;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: transform .08s ease, background-color .15s ease, border-color .15s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn svg { width: 1.3em; height: 1.3em; flex: none; }

.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-fg); }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); border-color: transparent; color: #fff; }
.btn.big { min-height: 64px; font-size: 1.12rem; border-radius: 16px; }
.btn.small { min-height: 40px; padding: .45em .85em; font-size: .92rem; border-radius: 11px; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }

.icon-btn {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 46px; height: 46px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 26px; height: 26px; }

/* Forms ------------------------------------------------------------------ */
.field { display: grid; gap: 6px; }
.field > span { font-size: .9rem; font-weight: 600; color: var(--muted); }

.input {
  width: 100%;
  min-height: 52px;
  padding: .6em .85em;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg);
  color: var(--fg);
  font-size: 1.08rem; /* >=16px prevents iOS zoom */
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.input::placeholder { color: var(--muted); opacity: .7; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.segmented button {
  appearance: none;
  min-height: 44px;
  padding: .4em .5em;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  touch-action: manipulation;
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  font-weight: 600;
  cursor: pointer;
}
.switch input {
  appearance: none;
  position: relative;
  width: 54px; height: 32px;
  flex: none;
  margin: 0;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background-color .2s;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s;
}
.switch input:checked { background: var(--accent); border-color: transparent; }
.switch input:checked::after { transform: translateX(22px); }
.switch input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Cards -------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.code-text {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  font-weight: 800;
  letter-spacing: .12em;
}

/* Bottom sheets (native <dialog>) ------------------------------------------ */
dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--bg-2);
  color: var(--fg);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .4);
  overscroll-behavior: contain;
}
dialog.sheet[open] { animation: sheet-up .22s cubic-bezier(.2, .9, .3, 1); }
dialog.sheet::backdrop { background: rgba(4, 7, 18, .6); }

@media (min-width: 640px) and (min-height: 600px) {
  dialog.sheet { margin: auto; border-radius: 22px; }
  dialog.sheet[open] { animation-name: sheet-pop; }
}

@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@keyframes sheet-pop { from { transform: scale(.96); opacity: 0; } }

.sheet-body {
  display: grid;
  gap: 18px;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 8px 8px 18px;
  background: var(--bg-2);
}
.sheet-head h2 { flex: 1; min-width: 0; font-size: 1.3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sheet-section { display: grid; gap: 10px; }
.sheet-section > h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* Toast ---------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 24px);
  padding: 10px 10px 10px 18px;
  min-height: 52px;
  border-radius: 14px;
  background: #0a0d18;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  font-weight: 550;
  transform: translate(-50%, 150%);
  opacity: 0;
  pointer-events: none;
  transition: transform .25s cubic-bezier(.2, .9, .3, 1), opacity .2s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-action {
  appearance: none;
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  color: #ffc95c;
  font-weight: 700;
  cursor: pointer;
}

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