/* ナンプレツール固有スタイル */

.difficulty-group {
  margin-top: 20px;
}

.option-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.option-tabs--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.option-tab {
  appearance: none;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.04s ease;
}

.option-tab:hover {
  background: var(--md-sys-color-primary-container);
}

.option-tab:active {
  transform: translateY(1px);
}

.option-tab.is-active {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.game-notice {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: color-mix(in srgb, var(--md-sys-color-primary) 8%, var(--md-sys-color-surface));
  color: var(--md-sys-color-on-surface);
  font-size: 0.875rem;
  line-height: 1.5;
}

.loading-panel {
  margin-top: 24px;
  padding: 28px 16px;
  text-align: center;
}

.loading-panel__text {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9375rem;
  font-weight: 600;
}

.game-panel {
  margin-top: 20px;
}

.game-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid rgba(96, 154, 214, 0.28);
  border-radius: var(--md-sys-shape-corner-medium);
  background:
    radial-gradient(circle at 8% 0%, rgba(63, 196, 255, 0.06), transparent 55%),
    var(--md-sys-color-surface);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.status-pill {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--md-sys-color-primary) 12%, var(--md-sys-color-surface));
  color: var(--md-sys-color-primary);
  font-size: 0.8125rem;
  font-weight: 700;
}

.game-status__timer {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.game-status__timer-label {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8125rem;
  font-weight: 600;
}

#timer-display {
  color: var(--md-sys-color-on-surface);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.clear-banner {
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--success) 35%, var(--md-sys-color-outline-variant));
  border-radius: var(--md-sys-shape-corner-medium);
  background: color-mix(in srgb, var(--success) 10%, var(--md-sys-color-surface));
}

.clear-banner__title {
  margin: 0 0 4px;
  color: var(--success);
  font-size: 1rem;
  font-weight: 700;
}

.clear-banner__detail {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.875rem;
  line-height: 1.5;
}

.board-wrap {
  width: 100%;
  max-width: min(100%, 480px);
  margin: 0 auto 16px;
  padding: 14px;
  box-sizing: border-box;
  border: 1px solid rgba(96, 154, 214, 0.35);
  border-radius: var(--md-sys-shape-corner-large);
  background:
    radial-gradient(circle at 18% 0%, rgba(63, 196, 255, 0.14), transparent 62%),
    radial-gradient(circle at 86% 100%, rgba(122, 157, 255, 0.14), transparent 60%),
    linear-gradient(160deg, #16264a 0%, #101c38 55%, #0d1730 100%);
  box-shadow: 0 14px 34px rgba(28, 52, 96, 0.24), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.np-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid rgba(96, 180, 255, 0.65);
  border-radius: 6px;
  overflow: hidden;
  background: #0d1a36;
  box-shadow:
    0 0 0 1px rgba(63, 196, 255, 0.2),
    inset 0 0 20px rgba(20, 50, 100, 0.25);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.np-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  margin: 0;
  padding: 0;
  border: none;
  border-right: 1px solid rgba(100, 160, 220, 0.28);
  border-bottom: 1px solid rgba(100, 160, 220, 0.28);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  color: #e8f2ff;
  font: inherit;
  font-size: clamp(0.95rem, 3.8vw, 1.35rem);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.np-cell:nth-child(9n) {
  border-right: none;
}

.np-cell:nth-child(n+73) {
  border-bottom: none;
}

.np-cell:nth-child(3n):not(:nth-child(9n)) {
  border-right: 2px solid rgba(120, 200, 255, 0.7);
}

.np-cell:nth-child(n+19):nth-child(-n+27),
.np-cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom: 2px solid rgba(120, 200, 255, 0.7);
}

.np-cell.is-given {
  color: #f4f8ff;
  font-weight: 700;
  cursor: default;
}

.np-cell.is-user {
  color: #6fd6ff;
  font-weight: 600;
}

.np-cell.is-related {
  background: rgba(63, 196, 255, 0.1);
}

.np-cell.is-same-num {
  background: rgba(63, 196, 255, 0.2);
}

.np-cell.is-selected {
  background: rgba(63, 196, 255, 0.28);
  box-shadow:
    inset 0 0 0 2px #3fc4ff,
    0 0 10px rgba(63, 196, 255, 0.35);
  z-index: 1;
}

.np-cell.is-error {
  color: #ff8aad;
}

.np-cell.is-conflict {
  color: #ff8aad;
}

.np-cell.is-hint {
  color: #ffc774;
}

.np-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
  pointer-events: none;
}

