/* お絵かきロジック固有スタイル */

.ng-select {
  margin-top: 8px;
}

.ng-size-group {
  margin-top: 22px;
}

.ng-size-group:first-child {
  margin-top: 4px;
}

.ng-size-group__title {
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface);
  font-size: 1rem;
  font-weight: 700;
}

.ng-puzzle-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.ng-puzzle-btn {
  appearance: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 64px;
  padding: 12px 14px;
  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;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.04s ease;
}

.ng-puzzle-btn:hover {
  background: var(--md-sys-color-primary-container);
}

.ng-puzzle-btn:active {
  transform: translateY(1px);
}

.ng-puzzle-btn:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.ng-puzzle-btn.is-cleared {
  border-color: color-mix(in srgb, var(--success) 40%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, var(--success) 8%, var(--md-sys-color-surface));
}

.ng-puzzle-btn__title {
  font-size: 0.9375rem;
  font-weight: 700;
}

.ng-puzzle-btn__meta {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.75rem;
  font-weight: 600;
}

.ng-puzzle-btn__badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--success) 18%, var(--md-sys-color-surface));
  color: var(--success);
  font-size: 0.6875rem;
  font-weight: 700;
}

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

.ng-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
  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);
}

.ng-status__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ng-status__title {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-size: 1.0625rem;
  font-weight: 700;
}

.status-pill {
  display: inline-block;
  padding: 4px 10px;
  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.75rem;
  font-weight: 700;
}

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

.ng-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;
}

.ng-mode {
  margin-bottom: 14px;
}

.ng-mode .field-label {
  margin-bottom: 8px;
}

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

.option-tab {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  padding: 8px 10px;
  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.9375rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.04s ease;
}

.option-tab small {
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.75;
}

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

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

.option-tab:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

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

.clear-banner {
  margin-bottom: 14px;
  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));
  text-align: center;
}

.clear-banner__title {
  margin: 0 0 4px;
  color: var(--success);
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.clear-banner__detail {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.9375rem;
  line-height: 1.6;
  white-space: pre-line;
}

.clear-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

.clear-actions .btn {
  min-width: 8.5rem;
}

.ng-board-wrap {
  width: 100%;
  max-width: min(100%, 560px);
  margin: 0 auto 8px;
  padding: 14px;
  box-sizing: border-box;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  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);
}

.ng-board-wrap.is-scrollable {
  justify-content: flex-start;
}

.ng-scroll-hint {
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.75rem;
  line-height: 1.45;
  text-align: center;
}

.ng-board {
  --ng-size: 5;
  --ng-row-hints: 1;
  --ng-col-hints: 1;
  --ng-cell: clamp(22px, calc((100vw - 72px) / (var(--ng-size) + 2.2)), 36px);
  --ng-hint-w: calc(var(--ng-cell) * 0.92);
  --ng-hint-h: calc(var(--ng-cell) * 0.85);
  --ng-line: rgba(90, 150, 220, 0.28);
  --ng-line-thick: rgba(120, 200, 255, 0.55);
  display: grid;
  grid-template-columns: calc(var(--ng-hint-w) * var(--ng-row-hints)) repeat(var(--ng-size), var(--ng-cell));
  grid-template-rows: calc(var(--ng-hint-h) * var(--ng-col-hints)) repeat(var(--ng-size), var(--ng-cell));
  width: max-content;
  margin: 0 auto;
  border: 1px solid rgba(96, 180, 255, 0.45);
  border-radius: var(--md-sys-shape-corner-medium);
  background:
    radial-gradient(circle at 12% 0%, rgba(63, 196, 255, 0.1), transparent 50%),
    linear-gradient(165deg, #101c3a 0%, #0c1630 100%);
  box-shadow:
    0 0 0 1px rgba(63, 196, 255, 0.12),
    0 4px 14px rgba(8, 16, 36, 0.28);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.ng-board--10 {
  --ng-cell: clamp(18px, calc((100vw - 56px) / (var(--ng-size) + 2.6)), 30px);
}

.ng-board--15 {
  --ng-cell: clamp(12px, calc((100vw - 40px) / (var(--ng-size) + 3.6)), 22px);
}

.ng-board.is-cleared {
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--success) 45%, transparent),
    0 0 22px rgba(94, 226, 178, 0.28),
    0 14px 30px rgba(28, 52, 96, 0.16);
}

