/* Mobile one-viewport Sudoku layout for main */
@media (max-width: 600px) {
  html, body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
  }

  body {
    position: fixed;
    inset: 0;
  }

  header {
    width: 100%;
    max-width: 500px;
    height: 52px;
    min-height: 52px;
    padding: 7px 10px;
    grid-template-columns: 72px 1fr 72px;
    flex: 0 0 52px;
  }

  .header-center {
    min-width: 0;
  }

  .header-title {
    font-size: 1.05rem;
    letter-spacing: .12em;
  }

  #timer-display {
    font-size: .58rem;
    margin-top: 0;
  }

  .back-btn, .header-action-btn {
    width: 34px;
    height: 34px;
  }

  .back-btn svg, .header-action-btn svg {
    width: 19px;
    height: 19px;
  }

  #toast {
    top: 60px;
  }

  main {
    width: 100%;
    max-width: none;
    height: calc(100dvh - 52px);
    min-height: 0;
    flex: 1 1 auto;
    padding: 5px 10px max(5px, env(safe-area-inset-bottom, 0px));
    margin: 0;
    gap: 5px;
    justify-content: space-between;
    overflow: hidden;
  }

  #sudoku-board {
    width: min(100%, calc(100dvh - 185px));
    height: min(100%, calc(100dvh - 185px));
    max-width: 390px;
    max-height: calc(100dvh - 185px);
    aspect-ratio: 1;
    flex: 0 1 auto;
    margin: 0 auto;
    border-radius: 12px;
  }

  .sudoku-cell {
    font-size: clamp(15px, 4.7vw, 22px);
    border-width: 1px;
  }

  .tools-bar {
    width: min(100%, 390px);
    max-width: none;
    gap: 5px;
    flex: 0 0 auto;
  }

  .control-action-btn {
    height: 34px;
    min-height: 34px;
    border-radius: 10px;
  }

  .control-action-btn svg {
    width: 18px;
    height: 18px;
  }

  #sudoku-keyboard {
    width: min(100%, 390px);
    max-width: none;
    gap: 3px;
    flex: 0 0 auto;
  }

  .num-key {
    height: clamp(28px, 8vw, 34px);
    min-height: 28px;
    border-radius: 8px;
    font-size: clamp(11px, 3.5vw, 14px);
  }

  .intro-text,
  footer {
    display: none !important;
  }
}

@media (max-width: 380px), (max-height: 650px) and (max-width: 600px) {
  header {
    height: 48px;
    min-height: 48px;
    flex-basis: 48px;
    grid-template-columns: 66px 1fr 66px;
  }

  .header-title {
    font-size: .98rem;
  }

  #timer-display {
    display: none;
  }

  main {
    height: calc(100dvh - 48px);
    padding: 4px 8px max(4px, env(safe-area-inset-bottom, 0px));
    gap: 4px;
  }

  #sudoku-board {
    width: min(100%, calc(100dvh - 165px));
    height: min(100%, calc(100dvh - 165px));
    max-height: calc(100dvh - 165px);
    border-radius: 10px;
  }

  .sudoku-cell {
    font-size: clamp(14px, 4.5vw, 20px);
  }

  .tools-bar {
    gap: 4px;
  }

  .control-action-btn {
    height: 30px;
    min-height: 30px;
    border-radius: 9px;
  }

  #sudoku-keyboard {
    gap: 2px;
  }

  .num-key {
    height: 26px;
    min-height: 26px;
    border-radius: 7px;
    font-size: 11px;
  }
}