.np-notes span {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(180, 210, 255, 0.75);
  font-size: clamp(0.45rem, 2vw, 0.65rem);
  font-weight: 500;
  line-height: 1;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
  max-width: min(100%, 480px);
  margin: 0 auto 16px;
}

.numpad__btn {
  appearance: none;
  min-height: 48px;
  padding: 8px 0;
  border: 1px solid rgba(96, 154, 214, 0.35);
  border-radius: var(--md-sys-shape-corner-medium);
  background:
    radial-gradient(circle at 50% 0%, rgba(63, 196, 255, 0.08), transparent 70%),
    var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: inherit;
  font-size: 1.125rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.04s ease;
}

.numpad__btn:hover {
  background: var(--md-sys-color-primary-container);
  border-color: rgba(63, 196, 255, 0.45);
}

.numpad__btn:active {
  transform: translateY(1px);
}

.numpad__btn.is-active {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: 0 0 12px rgba(63, 196, 255, 0.35);
}

.game-controls {
  max-width: min(100%, 480px);
  margin-left: auto;
  margin-right: auto;
}

.game-controls .btn {
  flex: 1 1 calc(50% - 8px);
  min-width: 7.5rem;
  justify-content: center;
}

#note-btn.is-active {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

@media (max-width: 480px) {
  .board-wrap {
    max-width: 100%;
  }

  .numpad {
    gap: 4px;
  }

  .numpad__btn {
    min-height: 44px;
    font-size: 1rem;
  }

  .game-controls .btn {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
  }
}

/* 共通プレイ画面。設定・盤面・入力をひとつの中央領域に収める。 */
html.gs-playing .np-screen {
  --md-sys-color-on-surface: var(--play-text);
  --md-sys-color-on-surface-variant: var(--play-text-muted);
  --md-sys-color-outline-variant: var(--play-border);
  --md-sys-color-surface: var(--play-hud-bg);
  --md-sys-color-primary: var(--play-accent);
  --md-sys-color-primary-container: var(--play-btn-hover);
  display: block;
}
html.gs-playing .np-screen > * { width: 100%; max-width: 560px; margin-inline: auto; }
html.gs-playing .np-screen > .gs-bar { margin-bottom: 10px; }
html.gs-playing .np-screen .option-tab { min-height: 44px; }
html.gs-playing #setup-section .field-label { color: var(--play-text-muted); }
html.gs-playing .np-screen .option-tab.is-active {
  border-color: var(--play-accent);
  background: color-mix(in srgb, var(--play-accent) 18%, var(--play-hud-bg));
  color: var(--play-accent);
}
html.gs-playing .np-screen .option-tab:focus-visible {
  outline: 2px solid var(--play-accent);
  outline-offset: 2px;
}
html.gs-playing .numpad__btn.is-active { color: var(--play-bg); }
html.gs-playing #setup-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px 12px;
  margin-bottom: 12px;
}
html.gs-playing #setup-section .difficulty-group { margin: 0; }

