/* Sudoku: calm paper-and-ink skin over the shared header, light and dark.
   The play area blocks text selection, callouts and double-tap zoom.
   Mobile first; sizes grow with the screen (vmin) up to a 4K TV. */
[hidden] {
  display: none !important;
}

html {
  font-size: clamp(16px, 2.4vmin, 64px);
}

:root {
  --sd-bg: #eef2f9;
  --sd-surface: #ffffff;
  --sd-ink: #1d2738;
  --sd-muted: #66728a;
  --sd-accent: #3d6bef;
  --sd-accent-soft: #dfe7fd;
  --sd-line: #cbd3e3;
  --sd-line-strong: #34405a;
  --sd-peer: #e8edf7;
  --sd-blocked: #c3cad7;
  --sd-open: #ffffff;
  --sd-same: #3d6bef;
  --sd-same-ink: #ffffff;
  --sd-selected: #ffd96a;
  --sd-user: #2f5ed8;
  --sd-wrong: #d23b3b;
  --sd-wrong-bg: #fde2e2;
  --sd-hinted: #12865a;
  --sd-flash: #ffeeb0;
  --sd-shadow: 0 2px 8px rgba(29, 39, 56, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --sd-bg: #121826;
    --sd-surface: #1d2536;
    --sd-ink: #e8edf6;
    --sd-muted: #93a0b8;
    --sd-accent: #7c9cff;
    --sd-accent-soft: #2a3658;
    --sd-line: #2f3a50;
    --sd-line-strong: #0a0e17;
    --sd-peer: #242e44;
    --sd-blocked: #161c29;
    --sd-open: #3d4c70;
    --sd-same: #7c9cff;
    --sd-same-ink: #0f1522;
    --sd-selected: #7a5f17;
    --sd-user: #9db5ff;
    --sd-wrong: #ff7a7a;
    --sd-wrong-bg: #4a2430;
    --sd-hinted: #5fd3a0;
    --sd-flash: #5a5120;
    --sd-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  }
}

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

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  background: var(--sd-bg);
  color: var(--sd-ink);
}

.game-nav {
  flex: 0 0 auto;
  background: var(--sd-bg);
  border-bottom: none;
  box-shadow: none;
}

.nav-title {
  color: var(--sd-ink);
  letter-spacing: 0.04em;
}

.back-button,
.options-button {
  background: var(--sd-accent);
}

.options-panel-sheet {
  color: #1f2937;
}

.sd-lang-switch {
  display: flex;
  gap: 8px;
}

.sd-chip {
  min-width: 3.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.9rem;
  border: 2px solid #d1d5db;
  border-radius: 0.6rem;
  background: #ffffff;
  color: #1f2937;
  font-weight: 700;
  cursor: pointer;
}

.sd-chip.active {
  border-color: #3d6bef;
  background: #dfe7fd;
}

.sd-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  cursor: pointer;
}

.sd-switch + .sd-switch {
  margin-top: 10px;
}

.sd-switch input {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: #3d6bef;
}

.sd-option-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.sd-option-actions[hidden] {
  display: none;
}

.sd-option-button {
  min-height: 2.75rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font-weight: 600;
  cursor: pointer;
}

.sd-app {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  box-sizing: border-box;
  /* Android bars can cover the bottom even when the safe-area inset is 0. */
  padding: 4px max(24px, env(safe-area-inset-right, 0px))
    max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px))
    max(24px, env(safe-area-inset-left, 0px));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.sd-app button {
  touch-action: manipulation;
}

/* --- Start screen and end card --- */
.sd-start {
  flex: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
}

.sd-card {
  box-sizing: border-box;
  width: min(100%, 28rem);
  padding: 1.4rem 1.2rem;
  border-radius: 1.25rem;
  background: var(--sd-surface);
  box-shadow: var(--sd-shadow);
  text-align: center;
}

.sd-card p {
  margin: 0 0 12px;
  line-height: 1.45;
}

.sd-logo {
  margin: 0 0 8px;
  font-size: clamp(2rem, 9vw, 2.8rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--sd-accent);
}

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

/* A saved match takes the pitch's room on the dashboard. */
.sd-card:has(.sd-resume:not([hidden])) .sd-pitch {
  display: none;
}

.sd-choose {
  font-weight: 800;
}

.sd-resume {
  display: grid;
  gap: 2px;
  width: 100%;
  margin: 0.25rem 0 1rem;
  padding: 0.85rem;
  border: none;
  border-radius: 0.9rem;
  background: var(--sd-accent);
  color: #ffffff;
  cursor: pointer;
}

.sd-resume-name {
  font-size: 1.1rem;
  font-weight: 800;
}

