:root {
  --bg: #eef4f8;
  --panel: #ffffff;
  --ink: #23313f;
  --ink-sub: #5d6f80;
  --line: #d5dfe8;

  --cell-undet: #f6f1e3;
  --cell-undet-line: #d9cfae;
  --cell-sea: #3d8fd1;
  --cell-sea-deep: #2f77b3;
  --cell-land: #7db65a;
  --cell-land-deep: #659946;
  --cell-base: #24445f;
  --cell-base-deep: #1a3349;
  --arrow: #ffd76a;

  --ok: #2f9e63;
  --ok-bg: #e2f6ea;
  --ng: #cf4b3f;
  --ng-bg: #fbe8e5;

  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  line-height: 1.55;
  color: var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 500px at 85% -10%, #dcecf7 0%, transparent 60%),
    var(--bg);
  display: flex;
  justify-content: center;
  padding: 0.75rem 0.5rem 1.5rem;
  touch-action: manipulation;
}

.app {
  width: 100%;
  max-width: 560px;
}

.app-header h1 {
  font-size: 1.3rem;
  margin: 0.25rem 0 0;
  letter-spacing: 0.02em;
}

.app-header .subtitle {
  margin: 0.1rem 0 0.5rem;
  color: var(--ink-sub);
  font-size: 0.82rem;
}

.app-header .launch-note {
  margin: 0 0 0.75rem;
  color: var(--ink-sub);
  font-size: 0.75rem;
  line-height: 1.4;
}

.view[hidden] {
  display: none !important;
}

/* --- 一覧画面 (E004) --- */
.list-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
}

.list-summary {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.puzzle-search-row,
.puzzle-jump-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.search-label,
.jump-label {
  font-size: 0.85rem;
  color: var(--ink-sub);
  flex-shrink: 0;
}

.puzzle-search {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.65rem;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.puzzle-jump {
  width: 4.2rem;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.5rem;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
  gap: 0.45rem;
}

.puzzle-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  min-height: 5rem;
  padding: 0.55rem 0.5rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.puzzle-card:hover {
  background: #e8f0f7;
}

.puzzle-card.cleared {
  border-color: var(--ok);
  background: var(--ok-bg);
}

.puzzle-card-num {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.1;
}

.puzzle-card-tier {
  font-size: 0.72rem;
  font-weight: 600;
}

.puzzle-card-tier.tier-easy { color: #2f7d4f; }
.puzzle-card-tier.tier-normal { color: #2f6b9e; }
.puzzle-card-tier.tier-hard { color: #a8433a; }

.puzzle-card-title {
  font-size: 0.72rem;
  color: var(--ink-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.puzzle-card-size {
  font-size: 0.68rem;
  color: var(--ink-sub);
}

.puzzle-card-badge {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  font-size: 0.85rem;
  color: var(--ok);
  font-weight: 700;
}

.puzzle-grid-empty {
  margin: 1rem 0;
  text-align: center;
  color: var(--ink-sub);
  font-size: 0.9rem;
}

/* --- プレイ画面 (E003/E005) --- */
.view-play {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 5rem);
}

.play-header {
  margin-bottom: 0.35rem;
}

.play-title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
}

.status {
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  margin: 0.35rem 0 0.5rem;
  font-size: 0.88rem;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink-sub);
  min-height: 2.5rem;
  display: flex;
  align-items: center;
}

.status.clear {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
  font-weight: 700;
}

.status.error {
  background: var(--ng-bg);
  border-color: var(--ng);
  color: var(--ng);
}

.board-wrap {
  flex: 1 1 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: clamp(4px, 1.5vw, 10px);
  box-shadow: 0 6px 18px rgba(35, 60, 90, 0.07);
  margin-bottom: 0.5rem;
}

.board {
  display: grid;
  gap: 3px;
  width: 100%;
  max-width: 100%;
  touch-action: manipulation;
}

.cell {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 44px;
  border: none;
  border-radius: 7px;
  padding: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cell.undet {
  background: var(--cell-undet);
  box-shadow: inset 0 0 0 1.5px var(--cell-undet-line);
}

.cell.sea {
  background: linear-gradient(180deg, var(--cell-sea) 0%, var(--cell-sea-deep) 100%);
}

.cell.land {
  background: linear-gradient(180deg, var(--cell-land) 0%, var(--cell-land-deep) 100%);
}

.cell .hint-marker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  transform: translate(-50%, -50%);
  background: #d64545;
  border-radius: 3px;
  box-shadow: 0 0 0 1.5px #9b2c2c;
  pointer-events: none;
  z-index: 2;
}

.cell.base {
  background: radial-gradient(circle at 50% 38%, var(--cell-base) 0%, var(--cell-base-deep) 85%);
  cursor: default;
  min-height: 44px;
}

.cell.base .num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: clamp(0.85rem, 4vw, 1.25rem);
  pointer-events: none;
}

.cell.base .arrow {
  position: absolute;
  width: 26%;
  height: 26%;
  pointer-events: none;
}

.cell.base .arrow svg { width: 100%; height: 100%; display: block; }
.cell.base .arrow path {
  fill: none;
  stroke: var(--arrow);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.arrow.up    { top: 2%;  left: 37%; }
.arrow.down  { bottom: 2%; left: 37%; transform: rotate(180deg); }
.arrow.left  { left: 2%;  top: 37%; transform: rotate(-90deg); }
.arrow.right { right: 2%; top: 37%; transform: rotate(90deg); }

.play-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: auto;
  padding-top: 0.5rem;
  position: sticky;
  bottom: 0;
  background: linear-gradient(transparent, var(--bg) 12%);
  padding-bottom: 0.25rem;
}

.btn {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.85rem;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-action { flex: 1 1 calc(50% - 0.25rem); min-width: calc(50% - 0.25rem); }
.btn-secondary { flex: 1 1 100%; }
.btn-primary {
  flex: 1 1 100%;
  background: #dceaf6;
  border-color: #7eb3d8;
  font-weight: 600;
}

.btn-primary-emphasis {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
}

.btn-jump {
  padding: 0.4rem 0.75rem;
  min-height: 44px;
}

details.rules {
  margin-top: 0.65rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
}

details.rules summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
details.rules ul { margin: 0.35rem 0 0.2rem; padding-left: 1.2rem; }
details.rules li { margin: 0.12rem 0; }

@media (max-width: 480px) {
  body { padding: 0.5rem 0.4rem 1rem; }
  .app-header h1 { font-size: 1.1rem; }
  .puzzle-grid {
    grid-template-columns: repeat(auto-fill, minmax(4.8rem, 1fr));
    gap: 0.35rem;
  }
  .puzzle-card { min-height: 4.5rem; padding: 0.45rem 0.4rem; }
  .board-wrap { padding: 4px; }
  .play-controls .btn { font-size: 0.85rem; }
}
