/* 紙・黒線。影とグラデーションは使わない。色は出られたドアとランプの黄だけ。 */
:root {
  --ink: #30302e;
  --dim: #8b887f;
  --paper: #f5f4ef;
  --card: #fff;
  --soft: #d9d6cd;
  --yellow: #f2d64b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; background: var(--paper); touch-action: manipulation; overscroll-behavior: none; }

body {
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", system-ui, sans-serif;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button { font-family: inherit; color: inherit; touch-action: manipulation; -webkit-touch-callout: none; }
p, h1, a, button { word-break: auto-phrase; text-wrap: pretty; }

#app {
  position: relative;
  height: var(--app-h, 100dvh);
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
}
@media (min-width: 520px) { #app { border-left: 1px solid var(--soft); border-right: 1px solid var(--soft); } }

/* --- 帯 --- */
.band { flex: 0 0 auto; padding: 8px 12px 2px; }
.band .r { display: flex; align-items: center; gap: 8px; }
.title { margin: 0; font-size: 18px; font-weight: 900; letter-spacing: .06em; white-space: nowrap; }
.tools { margin-left: auto; display: flex; gap: 6px; }
.tool {
  position: relative; height: 28px; padding: 0 9px; font-size: 12px; font-weight: 700; white-space: nowrap;
  border: 1.5px solid var(--ink); border-radius: 4px; background: var(--card); cursor: pointer;
}
.tool.snd { width: 28px; padding: 0; line-height: 1; font-size: 14px; }
/* 見た目は小さいまま、指の当たりだけ広げる */
.tool::before { content: ""; position: absolute; inset: -5px -3px; }
.tool.snd::before { inset: -5px -8px -5px -3px; }
.tool.snd.off::after { content: ""; position: absolute; left: 4px; right: 4px; top: 50%; border-top: 1.5px solid var(--ink); transform: rotate(-40deg); }
.rule { margin: 4px 0 0; font-size: 13px; color: var(--ink); white-space: nowrap; }

#main { flex: 1 1 auto; overflow: hidden; display: flex; flex-direction: column; }
#main.scroll { overflow-y: auto; overscroll-behavior: contain; }
#foot { flex: 0 0 auto; padding: 4px 14px 8px; font-size: 12px; text-align: center; }
#foot:empty { display: none; }
#foot .sn-guide-link { position: relative; }
#foot .sn-guide-link::before { content: ""; position: absolute; inset: -4px -6px; }

/* --- 遊ぶ面 --- */
.play { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; touch-action: none; }
.tabs { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 6px 12px; }
.tab {
  position: relative; display: flex; align-items: center; gap: 5px; height: 34px; padding: 0 10px 0 11px;
  border: 1.5px solid var(--ink); border-radius: 6px; background: var(--card); cursor: pointer; font-size: 16px; white-space: nowrap;
}
.tab b { font-weight: 900; font-variant-numeric: tabular-nums; }
.tab .lamp { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--card); }
.tab.on { background: var(--ink); color: #fff; }
.tab.on .lamp { border-color: #fff; }
.tab .lamp.out { background: var(--yellow); }
.tab .lamp.stale { background: var(--soft); }
.tab:disabled { opacity: .25; cursor: default; }
.tab.pulse { animation: wiggle .6s ease 2; animation-delay: var(--d, 0s); }
@keyframes wiggle { 0%, 70%, 100% { transform: none; } 15% { transform: translateY(-3px) rotate(-9deg); } 35% { transform: translateY(-3px) rotate(8deg); } 55% { transform: rotate(-4deg); } }
@media (prefers-reduced-motion: reduce) { .tab.pulse { animation: none; } }
.again {
  margin-left: auto; width: 38px; height: 34px; border: 1.5px solid var(--ink); border-radius: 6px; background: var(--card); cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.again.nudge { animation: nudge .9s ease infinite; }
@keyframes nudge { 0%, 60%, 100% { transform: none; } 20% { transform: rotate(-12deg); } 40% { transform: rotate(10deg); } }
.again svg, .key svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.stage { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 6px; }
#cv { display: block; touch-action: none; }

.pad { flex: 0 0 auto; display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
.pg { display: flex; gap: 10px; }
.key {
  width: 74px; height: 62px; border: 2px solid var(--ink); border-radius: 10px; background: var(--card); cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center; touch-action: none;
}
.key svg { width: 30px; height: 30px; }
.key.down { background: var(--ink); color: #fff; }
@media (max-height: 600px) { .key { height: 54px; } .pad { padding-top: 4px; } }

/* --- 結果 --- */
.result { flex: 1 1 auto; padding: 14px 12px 8px; text-align: center; overflow-y: auto; overscroll-behavior: contain; }
.result .doors { width: 76%; max-width: 280px; margin: 6px auto 14px; display: block; }
.result .msg { margin: 0 0 12px; font-size: 18px; font-weight: 900; white-space: nowrap; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 4px; width: 100%; max-width: 320px; height: 46px; margin: 8px auto;
  font-size: 16px; font-weight: 700; border: 2px solid var(--ink); border-radius: 6px; background: var(--card); color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn.x { background: var(--ink); color: #fff; }
.xlogo { width: 18px; height: 18px; }
.sn-after { margin-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 30%; transform: translateX(-50%); padding: 8px 14px; font-size: 14px; white-space: nowrap;
  background: var(--card); border: 1.5px solid var(--ink); border-radius: 4px; transition: opacity .5s; z-index: 10; pointer-events: none;
}
.toast.out { opacity: 0; }
