:root {
  --ink: #18181a;
  --dim: #85827a;
  --paper: #f4f3ef;
  --card: #fff;
  --line: #18181a;
  --soft: #e2dfd6;
  --gold: #c99a1c;
  --red: #d6332b;
  --note: #ffe066;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
}

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

button { font-family: inherit; color: inherit; }

#app {
  height: 100dvh;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--paper);
}

@media (min-width: 520px) {
  #app { border-left: 1px solid var(--soft); border-right: 1px solid var(--soft); }
}

.bar-wrap { flex: 0 0 auto; position: relative; overflow: hidden; }
.bar-wrap { margin: 0 -12px; padding: 0 12px; }
#bar {
  position: relative; z-index: 1;
  background: var(--paper);
  padding: 4px 2px 6px;
  border-bottom: 1.5px solid var(--line);
  transition: transform .75s cubic-bezier(.5, 0, .3, 1), opacity .75s;
}
.bar-wrap.open #bar { transform: translateY(-100%); opacity: .2; pointer-events: none; }
.vault {
  position: absolute; inset: 0 12px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--ink);
  opacity: 0; transition: opacity .3s;
}
.bar-wrap.open .vault { opacity: 1; }
.ingot {
  width: 64px; height: 30px;
  background: #f2c230;
  clip-path: polygon(14% 0, 86% 0, 100% 100%, 0 100%);
}
.bar-top { display: flex; align-items: flex-start; gap: 8px; }
.brand { flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 21px; letter-spacing: 2px; font-weight: 800; }
.brand .rule { margin: 2px 0 0; font-size: 12px; color: var(--dim); }
.bar-btns { display: flex; gap: 6px; }
.tool {
  width: 44px; height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.tool .tool-cap {
  position: absolute; bottom: 4px; left: 0; right: 0;
  font-size: 7.5px; line-height: 1.05; color: var(--dim); font-style: normal; text-align: center;
}
#hint > span { margin-top: -15px; font-size: 15px; }
.tool:active { background: var(--ink); color: var(--card); }
.bar-sub { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.dots { display: flex; margin: -16px 0 -7px -11px; }
.dots button { width: 36px; height: 37px; padding: 9px 0 0; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.dots button::before { content: ""; width: 11px; height: 11px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--line); transition: background .12s; }
.dots button.on::before { background: var(--ink); }
.dots.gold button::before { box-shadow: inset 0 0 0 1.5px var(--gold); }
.dots.gold button.on::before { background: var(--gold); }
.dots.buzz { animation: buzz .38s ease-in-out; }
.dots.idle button::before { animation: idle 2.4s ease-in-out infinite; }
.dots.idle button:nth-child(2)::before { animation-delay: .15s; }
.dots.idle button:nth-child(3)::before { animation-delay: .3s; }
.dots.idle button:nth-child(4)::before { animation-delay: .45s; }
@keyframes idle { 50% { box-shadow: inset 0 0 0 2px var(--ink); transform: scale(1.18); } }
.dots.glint button::before { box-shadow: inset 0 0 0 1.5px var(--gold); background: var(--gold); animation: glint .75s ease-out forwards; }
@keyframes glint { 0% { opacity: 1; } 55% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .dots.idle button::before { animation: none; box-shadow: inset 0 0 0 2px var(--ink); } }
@keyframes buzz {
  0%, 100% { transform: none; }
  15% { transform: translateX(-9px); }
  35% { transform: translateX(8px); }
  55% { transform: translateX(-6px); }
  75% { transform: translateX(4px); }
}

#main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  overflow-y: auto;
  padding: 2px 0;
}
@media (orientation: landscape) and (max-height: 500px) {
  #main { justify-content: flex-start; }
}

.safe {
  position: relative;
  perspective: 1000px;
  border-radius: 16px;
  background: var(--card);
  border: 2px solid var(--line);
  padding: 12px;
}
.safe-face { position: relative; transform-origin: left center; }
.safe.opening .safe-face { animation: doorOpen 1.5s ease-in-out forwards; }
.safe.opening .safe-glow { opacity: 1; }
.safe.opening .keypad { pointer-events: none; }
.safe.shake { animation: shake .32s ease-in-out; }
.safe.deep { background: #fbf4df; border-color: #8a6a12; }
.safe.squirm { animation: squirm .66s ease-in-out; }
@keyframes squirm {
  0%, 100% { transform: none; }
  20% { transform: rotate(-1.6deg) scaleY(.985); }
  45% { transform: rotate(1.4deg) scaleX(.985); }
  70% { transform: rotate(-.8deg); }
}
@keyframes doorOpen {
  0% { transform: rotateY(0deg); }
  18% { transform: rotateY(-7deg); }
  70% { transform: rotateY(-104deg); }
  100% { transform: rotateY(-104deg); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.safe-glow {
  position: absolute; inset: 0; border-radius: 14px; pointer-events: none;
  background: rgba(201, 154, 28, .25);
  opacity: 0; transition: opacity .35s;
}
.safe-brand { display: flex; align-items: center; gap: 6px; height: 16px; color: #aaa69c; font-size: 10px; letter-spacing: 3px; }
.safe-brand .bolt { width: 6px; height: 6px; border-radius: 50%; background: var(--ink); }
.display {
  margin: 5px 0 7px;
  height: 48px;
  border-radius: 9px;
  background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  gap: 3px;
}
.slot {
  width: 30px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-bottom: 2px solid #c8c4b8;
  font-size: 28px; font-weight: 700;
  color: var(--ink);
}
.slot.gs { margin-left: 16px; }
.slot.cur { border-bottom-color: var(--ink); animation: blinkline 1s steps(1) infinite; }
@keyframes blinkline { 50% { border-bottom-color: #c8c4b8; } }
.display.close .slot { color: var(--gold); border-bottom-color: var(--gold); }
.display.bad .slot { color: var(--red); border-bottom-color: var(--red); }
.keypad .key { position: relative; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.key {
  min-height: clamp(50px, 7dvh, 62px);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 24px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
  cursor: pointer;
}
.key:active { background: var(--ink); color: var(--card); }
.key b { font-weight: inherit; }
.key small, .key i { display: none; font-style: normal; pointer-events: none; }
.keypad.hintk .key small { display: block; margin-top: 4px; font-size: 10px; font-weight: 500; letter-spacing: .5px; color: var(--dim); animation: kanaIn 1.2s ease-out; }
@keyframes kanaIn { from { opacity: 0; } }
.key.lit { background: var(--ink); color: var(--card); }
.key.lit b, .key.lit small { visibility: hidden; }
.key.lit i { display: flex; position: absolute; inset: 0; align-items: center; justify-content: center; font-size: 28px; font-weight: 700; }
.keypad.kana .key b { position: absolute; top: 5px; left: 8px; font-size: 12px; color: var(--dim); }
.keypad.kana .key small { display: block; font-size: 13px; font-weight: 600; color: var(--ink); animation: kanaIn .5s ease-out; }
.keypad.kana .key small::first-letter { font-size: 23px; font-weight: 700; }
.keypad.kana .key.ans { background: var(--note); }
.keypad.hintk .key.sym small { font-size: 12px; letter-spacing: 2px; }
.keypad.kana .key.sym small, .keypad.kana .key.sym small::first-letter { font-size: 19px; letter-spacing: 3px; }

.hist { flex: 0 0 auto; height: 22px; display: flex; align-items: center; justify-content: center; gap: 4px; }
.try {
  height: 20px; padding: 0 5px;
  border: 1.5px solid var(--red); border-radius: 5px;
  background: var(--card); color: var(--red);
  font-size: 12px; font-weight: 700; line-height: 17px; letter-spacing: 1px;
}
.try.close { border-color: var(--gold); background: #fff3c4; color: #9a7410; }
.try.squirm { transform: rotate(-7deg); }
.hkey { margin-left: 2px; font-size: 10px; color: var(--dim); white-space: nowrap; }
.hkey b { color: var(--gold); }
.hkey b, .hkey i { margin-left: 3px; }
.try { white-space: nowrap; }
.try .hit, .hkey .hit { font-style: normal; text-decoration: underline 2px; text-underline-offset: 2px; }
.hkey .hit { color: var(--ink); }

.note {
  align-self: center;
  position: relative;
  width: 74%;
  border: 0;
  border-radius: 2px;
  background: var(--note);
  color: var(--ink);
  padding: 16px 12px 12px;
  transform: rotate(-1.6deg);
  min-height: 74px;
}
.note-text { display: block; font-size: 30px; letter-spacing: 8px; line-height: 1.15; text-align: center; font-weight: 700; }
.note-text .dk { position: relative; display: inline-block; }
.note-text .dk i { position: absolute; top: .0em; left: .76em; width: .24em; height: .24em; transform-origin: 30% 80%; }
.note-text .dk b { position: absolute; top: 0; width: .09em; height: .22em; border-radius: .04em; background: currentColor; transform: rotate(-28deg); }
.note-text .dk b:first-child { left: 0; }
.note-text .dk b:last-child { left: .14em; }
.note.nudge .dk i { animation: dkNudge 2.6s ease-in-out infinite; }
@keyframes dkNudge {
  0%, 70%, 100% { transform: none; }
  76% { transform: rotate(-22deg) scale(1.15); }
  82% { transform: rotate(18deg) scale(1.15); }
  88% { transform: rotate(-10deg) scale(1.08); }
  94% { transform: none; }
}
@media (prefers-reduced-motion: reduce) { .note.nudge .dk i { animation: none; transform: scale(1.2); } }
.note .pin { position: absolute; top: -5px; left: 50%; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--red); }
.note.blank { background: #f0ead2; }

#foot { flex: 0 0 auto; text-align: center; min-height: 18px; }
.reopen { min-height: 36px; padding: 0 18px; margin-bottom: 4px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font-size: 13px; }
.reopen.hidden { display: none; }
#foot .sn-guide-link { display: block; }
.stuck {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 32px; padding: 0 12px; margin-bottom: 2px;
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--card);
  color: var(--ink); font-size: 12.5px; text-decoration: none;
}
.stuck { position: relative; }
.stuck::before { content: ""; position: absolute; inset: -4px 0 -2px; }
.stuck .xlogo { width: 12px; height: 12px; }
.stuck:active { background: var(--ink); color: var(--card); }
.stuck.hidden { display: none; }

.overlay {
  position: fixed; left: 0; right: 0; top: var(--vvtop, 0px); height: var(--vvh, 100dvh); z-index: 50;
  background: rgba(244, 243, 239, .94);
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
  overflow-y: auto;
}
.overlay.hidden { display: none; }
.panel {
  width: min(94vw, 400px);
  max-height: calc(var(--vvh, 100dvh) - 28px);
  overflow-y: auto;
  border-radius: 18px;
  background: var(--card);
  border: 2px solid var(--line);
  padding: 18px 16px;
  text-align: center;
  position: relative;
}
.pclose {
  position: absolute; top: 6px; right: 6px; width: 40px; height: 40px;
  border: 0; background: transparent; color: var(--dim); font-size: 22px; cursor: pointer;
}
.plate {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 0 0 8px; padding: 4px 12px; border-radius: 8px;
  background: var(--paper); border: 1px solid var(--soft);
  font-size: 14px; letter-spacing: 2px; color: var(--dim);
}
.plate .lock { width: 16px; height: 16px; color: var(--dim); }
.plate.open { border-color: var(--gold); color: var(--gold); }
.plate.open .lock { color: var(--gold); }
.panel h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: 2px; }
.panel .sub { font-size: 11.5px; color: var(--dim); margin-bottom: 12px; }
.ending { display: flex; align-items: center; justify-content: center; gap: 8px; margin: -2px 0 12px; }
.ending b { padding: 2px 9px; border: 1.5px solid var(--line); border-radius: 6px; font-size: 12px; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.ending small { font-size: 12px; font-weight: 700; }
.ending.open b { border-color: var(--gold); background: var(--gold); color: var(--card); }
.ending.open small { color: var(--gold); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat { background: var(--paper); border: 1px solid var(--soft); border-radius: 11px; padding: 9px 6px; }
.stat .k { font-size: 10px; color: var(--dim); }
.stat .v { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat.big { grid-column: 1 / -1; }
.stat.big .v { font-size: 30px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; min-height: 48px; margin-top: 8px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--card);
  color: var(--ink); font-size: 15px; font-weight: 700;
  text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--card); }
.btn.x .xlogo { width: 17px; height: 17px; }

.sn-after { color: var(--ink); }
.sn-guide-link { color: var(--dim); }


.toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 80; max-width: 88vw;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  color: var(--ink); padding: 9px 14px; font-size: 12px; text-align: center;
  transition: opacity .4s, transform .4s;
}
.toast b { display: block; font-size: 14px; margin: 2px 0; }
.toast small { display: block; color: var(--dim); }
.toast.out { opacity: 0; transform: translateX(-50%) translateY(-8px); }
