/* Sudoku v1.2 — viewport-fit game layout
   Goal: the complete playable interface (board + numbers + tools + new game)
   is visible without scrolling on common phone, tablet, laptop and desktop viewports. */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* ---------- Desktop / large tablet ---------- */
.app-shell {
  width: min(1180px, calc(100% - 24px));
  padding: 12px 0 40px;
}

.hero-copy {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, .8fr);
  gap: 18px;
  align-items: end;
  max-width: none;
  margin: 0 0 10px;
}

.hero-copy .eyebrow {
  display: none;
}

.hero-copy h1 {
  max-width: none;
  margin: 0;
  font-size: clamp(1.25rem, 2.1vw, 1.8rem);
  line-height: 1.08;
  letter-spacing: -.025em;
}

.hero-copy > p:last-child {
  max-width: none;
  margin: 0;
  font-size: .78rem;
  line-height: 1.45;
}

.game-layout {
  grid-template-columns: minmax(0, 560px) minmax(250px, 290px) minmax(180px, 220px);
  gap: 14px;
  justify-content: center;
  align-items: start;
}

.board-panel {
  min-width: 0;
  padding: 10px;
}

/* The board is capped by viewport height, not only viewport width. */
.board-wrap {
  width: min(100%, calc(100dvh - 255px));
  max-width: 560px;
  margin-inline: auto;
}

.game-bar {
  margin-bottom: 8px;
}

.game-bar > div {
  padding: 8px 10px;
}

.progress-track {
  margin-top: 8px;
}

.board-message {
  min-height: 18px;
  margin-top: 6px;
  font-size: .76rem;
}

.control-panel {
  top: 74px;
  padding: 13px;
}

.status-card {
  padding: 12px;
}

.field-label {
  margin-top: 12px;
}

.number-pad {
  margin-top: 12px;
}

.tool-grid {
  margin-top: 9px;
}

.keyboard-card {
  margin-top: 10px;
  padding: 10px;
}

.ad-rail {
  min-height: 470px;
  padding: 16px;
}

.ad-art {
  width: 84px;
  margin: 42px auto 18px;
}

.feature-grid,
.how-to-play {
  margin-top: 16px;
}

@media (max-width: 1120px) {
  .game-layout {
    grid-template-columns: minmax(0, 570px) minmax(250px, 300px);
    max-width: 890px;
    margin-inline: auto;
  }

  .ad-rail {
    display: none;
  }
}

/* ---------- Tablet portrait ---------- */
@media (max-width: 820px) and (min-width: 601px) {
  .site-header {
    min-height: 54px;
    padding: 7px 12px;
  }

  .brand-mark {
    width: 38px;
  }

  .app-shell {
    width: min(720px, calc(100% - 16px));
    padding-top: 6px;
  }

  .hero-copy {
    display: none;
  }

  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
    width: 100%;
    max-width: 680px;
  }

  .board-panel,
  .control-panel {
    width: 100%;
  }

  .board-wrap {
    width: min(calc(100vw - 36px), calc(100dvh - 300px), 620px);
  }

  .control-panel {
    position: static;
    padding: 9px;
  }

  .status-card,
  .keyboard-card,
  .field-label {
    display: none;
  }

  .new-game-row {
    grid-template-columns: 1fr 1fr;
  }

  .number-pad {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 4px;
    margin-top: 7px;
  }

  .number-pad button {
    min-height: 38px;
    aspect-ratio: auto;
  }

  .tool-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
    margin-top: 6px;
  }

  .tool-button,
  .tool-button.wide {
    grid-column: auto;
    min-height: 48px;
  }
}

/* ---------- Phone portrait ---------- */
@media (max-width: 600px) {
  :root {
    --phone-header: 44px;
  }

  html,
  body {
    width: 100%;
    min-width: 0;
  }

  .site-header {
    position: relative;
    min-height: var(--phone-header);
    height: var(--phone-header);
    padding: 4px 7px;
  }

  .brand {
    gap: 7px;
  }

  .brand-mark {
    width: 30px;
    border-radius: 8px;
    font-size: 1rem;
  }

  .brand strong {
    font-size: .84rem;
  }

  .brand small {
    display: none;
  }

  .header-actions {
    gap: 4px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    min-height: 34px;
    border-radius: 9px;
  }

  /* The app is dark-only; the decorative theme control wastes phone space. */
  .theme-toggle {
    display: none;
  }

  .app-shell {
    width: 100%;
    padding: 3px 4px 24px;
  }

  .hero-copy {
    display: none;
  }

  .game-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    gap: 4px;
  }

  .board-panel {
    width: 100%;
    padding: 4px;
    border-radius: 10px;
    box-shadow: none;
  }

  .game-bar {
    gap: 3px;
    margin-bottom: 4px;
  }

  .game-bar > div {
    padding: 4px 6px;
    border-radius: 7px;
  }

  .game-bar .label {
    margin-bottom: 0;
    font-size: .42rem;
    letter-spacing: .08em;
  }

  .game-bar strong {
    font-size: .72rem;
  }

  /* Height-aware square. On short phones the board shrinks before controls disappear. */
  .board-wrap {
    width: min(calc(100vw - 16px), calc(100dvh - 270px));
    max-width: 100%;
    margin-inline: auto;
  }

  .sudoku-board {
    border-width: 2px;
    border-radius: 5px;
  }

  .cell {
    font-size: clamp(.92rem, 6.1vw, 1.45rem);
  }

  .cell.box-right {
    border-right-width: 2px;
  }

  .cell.box-bottom {
    border-bottom-width: 2px;
  }

  .cell.selected {
    box-shadow: inset 0 0 0 2px var(--accent);
  }

  .notes-grid {
    inset: 1px;
    font-size: clamp(.34rem, 2.1vw, .58rem);
  }

  .progress-track {
    height: 3px;
    margin-top: 4px;
  }

  .board-message {
    min-height: 14px;
    margin: 3px 1px 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: .64rem;
  }

  .control-panel {
    position: static;
    width: 100%;
    padding: 4px;
    border-radius: 10px;
    box-shadow: none;
  }

  .status-card,
  .field-label,
  .keyboard-card {
    display: none;
  }

  .new-game-row {
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }

  select,
  .button {
    min-height: 32px;
    height: 32px;
    padding-inline: 8px;
    border-radius: 7px;
    font-size: .78rem;
  }

  .number-pad {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 2px;
    margin-top: 4px;
  }

  .number-pad button {
    min-height: 32px;
    height: 32px;
    aspect-ratio: auto;
    padding: 0;
    border-radius: 6px;
    font-size: .92rem;
  }

  .tool-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
    margin-top: 4px;
  }

  .tool-button,
  .tool-button.wide {
    grid-column: auto;
    min-height: 42px;
    height: 42px;
    border-radius: 7px;
    gap: 0;
  }

  .tool-button > span {
    font-size: .92rem;
    line-height: 1;
  }

  .tool-button small {
    font-size: .55rem;
    line-height: 1.1;
  }

  .tool-button b {
    top: 2px;
    right: 2px;
    padding: 1px 3px;
    font-size: .4rem;
  }

  .feature-grid,
  .how-to-play {
    display: none;
  }

  footer {
    padding: 12px 8px 16px;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-align: center;
  }
}

