/* 方眼紙に青インクで描いた迷路、赤鉛筆でなぞる。暗い画面では青焼き図面。 */
:root {
  --paper: #f2f5f1;
  --grid: rgba(31, 58, 95, 0.09);
  --ink: #1f3a5f;
  --ink-soft: #5b6f86;
  --pencil: #d23c2a;
  --goal: #1f8a5b;
  --card: #ffffff;
  --fog: #e3e8e6;
  --marker: #e0a800;
  --graphite: #3b3f45;
  --night: rgba(16, 26, 44, 0.55);
  --font-display: "Dela Gothic One", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #102a4a; --grid: rgba(220, 232, 245, 0.08); --ink: #dce8f5; --ink-soft: #8fa6c0;
    --pencil: #ff7a59; --goal: #5fd39c; --card: #16365e; --fog: #0b2140; --marker: #ffd23f; --graphite: #c9d3de; --night: rgba(2, 10, 24, 0.7); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #102a4a; --grid: rgba(220, 232, 245, 0.08); --ink: #dce8f5; --ink-soft: #8fa6c0;
  --pencil: #ff7a59; --goal: #5fd39c; --card: #16365e; --fog: #0b2140; --marker: #ffd23f; --graphite: #c9d3de; --night: rgba(2, 10, 24, 0.7); color-scheme: dark;
}