.sd-resume-info {
  font-size: 0.9rem;
  opacity: 0.85;
}

.sd-levels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.sd-level {
  --level: #3bb273;
  display: grid;
  gap: 3px;
  padding: 0.85rem 0.6rem 0.75rem;
  border: 2px solid var(--sd-line);
  border-top: 6px solid var(--level);
  border-radius: 0.9rem;
  background: var(--sd-surface);
  color: var(--sd-ink);
  cursor: pointer;
}

.sd-level[data-level="medium"] {
  --level: #3d8bef;
}

.sd-level[data-level="hard"] {
  --level: #f08a24;
}

.sd-level[data-level="expert"] {
  --level: #d93b5a;
}

.sd-level:hover {
  border-color: var(--level);
}

.sd-level-name {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--level);
}

.sd-level-info,
.sd-level-best {
  font-size: 0.8rem;
  color: var(--sd-muted);
}

.sd-level-best {
  font-weight: 700;
}

.sd-level:active,
.sd-resume:active,
.sd-button:active {
  transform: scale(0.97);
}

.sd-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 0.75rem;
  overflow-y: auto;
  background: rgba(18, 24, 38, 0.45);
}

.sd-overlay-title {
  margin: 0 0 10px;
  font-size: 2rem;
  font-weight: 900;
  color: var(--sd-accent);
}

.sd-end-stats {
  color: var(--sd-muted);
}

.sd-end-best {
  font-weight: 800;
  color: var(--sd-hinted);
}

.sd-actions {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-top: 8px;
}

.sd-button {
  min-width: 13rem;
  min-height: 3rem;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 0.9rem;
  background: var(--sd-accent);
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
}

.sd-button-ghost {
  border: 2px solid var(--sd-line);
  background: transparent;
  color: var(--sd-ink);
}

/* Short landscape phones: the level grid moves beside the title. */
@media (orientation: landscape) and (max-height: 500px) {
  .sd-start .sd-card {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    grid-auto-flow: dense;
    align-items: center;
    column-gap: 1rem;
    width: min(100%, 40rem);
    padding: 0.7rem 1rem;
  }

  .sd-start .sd-card > * {
    grid-column: 1;
  }

  .sd-start .sd-choose,
  .sd-start .sd-levels {
    grid-column: 2;
  }

  .sd-start .sd-choose {
    grid-row: 1;
    margin: 0 0 0.4rem;
  }

  .sd-start .sd-levels {
    grid-row: 2 / span 3;
  }

  .sd-logo {
    font-size: 1.8rem;
  }

  .sd-pitch {
    display: none;
  }

  .sd-resume {
    margin: 0.4rem 0 0;
    padding: 0.5rem;
  }

  .sd-level {
    padding: 0.5rem 0.4rem;
  }

  .sd-level-info {
    display: none;
  }

  .sd-card p {
    margin-bottom: 0.4rem;
  }

  /* End card: title and stats left, buttons right. */
  .sd-end-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    column-gap: 1rem;
    width: min(100%, 40rem);
    padding: 0.8rem 1rem;
  }

  .sd-end-card > * {
    grid-column: 1;
  }

  .sd-end-card > .sd-actions {
    grid-column: 2;
    grid-row: 1 / span 4;
    margin: 0;
  }

  .sd-overlay-title {
    font-size: 1.6rem;
  }
}

/* Desktop and TV, 960x540 up to 3840x2160: the header grows with the
   screen and everything stays 3% away from the edges (TV overscan). */
@media (min-width: 960px) and (min-height: 500px) {
  .game-nav {
    height: auto;
    padding: 3dvh max(3vw, env(safe-area-inset-right, 0px)) 1dvh
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .nav-title {
    font-size: max(1.1rem, 3.4dvh);
  }

  .back-button,
  .options-button {
    width: max(36px, 6dvh);
    height: max(36px, 6dvh);
    font-size: max(1rem, 3dvh);
  }

  .back-button svg,
  .options-button svg {
    width: 50%;
    height: 50%;
  }

  .sd-app {
    padding: 2dvh max(3vw, env(safe-area-inset-right, 0px)) max(40px, 4dvh)
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .sd-card {
    width: min(100%, 32rem);
  }
}

/* TV remote: a thick, high-contrast ring on the focused control. */
html.tv :focus {
  outline: 0.25rem solid #ffb000 !important;
  outline-offset: 0.15rem;
  box-shadow: 0 0 0 0.5rem rgba(29, 39, 56, 0.6);
}

html.tv .sd-cell:focus {
  z-index: 1;
  outline-offset: -0.25rem;
}
