/* Konbini Roulette · "a gachapon machine at 2am". Every value traces to konbini/design/DESIGN.md. */
:root {
  /* ground and machine (DESIGN Colour) */
  --night: #0e1310;
  --body: #1a211c;
  --body-2: #232b25;
  --line: #2f3931;
  --lit: #f3efe0;
  --dim: #8e978f;
  --hanko: #d62b1f;
  /* rarity tiers = curse levels 1-5, colour means nothing else */
  --t1: #9aa59b; --t2: #3f8fe0; --t3: #e2a41c; --t4: #f06a2a; --t5: #b33be0;
  /* chain colour, header panel only */
  --chain: #f26b1d;
  /* receipt paper */
  --paper: #fffef7; --ink: #1d1b18;
  /* personal tier list S-D (Me tab) */
  --tier-s: #ff5c5c; --tier-a: #ff9f43; --tier-b: #ffd24d; --tier-c: #8fd16b; --tier-d: #7fb2ff;
  --bar-h: 64px;
  --word: "Zen Maru Gothic", system-ui, sans-serif;
  --num: "DotGothic16", ui-monospace, monospace;
  --seal: "Zen Antique", "Zen Maru Gothic", serif;
  color-scheme: dark;
}
body[data-chain="lawson"] { --chain: #0068b7; }
body[data-chain="fm"] { --chain: #00913a; }
body[data-chain="ms"] { --chain: #0b4ea2; }
body[data-chain="any"] { --chain: #5d574b; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--night); color: var(--lit);
  font-family: var(--word); font-weight: 500; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom));
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- app bar and tab bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--night) 90%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { margin: 0; font-weight: 900; font-size: 1.15rem; letter-spacing: .02em; color: var(--lit); }
.brand span { color: var(--dim); }
.pts-pill { border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; background: var(--body); color: var(--lit); font-family: var(--num); font-size: 1rem; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--bar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--body); border-top: 1px solid var(--line);
}
.tabbar button { border: 0; background: transparent; display: grid; place-items: center; align-content: center; gap: 2px; font-size: .72rem; font-weight: 700; color: var(--dim); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar svg .dot { fill: currentColor; stroke: none; }
.tabbar button.on { color: var(--lit); }

.wrap { max-width: 480px; margin: 0 auto; padding: 14px 16px 24px; }
.tab { display: grid; gap: 16px; }
h2 { margin: 0; font-size: 1.15rem; }
h3 { margin: 0 0 4px; font-size: 1rem; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 8px 13px; font-weight: 700; font-size: .9rem; color: var(--lit); }
.seg button.on { background: var(--lit); border-color: var(--lit); color: var(--night); }
.panel { background: var(--body); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.field { display: grid; gap: 6px; }
.field.row { grid-template-columns: 1fr auto; align-items: center; }
.label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--dim); }
select { border: 1px solid var(--line); background: var(--night); color: var(--lit); border-radius: 10px; padding: 7px 10px; font-weight: 700; }

/* ---------- the machine (DESIGN Grid) ---------- */
.machine { background: var(--body); border: 1px solid var(--line); border-radius: 22px; overflow: hidden; display: grid; }

/* header panel: the only chain-coloured surface, lit from inside */
.m-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px;
  background: var(--chain); color: #fff;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18), 0 0 28px color-mix(in srgb, var(--chain) 45%, transparent);
}
.m-store { margin: 0; font-weight: 900; font-size: 1.35rem; line-height: 1.1; letter-spacing: .01em; }
.m-area { margin: 2px 0 0; font-size: .8rem; opacity: .85; }
.m-edit { width: 38px; height: 38px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); background: transparent; color: #fff; font-size: 1rem; }
.m-edit[aria-expanded=true] { background: #fff; color: var(--chain); }
.controls { display: grid; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--body-2); }