.ng-corner {
  background: rgba(63, 196, 255, 0.06);
}

.ng-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 2px;
  color: #c8dcff;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.ng-hint--col {
  flex-direction: column;
  justify-content: flex-end;
  font-size: clamp(0.62rem, calc(var(--ng-cell) * 0.42), 0.85rem);
  border-bottom: 2px solid var(--ng-line-thick);
  background: rgba(63, 196, 255, 0.07);
}

.ng-hint--row {
  flex-direction: row;
  justify-content: flex-end;
  font-size: clamp(0.62rem, calc(var(--ng-cell) * 0.42), 0.85rem);
  border-right: 2px solid var(--ng-line-thick);
  background: rgba(63, 196, 255, 0.07);
}

.ng-hint span {
  display: block;
  min-width: 0.7em;
  text-align: center;
}

.ng-hint.is-done {
  color: rgba(160, 190, 230, 0.42);
}

.ng-cell {
  appearance: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--ng-cell);
  height: var(--ng-cell);
  margin: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--ng-line);
  border-bottom: 1px solid var(--ng-line);
  background: rgba(226, 238, 255, 0.12);
  color: #e8f2ff;
  cursor: pointer;
  touch-action: manipulation;
}

.ng-cell--thick-left {
  border-left: 2px solid var(--ng-line-thick);
}

.ng-cell--thick-top {
  border-top: 2px solid var(--ng-line-thick);
}

.ng-cell--thick-right {
  border-right: 2px solid var(--ng-line-thick);
}

.ng-cell--thick-bottom {
  border-bottom: 2px solid var(--ng-line-thick);
}

.ng-cell:hover:not(:disabled) {
  background: rgba(63, 196, 255, 0.22);
  box-shadow: inset 0 0 0 1px rgba(63, 196, 255, 0.35);
}

.ng-cell:focus-visible {
  outline: 2px solid #3fc4ff;
  outline-offset: -2px;
  z-index: 1;
}

