/* SHS 試作001 — BUILD 005（1画面収め + 経路表示） */

:root {
  --bg: #1a472a;
  --bg-panel: rgba(0, 0, 0, 0.2);
  --text: #f5f5dc;
  --accent: #ffd166;
  --path-color: #ff5722;
  --path-width: 4;
  --gap: 3px;
  --board-pad: 6px;
  --tile-w: 44px;
  --chrome-h: 11rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: linear-gradient(160deg, #1a472a 0%, #2d6a4f 45%, #1b4332 100%);
  color: var(--text);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 0.75rem 1rem;
}

.header {
  text-align: center;
  margin-bottom: 0.35rem;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
}

.subtitle {
  margin: 0.15rem 0 0;
  opacity: 0.85;
  font-size: 0.85rem;
}

.tile-count {
  text-align: center;
  margin: 0.25rem 0;
  font-size: 0.9rem;
}

.game-timer {
  text-align: center;
  margin: 0.15rem 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.game-timer[data-timer-state="running"] {
  color: #81c784;
}

.game-timer[data-timer-state="stopped"] {
  color: #ffd166;
}

.clear-time {
  margin: 0.35rem 0 0;
  font-size: 1rem;
  font-weight: 600;
}

#startup-note {
  font-size: 0.78rem;
  opacity: 0.8;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  margin: 0.35rem 0;
}

.control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  background: var(--accent);
  color: #1a1a1a;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text);
}

.status,
.hint-text {
  text-align: center;
  margin: 0.25rem 0;
  font-size: 0.9rem;
  min-height: 1.25em;
}

.hint-text {
  color: var(--accent);
}

.board-area {
  display: flex;
  justify-content: center;
  margin: 0.35rem 0;
  max-height: calc(100dvh - var(--chrome-h));
}

.board-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: calc(100dvh - var(--chrome-h));
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), var(--tile-w, 44px));
  grid-auto-rows: calc(var(--tile-w, 44px) * 4 / 3);
  grid-auto-flow: row;
  gap: var(--gap);
  padding: var(--board-pad);
  background: var(--bg-panel);
  border-radius: 12px;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
}

.tile-cell {
  width: var(--tile-w, 44px);
  height: calc(var(--tile-w, 44px) * 4 / 3);
  border: none;
  border-radius: 5px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  position: relative;
  transition: transform 0.1s, filter 0.1s;
}

.tile-cell.tile:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
}

.tile-cell.selected {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  z-index: 2;
}

.tile-cell.hint {
  outline: 3px dashed #4fc3f7;
  outline-offset: 1px;
}

.tile-cell.empty-slot {
  visibility: hidden;
  pointer-events: none;
}

.tile-svg {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.path-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  overflow: visible;
}

.path-overlay .path-lines {
  overflow: visible;
}

.path-overlay line,
.path-overlay polyline {
  stroke: var(--path-color);
  stroke-width: var(--path-width);
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8));
}

.path-overlay .path-dot {
  fill: var(--path-color);
  stroke: #fff;
  stroke-width: 1.5;
}

.clear-banner {
  text-align: center;
  padding: 0.75rem;
  background: rgba(255, 209, 102, 0.2);
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
}

.footer {
  margin-top: 0.75rem;
  font-size: 0.82rem;
  opacity: 0.9;
}

.footer details {
  margin-top: 0.35rem;
}

@media (max-width: 480px) {
  :root {
    --chrome-h: 10rem;
    --path-width: 3;
  }

  .controls {
    gap: 0.35rem;
  }

  .btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.85rem;
  }
}

@media (min-width: 900px) {
  :root {
    --chrome-h: 12rem;
  }
}