html, body { height: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

.app {
  height: 100%;
  box-sizing: border-box;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  max-width: 1100px;
  margin: 0 auto;
}

.top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; }
.brand { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.modes { display: flex; gap: 0; border: 1.5px solid var(--ink); }
.mode { font: inherit; font-size: 0.8rem; color: var(--ink); background: transparent; border: 0; padding: 4px 10px; cursor: pointer; }
.mode + .mode { border-left: 1.5px solid var(--ink); }
.mode[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.mode:focus-visible { outline: 3px solid var(--pencil); outline-offset: 2px; }
.share { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.share-text { font-family: var(--font-mono); font-size: 0.85rem; flex: 1 1 220px; min-width: 0; resize: none; color: var(--ink); background: var(--paper); border: 1px solid var(--ink-soft); }
.title { font-family: var(--font-display); font-weight: 400; font-size: 1.6rem; margin: 0; letter-spacing: 0.04em; }
.hud { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 20px; margin: 0; }
.hud dt { white-space: nowrap; }
.top { position: relative; }
.top-buttons { display: flex; gap: 6px; align-self: center; }
.help { position: fixed; inset: max(12px, env(safe-area-inset-top, 0px)) 12px 12px; margin: auto; max-width: 480px; height: fit-content; max-height: calc(100% - 24px); overflow: auto; box-sizing: border-box; z-index: 20;
  background: var(--card); border: 2px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); padding: 16px 20px; display: grid; gap: 10px; align-content: start; }
.help-title { font-family: var(--font-display); font-weight: 400; font-size: 1.3rem; margin: 0; }
.help-lead { margin: 0; font-weight: 700; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.86rem; line-height: 1.45; }
.legend li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start; }
.legend svg { width: 22px; height: 22px; margin-top: 1px; }
.legend .t-goal { color: var(--goal); }
.i-pencil { fill: var(--pencil); }
.i-q { fill: var(--pencil); font: 700 16px var(--font-body); }
.i-lead { fill: var(--graphite); }
.i-refill { stroke: var(--graphite); stroke-width: 2.5; fill: none; }
.i-star { fill: var(--marker); }
.i-key { stroke: var(--ink); stroke-width: 2; fill: none; }
.help .btn { justify-self: start; }
.icon-btn { text-decoration: none; display: inline-block; font: inherit; font-size: 0.75rem; letter-spacing: 0.08em; color: var(--ink-soft); background: transparent; border: 1.5px solid var(--ink-soft); padding: 3px 8px; cursor: pointer; align-self: center; }
.icon-btn[aria-pressed="false"] { text-decoration: line-through; opacity: 0.7; }
.icon-btn:focus-visible { outline: 3px solid var(--pencil); outline-offset: 2px; }
.hud div { display: flex; flex-direction: column; align-items: flex-end; }
.hud dt { font-size: 0.7rem; letter-spacing: 0.12em; color: var(--ink-soft); }
.hud dd { margin: 0; font-family: var(--font-mono); font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.hud-lead dd { display: flex; align-items: center; gap: 8px; }
#hud-lead { min-width: 3ch; text-align: right; }
.hud-lead dd { position: relative; }
.hud-stars dd { position: relative; }
.hud dd .sub { position: absolute; right: 0; top: 100%; font-size: 0.7rem; color: var(--ink-soft); white-space: nowrap; }
.delta { position: absolute; right: 0; top: 100%; font-size: 0.8rem; color: var(--pencil); opacity: 0; pointer-events: none; white-space: nowrap; }
.delta.show { animation: delta 1.4s ease-out; }
.delta.plus { color: var(--goal); }
@keyframes delta { 0% { opacity: 1; transform: translateY(0); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .delta.show { animation-duration: 2.5s; } }
.leadbar { width: clamp(70px, 18vw, 160px); height: 10px; background: var(--fog); position: relative; overflow: hidden; clip-path: polygon(0 0, 94% 0, 100% 50%, 94% 100%, 0 100%); }
.leadbar > span { position: absolute; inset: 0 auto 0 0; background: var(--graphite); transition: width 0.25s; }
.leadbar.low > span { background: var(--pencil); }

.stage { position: relative; min-height: 0; min-width: 0; display: grid; place-items: center; overflow: hidden; }
#board { display: block; touch-action: none; }

.result { flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; border: 2px solid var(--ink); background: var(--card); padding: 10px 16px; box-shadow: 4px 4px 0 var(--ink); }
.result p { margin: 0; word-break: auto-phrase; line-break: strict; }
.hint { word-break: auto-phrase; line-break: strict; }
.result-head { display: flex; align-items: baseline; gap: 10px; font-weight: 700; }
.result-kicker { font-family: var(--font-display); font-size: 1.3rem; color: var(--pencil); letter-spacing: 0.1em; }
.rank-mark { font-family: var(--font-display); font-size: 2rem; line-height: 1; }
.result-body { font-family: var(--font-mono); flex: 1 1 200px; min-width: 0; }
.result-sub { font-family: var(--font-body); color: var(--ink-soft); font-size: 0.9rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.notebook { flex: 1 1 100%; min-width: 0; display: grid; gap: 6px; }
.notebook-title { font-size: 0.75rem; letter-spacing: 0.12em; color: var(--ink-soft); }
.notebook-pages { list-style: none; margin: 0; padding: 0 0 4px; display: flex; flex-wrap: wrap; gap: 10px; }
.notebook-pages li { flex: 0 0 auto; display: grid; gap: 2px; font-size: 0.75rem; font-family: var(--font-mono); color: var(--ink-soft); }
.notebook-pages img { display: block; height: 72px; width: auto; border: 1px solid var(--grid); background: var(--paper); }
.notebook-pages .lost img { opacity: 0.6; }
.bottom:has(.result:not([hidden])) .hint, .bottom:has(.result:not([hidden])) .pad { display: none; }

.btn { grid-column: 1 / -1; }
.card-main { font-family: var(--font-mono); font-size: 1.1rem; }
.card-sub { color: var(--ink-soft); font-size: 0.9rem; }

.btn {
  font: inherit; font-weight: 700; color: var(--paper); background: var(--ink); border: 0; padding: 10px 16px; cursor: pointer;
}
.btn-ghost { color: var(--ink); background: transparent; border: 2px solid var(--ink); padding: 8px 14px; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tool { white-space: nowrap; }
.tool .hand { font-size: 0.75em; font-weight: 400; opacity: 0.8; }
.tool .cost { color: var(--marker); -webkit-text-stroke: 0.3px var(--ink); }
.tool[aria-pressed="true"] { background: var(--pencil); border-color: var(--pencil); color: var(--paper); }
.tool:disabled { opacity: 0.4; cursor: not-allowed; }
.bottom:has(.result:not([hidden])) .tools { display: none; }
.btn:focus-visible, .pad-btn:focus-visible { outline: 3px solid var(--pencil); outline-offset: 2px; }
kbd { font-family: var(--font-mono); font-size: 0.75em; opacity: 0.75; margin-left: 6px; }
@media (pointer: coarse) { kbd { display: none; } }

.bottom { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.hint { margin: 0; color: var(--ink-soft); font-size: 0.9rem; line-height: 1.45; flex: 1 1 240px; min-width: 0; min-height: 2.9em; display: flex; align-items: center; }

.pad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 44px); gap: 6px; }
.pad-btn {
  font: inherit; font-size: 1.1rem; color: var(--ink); background: transparent; border: 2px solid var(--ink); cursor: pointer;
  touch-action: manipulation;
}
.pad-btn:active { background: var(--ink); color: var(--paper); }
.pad .up { grid-column: 2; grid-row: 1; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }
.pad .one { grid-column: 3; grid-row: 1; font-size: 0.8rem; }
.pad .one[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

@media (hover: hover) and (pointer: fine) and (min-width: 700px) {
  .pad { display: none; }
}
