/* なぞ箱屋
   VOICE: 夜の古道具屋の主人。短く、値札と帳面の口調
   PICTURE: ランプの下のカウンター。主役は箱から出てくる品の光
   COLOUR: 墨色と古い木、緑のフェルト、真鍮。鮮やかなのは品の光だけ
   LAYOUT: 上に細い所持金の帯、下に帳面のような札。開けている間は中央に字を置かない */
:root {
  --ink: #2a2118; --paper: #efe4cc; --paper2: #e2d4b4; --brass: #c9a25a; --brass2: #8a6a34;
  --bg: #0e0b09; --red: #b8402a; --green: #2e6a4a; --muted: #8a7f6c; --txt: #f2eadb;
  --g0: #cfc6b4; --g1: #8fd0ff; --g2: #ffd36a; --g3: #ff8ad8;
  --safe-b: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--txt); font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font-family: inherit; border: 0; cursor: pointer; color: inherit; background: none; }
b, .num { font-variant-numeric: tabular-nums; }

/* 上の帯 */
#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 16px; background: linear-gradient(rgba(10, 8, 6, .92), rgba(10, 8, 6, .72)); border-bottom: 1px solid rgba(201, 162, 90, .25); }
.money { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 3px; min-width: 0; }
.money b { font-size: 27px; font-weight: 900; letter-spacing: .01em; transition: color .3s; }
.money b.up { color: #ffd76a; } .money b.down { color: #ff9a8a; }
.money small { font-size: 14px; font-weight: 700; }
#rate { width: 100%; font-size: 12px; color: #c9bfae; font-weight: 700; }
#rate em { font-style: normal; color: #9fe0a8; }
nav { display: flex; gap: 6px; flex: none; }
.nb { position: relative; height: 40px; min-width: 50px; padding: 0 11px; border-radius: 10px; background: rgba(255, 240, 210, .08); border: 1px solid rgba(255, 240, 210, .12); font-size: 14px; font-weight: 700; color: #ece2cf; }
.nb:active { transform: translateY(1px); background: rgba(255, 240, 210, .16); }
.nb i { display: block; font-style: normal; font-size: 10px; color: #a89d88; line-height: 1; margin-top: 1px; }
.nb .dot { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: #ffcf5a; box-shadow: 0 0 6px #ffcf5a; }

/* 操作の手引き */
#guide { position: fixed; z-index: 9; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 72px); pointer-events: none; }
#guide p { font-size: 14px; font-weight: 700; color: #f6ecd8; background: rgba(14, 11, 9, .78); padding: 7px 14px; border-radius: 999px; border: 1px solid rgba(255, 230, 190, .16); white-space: nowrap; animation: fadein .3s; }

/* 値札 */
#tags { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.tag { position: absolute; transform: translate(-50%, 0); background: var(--paper); color: var(--ink); border-radius: 3px 3px 5px 5px; padding: 3px 9px 4px; text-align: center; box-shadow: 0 3px 8px rgba(0, 0, 0, .5); white-space: nowrap; transition: opacity .2s, transform .2s; }
.tag::before { content: ''; position: absolute; left: 50%; top: -9px; width: 1px; height: 9px; background: rgba(240, 225, 190, .6); }
.tag::after { content: ''; position: absolute; left: calc(50% - 3px); top: 3px; width: 6px; height: 6px; border-radius: 50%; background: rgba(0, 0, 0, .2); }
.tag b { display: block; font-size: 16px; font-weight: 900; line-height: 1.25; margin-top: 4px; }
.tag span { font-size: 11px; font-weight: 700; color: #6a5a44; }
.tag.sel { background: #ffe8a8; transform: translate(-50%, -4px) scale(1.06); }
.tag.free { background: #c8e8c0; }
.tag.no b { color: #a8402a; }
.tag.mini { padding: 2px 6px 3px; }
.tag.mini b { font-size: 12px; margin-top: 3px; }
.tag.mini span { font-size: 9px; }

/* 下の札（帳面） */
#panel { position: fixed; z-index: 8; left: 0; right: 0; bottom: 0; padding: 12px 14px calc(var(--safe-b) + 14px); background: linear-gradient(rgba(14, 11, 9, 0), rgba(14, 11, 9, .9) 18px); animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(16px); opacity: 0; } }
@keyframes fadein { from { opacity: 0; } }
.card { background: var(--paper); color: var(--ink); border-radius: 10px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(120, 90, 40, .25); max-width: 520px; margin: 0 auto; }
.card h2 { font-size: 20px; font-weight: 900; line-height: 1.3; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .meta { font-size: 12px; color: #6a5a44; font-weight: 700; margin-top: 2px; }
.card .val { font-size: 30px; font-weight: 900; margin-top: 4px; line-height: 1.15; }
.card .val small { font-size: 15px; }
.card .val .delta { font-size: 14px; margin-left: 6px; color: var(--green); }
.card .hintline { margin-top: 6px; font-size: 14px; font-weight: 700; padding: 7px 10px; border-radius: 7px; background: #e2d4b4; color: #4a3c2a; }
.card .hintline em { font-style: normal; color: #8a7458; font-size: 11px; display: block; }
.grade { display: inline-block; font-size: 12px; font-weight: 900; padding: 2px 8px; border-radius: 999px; background: #d8cdb6; color: #5a4c38; }
.grade.g1 { background: #cfe8ff; color: #1c4a7a; } .grade.g2 { background: #ffe7a0; color: #7a5200; } .grade.g3 { background: linear-gradient(90deg, #ffc2e8, #c8d4ff, #c2ffe0); color: #5a1c5a; }
.grade.scar { background: #f0c8bc; color: #8a2a1a; }
.newb { font-size: 11px; font-weight: 900; background: var(--red); color: #fff; padding: 2px 7px; border-radius: 4px; }
.row { display: flex; gap: 8px; margin-top: 10px; }
.btn { flex: 1; min-height: 50px; border-radius: 9px; font-size: 16px; font-weight: 900; background: var(--ink); color: var(--paper); padding: 6px 8px; line-height: 1.2; box-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.btn small { display: block; font-size: 11px; font-weight: 700; opacity: .8; margin-top: 2px; }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: .38; }
.btn.gold { background: linear-gradient(#e0bc6a, #b88c3c); color: #2a1c08; }
.btn.green { background: #2e5a40; color: #f0f6e8; }
.btn.red { background: #8a3024; color: #fff2ea; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px rgba(42, 33, 24, .5); }
.btn.lite { flex: none; padding: 6px 14px; background: #d8cab0; color: var(--ink); }
.repair { width: 100%; margin-top: 10px; display: flex; align-items: center; justify-content: space-between; text-align: left; gap: 8px; }
.repair .rk { font-size: 15px; }
.repair .rk em { display: block; font-style: normal; font-size: 11px; opacity: .85; font-weight: 700; }
.repair .rr { text-align: right; font-size: 13px; }
.repair .rr b { display: block; font-size: 15px; }
.risk { color: #ffb4a4; } .gold .risk { color: #8a2a14; }
.steps { display: flex; gap: 4px; margin-top: 8px; }
.steps i { flex: 1; height: 5px; border-radius: 3px; background: #d4c6a8; }
.steps i.on { background: #b88c3c; } .steps i.x { background: #b8402a; }

.mk { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; margin: 0 auto 6px; max-width: 520px; scrollbar-width: none; touch-action: pan-x; }
.mk::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 11px; border-radius: 999px; font-size: 13px; font-weight: 700; background: rgba(255, 240, 210, .1); color: #e8dcc6; border: 1px solid rgba(255, 240, 210, .15); }
.chip.on { background: var(--paper); color: var(--ink); }
.chip.lock { opacity: .55; }
.chip.lock em { font-style: normal; font-size: 11px; margin-left: 4px; }
.chip.new { box-shadow: 0 0 0 2px #ffcf5a; }
.free { display: flex; justify-content: center; margin: 0 auto 8px; max-width: 520px; }
.freeb { font-size: 13px; font-weight: 900; padding: 8px 14px; border-radius: 999px; background: #2e5a40; color: #f0f6e8; box-shadow: 0 0 0 2px rgba(160, 230, 170, .3); animation: glow 1.6s infinite; }
.freeb.wait { background: rgba(255, 240, 210, .08); color: #a89d88; box-shadow: none; animation: none; font-weight: 700; }
@keyframes glow { 50% { box-shadow: 0 0 0 5px rgba(160, 230, 170, .15); } }
.tip { text-align: center; font-size: 13px; color: #cfc4b0; font-weight: 700; margin-bottom: 6px; }
.tip b { color: #fff3d8; }

/* 全面の札（図鑑・店） */
#sheet { position: fixed; inset: 0; z-index: 20; background: rgba(6, 5, 4, .72); display: flex; align-items: flex-end; justify-content: center; animation: fadein .2s; }
.sheetIn { position: relative; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; background: var(--paper); color: var(--ink); border-radius: 16px 16px 0 0; padding: 18px 16px calc(var(--safe-b) + 22px); touch-action: pan-y; animation: up .25s ease-out; }
.close { position: absolute; right: 10px; top: 8px; width: 40px; height: 40px; font-size: 26px; color: #6a5a44; }
.sheetIn h3 { font-size: 21px; font-weight: 900; }
.sheetIn h4 { font-size: 14px; font-weight: 900; margin: 16px 0 6px; display: flex; justify-content: space-between; }
.sheetIn h4 span { font-weight: 700; color: #7a6a52; font-size: 12px; }
.sheetIn .lead { font-size: 13px; color: #5a4c38; font-weight: 700; margin-top: 4px; line-height: 1.6; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cell { background: #e6d9bc; border-radius: 8px; padding: 6px 4px 7px; text-align: center; position: relative; }
.cell img { width: 100%; aspect-ratio: 1; display: block; }
.cell p { font-size: 11px; font-weight: 900; line-height: 1.3; min-height: 2.6em; display: flex; align-items: center; justify-content: center; }
.cell.unk p { color: #9a8a70; }
.cell .gd { position: absolute; top: 5px; left: 5px; width: 9px; height: 9px; border-radius: 50%; }
.cell .cnt { position: absolute; top: 3px; right: 6px; font-size: 10px; color: #7a6a52; font-weight: 700; }
.bonus { margin-top: 10px; background: #2a2118; color: #f0e4c8; border-radius: 9px; padding: 10px 12px; font-size: 13px; font-weight: 700; line-height: 1.7; }
.bonus b { color: #ffd76a; }
.shopRow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px dashed rgba(42, 33, 24, .25); }
.shopRow div { font-size: 14px; font-weight: 900; }
.shopRow div small { display: block; font-size: 12px; color: #6a5a44; font-weight: 700; margin-top: 2px; }
.shopRow .btn { flex: none; min-width: 120px; min-height: 46px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.stats div { background: #e6d9bc; border-radius: 8px; padding: 8px 10px; font-size: 11px; font-weight: 700; color: #6a5a44; }
.stats b { display: block; font-size: 17px; color: var(--ink); }
.toggle { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 14px; font-weight: 700; }

/* 知らせ */
#toasts { position: fixed; z-index: 30; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 112px); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: rgba(20, 16, 12, .92); border: 1px solid rgba(255, 215, 140, .35); color: #fff1d6; font-size: 14px; font-weight: 700; padding: 8px 16px; border-radius: 999px; animation: toast 2.6s forwards; max-width: 90vw; text-align: center; }
.toast b { color: #ffd76a; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 10%, 82% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.pop { position: fixed; z-index: 7; pointer-events: none; font-weight: 900; font-size: 22px; color: #ffe08a; text-shadow: 0 2px 6px rgba(0, 0, 0, .7); transform: translate(-50%, -50%); animation: pop 1.1s forwards; }
.pop.bad { color: #ff9a8a; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.8); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -160%); } }
#flash { position: fixed; inset: 0; z-index: 6; pointer-events: none; background: #fff6e0; opacity: 0; }
#flash.on { animation: flash .6s ease-out; }
#flash.red { background: #ff6a50; }
@keyframes flash { 0% { opacity: .75; } 100% { opacity: 0; } }

/* はじめの画面 */
#start { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; background: radial-gradient(ellipse at 50% 35%, rgba(255, 200, 120, .16), rgba(14, 11, 9, .92) 60%), rgba(14, 11, 9, .55); text-align: center; padding: 24px; transition: opacity .5s; }
#start.out { opacity: 0; pointer-events: none; }
.logo .sub { font-size: 14px; letter-spacing: .3em; color: #c9a25a; font-weight: 700; }
.logo h1 { font-size: clamp(48px, 15vw, 76px); font-weight: 900; letter-spacing: .08em; color: #f6ead2; text-shadow: 0 4px 30px rgba(255, 190, 90, .35); margin: 4px 0 12px; }
.logo .lead { font-size: 15px; line-height: 1.8; color: #e0d4bc; font-weight: 700; }
#go { min-width: 200px; height: 56px; border-radius: 999px; font-size: 18px; font-weight: 900; background: linear-gradient(#e8c470, #b88c3c); color: #2a1c08; box-shadow: 0 6px 24px rgba(230, 180, 90, .35); }
#go:disabled { opacity: .5; }
#start .note { font-size: 12px; color: #8a7f6c; font-weight: 700; }

.modal { text-align: center; }
.modal .big { font-size: 34px; font-weight: 900; margin: 6px 0; }