.ng-cell.is-fill {
  background: linear-gradient(160deg, #5ec8ff 0%, #2a7fd4 55%, #1a5aa8 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    0 0 6px rgba(63, 196, 255, 0.28);
}

.ng-cell.is-fill:hover:not(:disabled) {
  background: linear-gradient(160deg, #7ad4ff 0%, #3a90e0 55%, #2268b8 100%);
}

.ng-board.is-cleared .ng-cell.is-fill {
  background: linear-gradient(160deg, #6fe6a6 0%, #2fbf7a 55%, #1a8f5c 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    0 0 8px rgba(94, 226, 178, 0.35);
}

.ng-cell.is-mark {
  background: rgba(226, 238, 255, 0.08);
}

.ng-cell__mark {
  color: rgba(180, 210, 255, 0.7);
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: clamp(0.7rem, calc(var(--ng-cell) * 0.55), 1rem);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.ng-guide {
  margin: 0 0 14px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8125rem;
  line-height: 1.55;
  text-align: center;
}

.game-controls {
  margin-top: 4px;
}

.how-to-list {
  margin: 10px 0 0;
  padding-left: 1.2em;
}

.how-to-list li {
  margin: 0.35em 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .ng-puzzle-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ng-status {
    flex-direction: column;
    align-items: flex-start;
  }

  .ng-board-wrap {
    max-width: 100%;
  }

  .option-tab {
    min-height: 56px;
  }
}

@media (min-width: 720px) {
  .ng-board {
    --ng-cell: clamp(26px, 4.2vw, 38px);
  }

  .ng-board--10 {
    --ng-cell: clamp(22px, 3.4vw, 32px);
  }

  .ng-board--15 {
    --ng-cell: clamp(18px, 2.6vw, 26px);
  }
}

/* 共通画面・HUDを再利用し、盤面と問題選択だけを固有に配置する。 */
html.gs-playing .ng-screen > .gs-bar,
html.gs-playing .ng-screen > .game-panel {
  flex: none;
  width: 100%;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}
html.gs-playing .ng-screen > .game-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  margin-bottom: auto;
}
html.gs-playing .ng-screen .gs-hud { max-width: 100%; margin-bottom: 0; }
html.gs-playing .ng-screen .gs-hud__value { margin: 0; }
html.gs-playing #puzzle-title { font-size: 1rem; overflow-wrap: anywhere; }
html.gs-playing #timer-display { color: var(--play-text); font-size: 1.15rem; }
html.gs-playing .ng-mode { margin: 0; }
html.gs-playing .ng-mode .field-label,
html.gs-playing .ng-guide {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
html.gs-playing .option-tabs { gap: 6px; }
html.gs-playing .option-tab {
  min-height: 44px;
  gap: 0;
  padding: 4px 6px;
  border-color: var(--play-border);
  background: var(--play-hud-bg);
  color: var(--play-text);
  font-size: .8125rem;
}
html.gs-playing .option-tab small { font-size: .6875rem; }
html.gs-playing .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 .option-tab:focus-visible { outline-color: var(--play-accent); }
html.gs-playing .ng-stage { position: relative; isolation: isolate; }
html.gs-playing .ng-board-wrap { margin: 0 auto; max-width: 100%; }
html.gs-playing .clear-banner {
  position: absolute;
  z-index: 2;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(94%, 360px);
  max-height: 100%;
  overflow: auto;
  margin: 0;
  border-color: var(--play-border);
  background: var(--play-hud-bg);
  box-shadow: 0 12px 36px #0009;
}
html.gs-playing .clear-banner__title { color: color-mix(in srgb, var(--success) 55%, var(--play-text)); }
html.gs-playing .clear-banner__detail { color: var(--play-text); }
html.gs-playing .clear-actions { gap: 8px; }
html.gs-playing .clear-actions .btn--secondary {
  border-color: var(--play-border);
  background: var(--play-bg);
  color: var(--play-text);
}
html.gs-playing .game-controls { margin: 0; justify-content: center; gap: 12px; }
html.gs-playing .ng-scroll-hint { margin: 0; color: var(--play-text-muted); }
.ng-select {
  position: fixed;
  inset: 0;
  width: min(640px, calc(100% - 28px));
  max-height: calc(100dvh - 40px);
  margin: auto;
  padding: 18px;
  border: 1px solid var(--play-border);
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--play-hud-bg);
  color: var(--play-text);
  overflow: auto;
  overscroll-behavior: contain;
}
.ng-select::backdrop { background: #080f1fcc; }
.ng-select__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ng-select__header h2 { margin: 0; font-size: 1.1rem; }
.ng-select .ng-size-group__title,
.ng-select .ng-puzzle-btn__title { color: var(--play-text); }
.ng-select .ng-puzzle-btn {
  border-color: var(--play-border);
  background: var(--play-bg);
  color: var(--play-text);
}
.ng-select .ng-puzzle-btn__meta { color: var(--play-text-muted); }
.ng-select .ng-puzzle-btn.is-cleared { border-color: var(--success); }
@media (hover: hover) {
  html.gs-playing .option-tab:hover,
  .ng-select .ng-puzzle-btn:hover { border-color: var(--play-accent); background: var(--play-btn-hover); }
}
@media (min-width: 720px) and (min-height: 700px) {
  html.gs-playing .ng-screen { padding-top: 24px; padding-bottom: 24px; }
  html.gs-playing .ng-screen > .game-panel { gap: 20px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .ng-screen > .game-panel {
    display: grid;
    grid-template-columns: minmax(200px, 240px) minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr;
    align-items: start;
    gap: 10px 16px;
    margin-top: 0;
  }
  html.gs-playing .ng-screen .gs-hud { grid-column: 1; grid-row: 1; }
  html.gs-playing .ng-mode { grid-column: 1; grid-row: 2; }
  html.gs-playing .ng-stage { grid-column: 2; grid-row: 1 / 5; align-self: center; min-width: 0; }
  html.gs-playing .ng-scroll-hint { grid-column: 1; grid-row: 4; }
  html.gs-playing .game-controls { grid-column: 1; grid-row: 3; }
  html.gs-playing .ng-board-wrap { padding: 6px; }
}
