/* シンプル: 白地に黒の線。影とグラデーションは使わない。色は付箋の黄と、金（隠し）と、赤（外れ）だけ。 */
: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 {
  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; 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: -8px 0 -8px -10px; }
/* 押せる幅は 34px。見えるのは中の 11px の輪だけ。開けた段の点はタップでその段に戻る。 */
.dots button { width: 34px; height: 30px; padding: 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; }
@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;
}

/* 金庫 */
.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: 10px;
}
.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.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 { 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); }

/* メモ */
.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 .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; }

/* --- 結果 --- */
.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; }
.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; }

/* 結果は afterHtml（ほかのゲーム）ぶん縦に伸びる。 */
.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); }
