/* 一画面のゲーム。上から 見出し → 目標 → 手順 → 盤面 → 操作（親指の届く下側） */
:root {
  --ink: #0f2129;        /* 背景：夜の水槽のような藍緑 */
  --well: #142e38;       /* 盤面のくぼみ */
  --well-edge: #23495a;
  --paper: #e8f1ee;      /* 文字 */
  --muted: #8eaaa8;
  --amber: #ffb547;      /* 連鎖数・星 */
  --btn: #1c3b47;
  --btn-press: #275062;
  --display: "Dela Gothic One", "Hiragino Sans", "Yu Gothic", sans-serif;
  --body: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--body);
  font-weight: 500;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

button {
  font: inherit;
  color: var(--paper);
  background: var(--btn);
  border: 1px solid var(--well-edge);
  border-radius: 12px;
  cursor: pointer;
}
button:active { background: var(--btn-press); }
button:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
button:disabled { opacity: 0.4; }

.chip { padding: 6px 12px; font-size: 14px; border-radius: 999px; }
.primary { background: var(--amber); color: #2a1a00; border-color: var(--amber); font-weight: 700; }
.primary:active { background: #e89a2c; }

.bar { display: flex; align-items: center; gap: 10px; }
.stage { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.stage-no { font-family: var(--display); color: var(--amber); font-size: 20px; }
.bar h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 18px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stars { color: var(--amber); letter-spacing: 2px; font-size: 16px; white-space: nowrap; }
.stars .off { color: #36525c; }
.stars.large { font-size: 34px; }

.info { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; color: var(--muted); }
.info .goal { min-width: 0; }
.info .now { white-space: nowrap; }
.info .now b { font-family: var(--display); font-weight: 400; font-size: 22px; color: var(--paper); font-variant-numeric: tabular-nums; }

.hint { margin: 0; font-size: 13px; line-height: 1.5; color: var(--paper); opacity: 0.85; }
.hint::before { content: "ヒント"; font-size: 11px; color: var(--amber); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-right: 6px; vertical-align: 1px; }

.queue {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px;
  scrollbar-width: none;
}
.queue::-webkit-scrollbar { display: none; }
.qpair {
  flex: none;
  display: grid;
  gap: 2px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid transparent;
}
.qpair .d { width: 14px; height: 14px; border-radius: 50%; }
.qpair.done { opacity: 0.2; }
.qpair.now { border-color: var(--amber); background: #1a3540; }

.stage-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#field { display: block; border-radius: 14px; touch-action: none; }

.chain-pop {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-size: 44px;
  color: var(--amber);
  text-shadow: 0 3px 0 #5a3500, 0 0 18px rgba(255, 181, 71, 0.5);
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
}
.chain-pop { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.chain-pop .sub { font-family: var(--body); font-weight: 700; font-size: 16px; color: var(--paper); text-shadow: 0 1px 2px #000; }
.chain-pop.show { animation: pop 900ms ease-out; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  30% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

.controls { display: grid; grid-template-columns: 1fr 1fr 1.6fr 1fr 1fr; gap: 8px; }
.controls button { height: 56px; font-size: 22px; }
.controls .primary { font-size: 18px; }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.drop small { display: none; font-size: 11px; font-weight: 700; }
.drop.fire { background: #ff7a59; border-color: #ff7a59; }
.drop.fire small { display: block; }
.subcontrols { display: flex; justify-content: center; gap: 10px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 16, 20, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  z-index: 20;
}
.sheet {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--well);
  border: 1px solid var(--well-edge);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.total { display: block; margin-top: 4px; color: var(--amber); font-weight: 700; }
.sheet h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 22px; }
.sheet .lead { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.sheet > .row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.howto-list { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.6; }
.howto-list b { color: var(--amber); font-weight: 700; }
#btn-howto-close { align-self: center; padding: 10px 28px; font-size: 16px; }
.menu-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.menu-list button {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  text-align: left;
  padding: 10px 12px;
}
.menu-list .n { font-family: var(--display); color: var(--amber); }
.menu-list .t { min-width: 0; }
.menu-list .t small { display: block; color: var(--muted); font-size: 12px; }

.result { text-align: center; align-items: center; }
.result .eyebrow { margin: 0; color: var(--muted); letter-spacing: 0.08em; }
.result .big { margin: 0; font-family: var(--display); font-size: 72px; line-height: 1; color: var(--amber); }
.result .big small { font-size: 22px; color: var(--paper); margin-left: 4px; }
.chainlog { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 2px; }
.chainlog li { display: flex; align-items: center; gap: 2px; }
.chainlog .step { display: flex; align-items: center; gap: 3px; padding: 3px 6px; border-radius: 8px; background: #1b3b47; font-size: 12px; }
.chainlog .step.multi { outline: 1px dashed var(--amber); }
.chainlog .k { color: var(--muted); margin-right: 2px; font-variant-numeric: tabular-nums; }
.chainlog .d { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.chainlog .arrow { color: var(--muted); font-size: 11px; }
.result .note { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.result .row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.hint2 { margin: 0; padding: 8px 12px; border-radius: 10px; background: #1b3b47; font-size: 14px; line-height: 1.6; text-align: left; }
.hint2::before { content: "もう一歩"; display: block; font-size: 11px; color: var(--amber); }
.hint.deep::before { content: "もう一歩"; }
.linkish { background: none; border: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; font-size: 13px; padding: 4px 8px; }

/* 背の低い画面では盤面を優先して詰める */
@media (max-height: 640px) {
  #app { gap: 6px; padding-block: 6px; }
  .controls button { height: 48px; }
  .hint { font-size: 12px; }
  .qpair { padding: 3px; }
  .qpair .d { width: 12px; height: 12px; }
  .chip { padding: 4px 10px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .chain-pop { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.chain-pop .sub { font-family: var(--body); font-weight: 700; font-size: 16px; color: var(--paper); text-shadow: 0 1px 2px #000; }
.chain-pop.show { animation-duration: 1ms; }
}