/* Small / short portrait phones: preserve all controls by dropping nonessential status text. */
@media (max-width: 600px) and (max-height: 700px) and (orientation: portrait) {
  .progress-track,
  .board-message {
    display: none;
  }

  .board-wrap {
    width: min(calc(100vw - 16px), calc(100dvh - 220px));
  }

  .control-panel {
    padding-top: 3px;
  }
}

@media (max-width: 380px) {
  .site-header {
    padding-inline: 5px;
  }

  .app-shell {
    padding-inline: 2px;
  }

  .board-panel,
  .control-panel {
    padding-inline: 2px;
  }

  .board-wrap {
    width: min(calc(100vw - 8px), calc(100dvh - 220px));
  }

  .number-pad button {
    font-size: .84rem;
  }

  .tool-button small {
    font-size: .5rem;
  }
}

/* ---------- Landscape phones and other short, wide screens ---------- */
@media (max-height: 600px) and (min-width: 601px),
       (max-height: 520px) and (orientation: landscape) {
  .site-header {
    position: relative;
    min-height: 40px;
    height: 40px;
    padding: 3px 8px;
  }

  .brand-mark {
    width: 30px;
    border-radius: 8px;
  }

  .brand small,
  .theme-toggle,
  .hero-copy,
  .status-card,
  .field-label,
  .keyboard-card,
  .progress-track,
  .board-message,
  .ad-rail,
  .feature-grid,
  .how-to-play,
  footer {
    display: none;
  }

  .icon-button {
    width: 32px;
    height: 32px;
    min-height: 32px;
  }

  .app-shell {
    width: 100%;
    height: calc(100dvh - 40px);
    padding: 3px 5px;
  }

  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, .82fr);
    gap: 5px;
    align-items: center;
    width: 100%;
    height: 100%;
    max-width: 980px;
    margin-inline: auto;
  }

  .board-panel {
    width: fit-content;
    max-width: 100%;
    padding: 3px;
    justify-self: end;
    box-shadow: none;
  }

  .game-bar {
    margin-bottom: 3px;
  }

  .game-bar > div {
    padding: 3px 5px;
  }

  .board-wrap {
    width: min(52vw, calc(100dvh - 86px));
    max-width: 100%;
  }

  .control-panel {
    position: static;
    width: 100%;
    max-width: 360px;
    padding: 5px;
    box-shadow: none;
  }

  .new-game-row {
    gap: 4px;
  }

  select,
  .button {
    min-height: 32px;
    height: 32px;
    font-size: .76rem;
  }

  .number-pad {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 2px;
    margin-top: 5px;
  }

  .number-pad button {
    min-height: 31px;
    height: 31px;
    aspect-ratio: auto;
    padding: 0;
    font-size: .85rem;
  }

  .tool-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
    margin-top: 5px;
  }

  .tool-button,
  .tool-button.wide {
    grid-column: auto;
    min-height: 44px;
    height: 44px;
  }

  .tool-button small {
    font-size: .55rem;
  }
}

/* Short desktop/laptop viewports: scale the board by height and remove marketing copy. */
@media (min-width: 821px) and (max-height: 820px) {
  .site-header {
    min-height: 58px;
  }

  .app-shell {
    padding-top: 7px;
  }

  .hero-copy {
    display: none;
  }

  .board-wrap {
    width: min(100%, calc(100dvh - 185px));
  }

  .game-layout {
    grid-template-columns: minmax(0, 540px) minmax(245px, 285px) minmax(170px, 210px);
  }

  .control-panel {
    top: 66px;
  }

  .ad-rail {
    min-height: 440px;
  }
}

@media (min-width: 821px) and (max-width: 1120px) and (max-height: 820px) {
  .game-layout {
    grid-template-columns: minmax(0, 540px) minmax(245px, 285px);
  }
}

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