/* fact strip: price, item count, tier range (P1) */
.m-facts { margin: 0; padding: 10px 16px; font-family: var(--num); font-size: 1rem; color: var(--lit); border-bottom: 1px dashed var(--line); letter-spacing: .02em; }
.m-facts .rng b { font-weight: 400; }

/* lineup card: vibe + tier legend */
.m-lineup { padding: 12px 16px; display: grid; gap: 10px; border-bottom: 1px dashed var(--line); }
.vibes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.vibes button { padding: 9px 4px; font-size: .88rem; border-color: var(--line); }
.legend { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.tier { display: grid; justify-items: center; gap: 1px; padding: 5px 2px; border-radius: 8px; border: 1px solid var(--line); color: var(--dim); font-family: var(--num); font-size: .72rem; opacity: .5; }
.tier b { font-size: 1rem; font-weight: 400; line-height: 1; }
.tier.lit { opacity: 1; color: #fff; border-color: transparent; }
.tier.t1.lit { background: var(--t1); color: #111; } .tier.t2.lit { background: var(--t2); } .tier.t3.lit { background: var(--t3); color: #111; }
.tier.t4.lit { background: var(--t4); } .tier.t5.lit { background: var(--t5); }
.tier.t5 b { font-family: var(--seal); }

/* price plates (budget) */
.plates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 16px; border-bottom: 1px dashed var(--line); }
.plates button {
  border: 1px solid var(--line); background: var(--night); color: var(--dim); border-radius: 10px; padding: 6px 4px 8px;
  font-family: var(--num); font-size: 1.15rem; display: grid; justify-items: center; line-height: 1.15;
}
.plates button small { font-family: var(--word); font-size: .68rem; font-weight: 700; letter-spacing: .1em; }
.plates button.on { background: var(--lit); color: var(--night); border-color: var(--lit); }

/* window where capsules land: insert cards */
.window { padding: 12px; background: var(--night); }
.reels { display: grid; gap: 10px; }
.reel {
  position: relative; display: grid; grid-template-columns: 112px 1fr; align-items: center; gap: 12px;
  background: var(--body); border: 1px solid var(--line); border-radius: 14px; padding: 10px; overflow: hidden;
}
.reel .cap { position: relative; }
.reel .thumb {
  width: 112px; height: 112px; border-radius: 10px; border: 0; padding: 0;
  /* the capsule half-sphere: the only gradient allowed (Refusal 7) */
  background: radial-gradient(circle at 50% 50%, #2e3830 0 40%, #3a463c 40.5% 43%, #1b221d 43.5%);
  display: grid; place-items: center; font-size: 2.8rem; overflow: hidden; cursor: default;
}
.reel .thumb:has(img) { background: #fff; cursor: zoom-in; }
.reel .thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.reel .info { display: grid; gap: 5px; min-width: 0; }
.reel .head { display: flex; align-items: flex-start; gap: 6px; min-width: 0; }
.reel .no { font-family: var(--num); font-size: .78rem; color: var(--dim); white-space: nowrap; }
.reel .slotname { font-size: .72rem; font-weight: 700; color: var(--dim); line-height: 1.3; padding-top: 2px; flex: 1; min-width: 0; }
.curse { font-family: var(--num); font-size: .78rem; border-radius: 6px; padding: 1px 7px; color: #fff; white-space: nowrap; }
.curse b { font-weight: 400; margin-right: 4px; }
.curse[data-c="1"] { background: var(--t1); color: #111; } .curse[data-c="2"] { background: var(--t2); } .curse[data-c="3"] { background: var(--t3); color: #111; }
.curse[data-c="4"] { background: var(--t4); } .curse[data-c="5"] { background: var(--t5); }
.curse[data-c="5"] b { font-family: var(--seal); }
.reel .name { font-weight: 700; font-size: 1rem; line-height: 1.3; overflow-wrap: anywhere; }
.reel .pack { font-size: .85rem; line-height: 1.35; background: var(--night); border-radius: 6px; padding: 4px 7px; }
.reel .pack small { display: block; font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }
.reel .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.reel .price { font-family: var(--num); font-size: 1.35rem; white-space: nowrap; }
.reel .got { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: .82rem; white-space: nowrap; }
.reel .swap { justify-self: start; border: 0; background: none; padding: 2px 0; color: var(--dim); font-size: .78rem; text-decoration: underline; text-underline-offset: 2px; }
.reel.found { border-color: var(--lit); }
.reel.found .got { background: var(--lit); border-color: var(--lit); color: var(--night); }
.reel.found .thumb img { opacity: .35; }
.reel.found .cap::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 3rem; font-weight: 900; color: var(--night); pointer-events: none; }
.reel.spinning .info, .reel.spinning .thumb { filter: blur(1.5px); opacity: .75; }
.reel.spinning .got, .reel.idle .got, .reel.spinning .curse, .reel.idle .curse, .reel.spinning .swap, .reel.idle .swap { visibility: hidden; }
.reel.spinning .pack, .reel.idle .pack, .reel.idle .swap { display: none; }
.reel.landed { animation: drop .35s ease-out; }
/* Before the first turn the window shows closed capsules in one row, so the crank stays on screen. */
.reels.waiting { grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
.reel.idle { grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 10px 4px; gap: 6px; }
.reel.idle .thumb { width: 64px; height: 64px; font-size: 1.5rem; }
.reel.idle .info { justify-items: center; }
.reel.idle .head { flex-direction: column; gap: 0; }
.reel.idle .name, .reel.idle .row { display: none; }
@keyframes drop { 0% { transform: translateY(-10px); } 60% { transform: translateY(3px); } 100% { transform: none; } }

/* NEW mark (P5) */
.new { position: absolute; bottom: 6px; left: 6px; font-family: var(--num); font-size: .7rem; background: var(--lit); color: var(--night); border-radius: 4px; padding: 0 5px; }

/* hanko: cursed items, claimed receipt (MOTIFS 3) */
.hanko {
  position: absolute; display: grid; place-items: center; width: 44px; height: 44px; border: 3px solid var(--hanko); border-radius: 6px;
  color: var(--hanko); font-family: var(--seal); font-size: 1.5rem; line-height: 1; transform: rotate(-12deg);
  background: color-mix(in srgb, #fff 70%, transparent); pointer-events: none;
}
.reel .hanko { right: -6px; bottom: -6px; }
.reel.landed .hanko { animation: thunk .18s ease-out .2s both; }
@keyframes thunk { from { transform: rotate(-12deg) scale(1.4); opacity: 0; } to { transform: rotate(-12deg) scale(1); opacity: 1; } }

/* 故障中 tape on a swapped-in card (P2) */
.tape {
  position: absolute; top: -2px; left: 50%; transform: translateX(-50%) rotate(-7deg); background: #c9a86a; color: #3b2a12;
  font-family: var(--seal); font-size: .8rem; padding: 1px 14px; white-space: nowrap; opacity: .95; box-shadow: 0 1px 2px rgba(0,0,0,.4); pointer-events: none;
}

/* crank */
.crank-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 14px; padding: 14px 16px 16px; }
.crank {
  position: relative; width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--lit);
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.18), 0 0 24px color-mix(in srgb, var(--lit) 30%, transparent);
  transition: transform .55s cubic-bezier(.25, 1, .5, 1);
}
.crank-bar { position: absolute; left: 50%; top: 10px; bottom: 10px; width: 18px; margin-left: -9px; border-radius: 9px; background: var(--night); }
.crank.turning { transform: rotate(360deg); }
.crank:disabled { opacity: .6; cursor: not-allowed; }
.crank-label { margin: 0; font-family: var(--num); font-size: 1.5rem; letter-spacing: .06em; }
.crank-label.blink { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rules { margin: 2px 0 0; color: var(--dim); font-size: .82rem; }

/* ---------- receipt ---------- */
.receipt {
  position: relative; background: var(--paper); color: var(--ink); font-family: var(--num); padding: 22px 20px 26px;
  border-radius: 4px; box-shadow: 0 12px 30px -14px rgba(0,0,0,.6);
  -webkit-mask: linear-gradient(#000 0 0) top / 100% calc(100% - 8px) no-repeat, radial-gradient(circle at 8px 8px, transparent 7px, #000 7.5px) bottom left / 16px 8px repeat-x;
          mask: linear-gradient(#000 0 0) top / 100% calc(100% - 8px) no-repeat, radial-gradient(circle at 8px 8px, transparent 7px, #000 7.5px) bottom left / 16px 8px repeat-x;
}
.r-head { text-align: center; border-bottom: 1px dashed #bbb; padding-bottom: 10px; }
.r-store { margin: 0; font-size: 1.2rem; }
.r-date { margin: 2px 0 0; font-size: .8rem; color: #777; }
.r-items { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 12px; }
.r-items li { display: grid; gap: 6px; }
.r-line { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.r-line a { color: inherit; text-decoration: none; }
.r-line .ja { display: block; font-size: .72rem; color: #888; margin-top: 2px; }
.r-meta { font-size: .72rem; color: #888; }
.rate { display: flex; gap: 4px; }
.rate button { border: 1px solid #ccc; background: transparent; border-radius: 6px; width: 32px; height: 28px; font-family: inherit; font-size: .8rem; color: #555; }
.rate button.on { color: #fff; border-color: transparent; }
.rate button[data-t=S].on { background: var(--tier-s); } .rate button[data-t=A].on { background: var(--tier-a); }
.rate button[data-t=B].on { background: var(--tier-b); color: #333; } .rate button[data-t=C].on { background: var(--tier-c); }
.rate button[data-t=D].on { background: var(--tier-d); }
.r-total, .r-sub, .r-points { display: flex; justify-content: space-between; gap: 10px; }
.r-total { border-top: 1px dashed #bbb; padding-top: 10px; font-size: 1.3rem; }
.r-sub { font-size: .85rem; color: #666; }
.r-points { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #bbb; font-size: 1.1rem; }
.r-points span:last-child { white-space: nowrap; }
.claim { width: 100%; margin-top: 12px; border: 0; border-radius: 12px; padding: 14px; background: var(--ink); color: var(--paper); font-family: var(--word); font-weight: 900; font-size: 1.05rem; }
.claim:disabled { background: #d6d1c6; color: #7a756b; cursor: not-allowed; }
.claim.done:disabled { background: #e9e4d6; color: var(--ink); }
.r-foot { font-size: .75rem; color: #888; text-align: center; margin: 10px 0; }
.r-actions { display: flex; justify-content: center; gap: 8px; }
.r-actions button { border: 1px solid var(--ink); background: transparent; color: var(--ink); border-radius: 8px; padding: 7px 14px; font-family: inherit; }
.r-actions button.primary { background: var(--ink); color: var(--paper); }
.r-stamp { bottom: 110px; right: 8px; width: 72px; height: 72px; font-size: 2.6rem; border-width: 4px; border-radius: 50%; animation: thunk .18s ease-out both; }

/* ---------- ranking: arcade high-score table (P4) ---------- */
#tab-rank h2 { font-family: var(--num); font-weight: 400; font-size: 1.6rem; letter-spacing: .08em; text-align: center; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.board li, .board-me { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; background: var(--body); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.rk { font-family: var(--num); font-size: 1.2rem; text-align: center; color: var(--dim); }
.board li:nth-child(-n+3) { background: var(--body-2); }
.board li:nth-child(-n+3) .rk { color: var(--lit); }
.nm { font-weight: 700; overflow-wrap: anywhere; }
.nm small { display: block; font-weight: 500; font-size: .75rem; color: var(--dim); }
.pt { font-family: var(--num); font-size: 1.15rem; white-space: nowrap; }
.board li.me, .board-me { border-color: var(--lit); }
.board-me { position: sticky; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 8px); }
.empty { color: var(--dim); font-size: .9rem; margin: 0; text-align: center; }
.soon p { margin: 0 0 10px; color: var(--dim); font-size: .9rem; }
.soon button { border: 1px dashed var(--line); background: transparent; border-radius: 10px; padding: 8px 14px; color: var(--dim); }

/* ---------- me ---------- */
.me-card { display: grid; gap: 8px; }
.me-name { margin: 0; font-size: 1.4rem; font-weight: 900; overflow-wrap: anywhere; }
.link { border: 0; background: none; padding: 0; color: var(--lit); font-weight: 700; justify-self: start; text-decoration: underline; text-underline-offset: 3px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.stats div { background: var(--night); border-radius: 12px; padding: 10px 6px; display: grid; gap: 2px; text-align: center; }
.stats b { font-family: var(--num); font-size: 1.35rem; font-weight: 400; }
.stats span { font-size: .72rem; color: var(--dim); }
.tiers h2, .how h2 { margin-bottom: 10px; }
.tier-row { display: grid; grid-template-columns: 38px 1fr; gap: 8px; align-items: start; margin-bottom: 6px; }
.tier-badge { border-radius: 8px; height: 34px; display: grid; place-items: center; font-weight: 900; color: #fff; }
.tier-items { display: flex; flex-wrap: wrap; gap: 4px; min-height: 34px; align-items: center; }
.chip { font-size: .78rem; background: var(--night); border: 1px solid var(--line); border-radius: 8px; padding: 3px 7px; }
.chip i { font-style: normal; opacity: .6; font-size: .7rem; }
.how-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.how-row:last-of-type { border-bottom: 0; }
.how-row > b { font-family: var(--num); font-weight: 400; font-size: 1.1rem; }
.how .tier { display: inline-grid; grid-auto-flow: column; gap: 6px; opacity: 1; padding: 3px 8px; font-size: .85rem; }
.how p { margin: 10px 0 0; font-size: .85rem; color: var(--dim); }
.foot { color: var(--dim); font-size: .75rem; text-align: center; }
.foot p { margin: 4px 0; }

/* ---------- overlays ---------- */
.zoom { position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 9, .94); display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.zoom figure { margin: 0; display: grid; gap: 12px; justify-items: center; max-width: 480px; width: 100%; }
.zoom img { width: 100%; max-height: 62vh; object-fit: contain; background: #fff; border-radius: 14px; }
.zoom figcaption { text-align: center; display: grid; gap: 4px; }
.zoom .z-name { font-weight: 700; font-size: 1.1rem; }
.zoom .z-ja { font-size: 1rem; color: var(--dim); }
.zoom .z-price { font-family: var(--num); font-size: 1.5rem; }

.sheet { border: 1px solid var(--line); border-radius: 20px; padding: 20px; width: min(420px, calc(100vw - 32px)); background: var(--body); color: var(--lit); }
.sheet::backdrop { background: rgba(0, 0, 0, .6); }
.sheet form { display: grid; gap: 12px; }
.sheet input { border: 1px solid var(--line); background: var(--night); color: var(--lit); border-radius: 12px; padding: 12px; font-size: 1.1rem; font-weight: 700; }
.sheet .err { margin: 0; min-height: 1.2em; color: var(--hanko); font-size: .85rem; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sheet-actions button { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 9px 16px; font-weight: 700; }
.sheet-actions .primary { background: var(--lit); border-color: var(--lit); color: var(--night); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  opacity: 0; pointer-events: none; z-index: 60; background: var(--lit); color: var(--night);
  padding: 10px 16px; border-radius: 12px; font-weight: 700; transition: .25s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .crank, .reel.landed, .reel .hanko, .r-stamp, .crank-label.blink { animation: none !important; transition: none !important; }
}