html.gs-playing #setup-section .field-label { margin: 0 0 4px; font-size: .8125rem; }
html.gs-playing .np-screen .option-tabs { gap: 6px; }
html.gs-playing .np-screen .option-tab { padding: 6px; }
html.gs-playing .np-screen .option-tab:disabled { opacity: .6; cursor: wait; }
html.gs-playing .np-game:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 8px;
  margin-top: 0;
}
html.gs-playing .game-status {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 0;
  width: 100%;
  margin: 0;
  padding: 8px;
  border: 1px solid var(--play-border);
  border-radius: var(--md-sys-shape-corner-medium);
  background: color-mix(in srgb, var(--play-hud-bg) 88%, transparent);
}
html.gs-playing .status-pill { color: var(--play-text); background: none; }
html.gs-playing .np-difficulty {
  position: relative;
  flex: 0 0 auto;
  width: max-content;
  color: var(--play-text-muted);
  font-size: .8125rem;
  font-weight: 600;
}
html.gs-playing .np-difficulty summary {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  white-space: nowrap;
  cursor: pointer;
  list-style: none;
}
html.gs-playing .np-difficulty summary::-webkit-details-marker { display: none; }
html.gs-playing #difficulty-label { color: var(--play-text); }
html.gs-playing .np-difficulty summary:focus-visible {
  outline: 2px solid var(--play-accent);
  outline-offset: 2px;
}
html.gs-playing .np-difficulty__list {
  position: absolute;
  top: 100%;
  left: -1px;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: min(300px, calc(100vw - 48px));
  min-width: 100%;
  padding: 10px;
  border: 1px solid var(--play-border);
  border-radius: 0 0 var(--md-sys-shape-corner-medium) var(--md-sys-shape-corner-medium);
  background: var(--play-hud-bg);
  box-shadow: 0 12px 24px rgba(0, 0, 0, .35);
}
@media (max-width: 400px) {
  html.gs-playing .game-status { gap: 0; padding: 4px; }
  html.gs-playing .np-difficulty summary { gap: 4px; font-size: .75rem; }
  html.gs-playing .game-status .game-status__timer { gap: 4px; padding-left: 6px; }
  html.gs-playing #timer-display { font-size: 1rem; }
}
html.gs-playing .game-status__timer {
  flex: 1;
  justify-content: center;
  white-space: nowrap;
  padding-left: 12px;
  border-left: 1px solid var(--play-border);
}
html.gs-playing .board-wrap {
  position: relative;
  width: min(100%, max(220px, 100dvh - 490px), 560px);
  max-width: 100%;
  padding: 6px;
  margin: 0;
  border-color: var(--play-border);
}
html.gs-playing .numpad {
  width: 100%;
  max-width: 560px;
  gap: 4px;
  margin: 0;
}
html.gs-playing .numpad__btn { min-height: 44px; padding: 4px 0; }
html.gs-playing .game-controls {
  width: 100%;
  max-width: 560px;
  justify-content: center;
  gap: 8px;
  margin: 0;
}
html.gs-playing .game-controls .gs-icon-btn { flex: none; min-width: 44px; padding: 0; }
html.gs-playing #note-btn.is-active { background: var(--play-btn-hover); color: var(--play-accent); }
/* ヒントや警告がない間も領域を確保する。 */
html.gs-playing .game-notice,
html.gs-playing .game-notice[hidden] {
  display: block !important;
  width: 100%;
  height: 3.2em;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  border: 0;
  background: none;
  color: #ffd166;
  font-size: .8125rem;
  line-height: 1.6;
  text-align: center;
}
html.gs-playing .game-notice[hidden] { visibility: hidden; }
html.gs-playing .clear-banner {
  position: absolute;
  inset: 0;
  z-index: 2;
  height: fit-content;
  max-height: 100%;
  overflow-y: auto;
  margin: auto;
  text-align: center;
  background: var(--play-hud-bg);
  border-color: var(--play-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
html.gs-playing .clear-banner__title { color: #6ee7b7; font-size: 1.5rem; }
html.gs-playing .clear-banner .btn { margin-top: 12px; }

/* スマホ縦画面では盤面を利用可能な横幅いっぱいに広げる。 */
@media (max-width: 767px) and (orientation: portrait) {
  html.gs-playing .board-wrap {
    width: 100%;
  }
}

@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .np-screen { padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top)); }
  html.gs-playing .np-screen > * { max-width: 640px; }
  html.gs-playing .np-screen > .gs-bar { margin-bottom: 24px; }
  html.gs-playing .np-game:not([hidden]) { gap: 16px; }
  html.gs-playing .board-wrap { width: min(100%, max(240px, 100dvh - 610px), 560px); }
}

@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .np-screen {
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    gap: 8px 16px;
    align-content: start;
  }
  html.gs-playing .np-screen > .gs-bar { grid-column: 1; margin-bottom: 0; }
  html.gs-playing #setup-section { grid-column: 1; margin: 0; }
  html.gs-playing #game-section { grid-column: 2; grid-row: 1 / span 3; }
  html.gs-playing .np-screen > * { max-width: none; }
  html.gs-playing .np-game:not([hidden]) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "status" "board" "notice" "pad" "controls";
    gap: 4px;
  }
  html.gs-playing .game-status { grid-area: status; }
  html.gs-playing .board-wrap { grid-area: board; width: min(100%, 100dvh - 210px); align-self: center; }
  html.gs-playing .game-notice { grid-area: notice; }
  html.gs-playing .numpad { grid-area: pad; }
  html.gs-playing .game-controls { grid-area: controls; }
}

/* 難易度は戻るボタンと同じツールバーに配置する。 */
html.gs-playing .np-screen > .gs-bar { gap: 8px; align-items: center; }
html.gs-playing .np-screen > .gs-bar .difficulty-group {
  flex: 1;
  min-width: 0;
  margin: 0;
}
html.gs-playing .np-screen > .gs-bar .field-label { display: none; }
html.gs-playing .np-screen > .gs-bar .option-tabs { margin: 0; align-items: center; }
html.gs-playing .np-screen > .gs-bar .option-tab {
  height: 44px;
  min-height: 44px;
  padding: 0 3px;
  font-size: .75rem;
  line-height: 1;
  white-space: nowrap;
}
