/* Layout: 夜の縁日の台。上に場（灯り）、中段に相手の手札、親指の届く下段に自分の伏せ札。 */
:root {
  --night: #121829;
  --night-2: #1b2340;
  --night-3: #26304f;
  --line: #34406a;
  --ink: #efe8d8;
  --ink-dim: #a3a9c2;
  --ink-faint: #6b7396;
  --glow: #f4b65c;
  --danger: #ec6a5f;
  --ok: #7fd38a;
  --card-ink: #1a1424;
  --c-r: #e85b52;
  --c-y: #ecc548;
  --c-g: #6cc272;
  --c-b: #5eaaf0;
  --c-p: #bb8fe6;
  --font-display: 'Shippori Mincho B1', 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif JP', serif;
  --font-body: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic', system-ui, sans-serif;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--night);
  background-image: radial-gradient(120% 60% at 50% -10%, #2a2448 0%, transparent 60%);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 2px solid var(--glow); outline-offset: 2px; }

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 8px calc(8px + env(safe-area-inset-bottom, 0px));
}

/* ---------- header ---------- */
.bar { display: flex; align-items: center; gap: 10px; }
.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  margin: 0;
  color: var(--glow);
  text-shadow: 0 0 12px rgba(244, 182, 92, 0.35);
}
.tokens { display: flex; gap: 4px 10px; margin-left: auto; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.tok {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.tok b { color: var(--ink); font-size: 14px; }
.pips { display: inline-flex; gap: 2px; }
.pip { width: 7px; height: 7px; border-radius: 50%; background: var(--glow); }
.pip.off { background: transparent; box-shadow: inset 0 0 0 1px var(--ink-faint); }
.pip.life { background: var(--danger); border-radius: 2px; transform: rotate(45deg); }
.pip.life.off { background: transparent; box-shadow: inset 0 0 0 1px var(--ink-faint); }
.iconbtn {
  background: var(--night-2); border: 1px solid var(--line); border-radius: 8px;
  width: 36px; height: 36px; font-size: 16px; cursor: pointer;
}

/* ---------- stacks ---------- */
.stacks { display: grid; grid-template-columns: repeat(var(--ncol, 5), 1fr); gap: 8px; }
.lantern {
  position: relative;
  border-radius: 16px 16px 12px 12px;
  aspect-ratio: 3 / 3.4;
  display: grid; place-items: center;
  background: var(--night-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.lantern::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to top, var(--col) var(--fill, 0%), transparent var(--fill, 0%));
  opacity: 0.85;
}
.lantern .n {
  position: relative;
  font-family: var(--font-display); font-weight: 800; font-size: 26px; line-height: 1;
  color: var(--ink);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.lantern .s { position: absolute; top: 4px; left: 6px; font-size: 11px; color: var(--col); }
.lantern.lit { box-shadow: 0 0 16px -2px var(--col); }
.lantern .nx {
  position: absolute; bottom: 3px; left: 0; right: 0;
  display: flex; justify-content: center; align-items: center; gap: 2px;
  font-size: 10px; color: var(--ink-dim); white-space: nowrap;
}
.lantern .nx b { font-size: 11px; color: var(--ink); margin: 0 2px 0 1px; }
.lantern .nx i { width: 5px; height: 5px; border-radius: 50%; background: var(--col); }
.lantern .nx i.gone { background: transparent; box-shadow: inset 0 0 0 1px var(--ink-faint); }
.lantern .nx.last b { color: var(--danger); }
.lantern .nx.dead { color: var(--danger); }
.lantern.done .nx { color: var(--card-ink); font-weight: 700; }
.lantern .cap { position: absolute; top: 4px; right: 5px; font-size: 9px; color: var(--danger); }
.lantern.capped { opacity: 0.7; }
.lantern.done .n { color: var(--card-ink); text-shadow: none; }
.lantern.flash { animation: flash 0.9s ease-out; }
@keyframes flash { 0% { transform: scale(1.12); box-shadow: 0 0 28px 4px var(--col); } 100% { transform: scale(1); } }

/* ---------- zones ---------- */
.zone { display: flex; flex-direction: column; gap: 6px; }
.zone-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.who { font-weight: 700; letter-spacing: 0.04em; }
.who small { font-weight: 400; color: var(--ink-dim); margin-left: 4px; font-size: 11px; }
.zone-note { font-size: 11px; color: var(--ink-faint); }
.hand { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.me { margin-top: auto; }

.slot { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card {
  position: relative;
  aspect-ratio: 5 / 7;
  border-radius: var(--radius);
  border: 2px solid transparent;
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  padding: 0;
  width: 100%;
}
.card:active { transform: scale(0.96); }
.card.face { background: var(--col); color: var(--card-ink); }
.card.face .n { font-family: var(--font-display); font-weight: 800; font-size: clamp(26px, 8vw, 36px); line-height: 1; }
.card .s { position: absolute; top: 4px; left: 6px; font-size: 12px; }
.card.face .s { color: var(--card-ink); opacity: 0.75; }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.03) 0 6px, transparent 6px 12px),
    var(--night-3);
  border-color: var(--line);
  color: var(--ink);
}
.card.back.kc { border-color: var(--col); background:
    linear-gradient(to bottom, color-mix(in srgb, var(--col) 45%, transparent), transparent 70%),
    var(--night-3); }
.card.back .n { font-family: var(--font-display); font-weight: 800; font-size: clamp(24px, 7.5vw, 34px); line-height: 1; }
.card.back .n.unk { color: var(--ink-faint); font-size: 20px; }
.card.back .s { color: var(--col, var(--ink-faint)); }
.card.touched { box-shadow: 0 0 0 2px var(--glow), 0 0 16px 2px rgba(244, 182, 92, 0.6); }
.card.preview { box-shadow: 0 0 0 3px var(--ink), 0 0 18px 2px rgba(239, 232, 216, 0.5); transform: translateY(-4px); }
.card.dim { opacity: 0.45; }
.card.selected { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--glow); }
.tag {
  position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%);
  font-size: 10px; padding: 1px 6px; border-radius: 6px 6px 0 0;
  background: var(--night); color: var(--ink-dim); white-space: nowrap;
}
.tag.chop { color: var(--ink-dim); }
.tag.focus { background: var(--glow); color: var(--card-ink); font-weight: 700; }
.tag.mark-play { background: var(--glow); color: var(--card-ink); font-weight: 700; }
.tag.mark-save { background: var(--c-b); color: var(--card-ink); font-weight: 700; }
.tag.latest { animation: pulse 1.2s ease-in-out 2; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.15); } }
.card.fresh { animation: slidein 0.45s ease-out; }
@keyframes slidein { from { transform: translateX(-60%) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
.newdot { position: absolute; top: 4px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--glow); }

/* knowledge pips under a card */
.know { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; justify-items: center; }
.know i {
  display: block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--col);
}
.know i.x { background: transparent; box-shadow: inset 0 0 0 1px var(--ink-faint); opacity: 0.5; }
.know em {
  font-style: normal; font-size: 10px; line-height: 12px; color: var(--ink); font-variant-numeric: tabular-nums;
}
.know em.x { color: var(--ink-faint); opacity: 0.45; text-decoration: line-through; }

/* ---------- banner ---------- */
.banner {
  min-height: 44px;
  border-radius: 10px;
  background: var(--night-2);
  border: 1px solid var(--line);
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.45;
  display: flex; align-items: center; gap: 8px;
}
.banner.turn-me { border-color: var(--glow); }
.banner .who-tag { font-size: 11px; color: var(--ink-dim); white-space: nowrap; }
.banner b { color: var(--glow); }
.banner .bad { color: var(--danger); font-weight: 700; }
.banner .good { color: var(--ok); font-weight: 700; }

.recent { list-style: none; margin: 0; padding: 0 4px; display: grid; gap: 2px; font-size: 12px; color: var(--ink-faint); }
.recent li.mine { color: var(--ink-dim); }
.recent li::before { content: '・'; }
.recent li.alert { color: var(--danger); font-weight: 700; }
.recent li.alert::before { content: '⚠ '; }
.tag.danger { background: var(--danger); color: var(--card-ink); font-weight: 700; }
.card.danger { animation: danger 1.4s ease-in-out infinite; }
@keyframes danger { 50% { box-shadow: 0 0 0 3px var(--danger), 0 0 18px 2px var(--danger); } }

/* ---------- dock ---------- */
.dock { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dockbtn {
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 0; font-size: 13px; color: var(--ink-dim); cursor: pointer;
}

/* ---------- curtain (ふたりモードの受け渡し) ---------- */
.curtain {
  position: fixed; inset: 0; z-index: 30;
  background: var(--night);
  background-image: radial-gradient(90% 50% at 50% 30%, #2a2448 0%, transparent 70%);
  display: grid; place-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.curtain-in { max-width: 420px; width: 100%; display: grid; gap: 14px; text-align: center; }
.curtain-in p { margin: 0; line-height: 1.7; color: var(--ink-dim); }
.curtain-who { font-family: var(--font-display); font-weight: 800; font-size: 28px; color: var(--glow) !important; }
.curtain-last { background: var(--night-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; color: var(--ink) !important; }
.curtain .btn { justify-content: center; }

/* ---------- sheet ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(5, 8, 18, 0.55); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 520px; margin: 0 auto;
  max-height: 82%;
  overflow-y: auto;
  background: var(--night-2);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: 14px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  animation: up 0.18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { font-family: var(--font-display); font-weight: 800; font-size: 18px; margin: 0 0 6px; text-wrap: balance; }
.sheet p { margin: 6px 0; line-height: 1.6; color: var(--ink-dim); }
.sheet .actions { display: grid; gap: 8px; margin-top: 12px; }
.btn {
  border: 1px solid var(--line); background: var(--night-3); border-radius: 10px;
  padding: 12px 14px; font-size: 15px; text-align: left; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.btn small { color: var(--ink-dim); font-size: 12px; }
.btn.primary { background: var(--glow); color: var(--card-ink); border-color: var(--glow); font-weight: 700; }
.btn.primary small { color: rgba(26, 20, 36, 0.7); }
.btn.danger { border-color: var(--danger); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { background: transparent; justify-content: center; color: var(--ink-dim); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--col, var(--night-3)); color: var(--card-ink); font-weight: 700; }

.btn.opt { background: transparent; }
.btn.opt.on { border-color: var(--glow); background: var(--night-3); box-shadow: inset 0 0 0 1px var(--glow); }
.preview-line { margin: 10px 0 0; color: var(--ink); }
.mean { font-weight: 700; }
.warn { color: var(--danger) !important; font-size: 13px; }
.mean.play { color: var(--glow); }
.mean.save { color: var(--c-b); }
.mean.info { color: var(--ink-dim); }
.cands-label { font-size: 12px; }
.cands { display: flex; flex-wrap: wrap; gap: 6px; }
.cand {
  display: inline-flex; align-items: baseline; gap: 2px;
  padding: 3px 8px; border-radius: 6px;
  background: var(--night-3); color: var(--col); font-weight: 700; font-size: 14px;
  border: 1px solid var(--line);
}
.cand small { color: var(--ink-dim); font-weight: 400; font-size: 11px; }
.cand.playable { border-color: var(--glow); box-shadow: 0 0 8px -1px rgba(244, 182, 92, 0.7); }
.cand.trash { opacity: 0.4; text-decoration: line-through; }
.cand.critical { border-color: var(--danger); }

/* rules / log text */
.prose { line-height: 1.7; color: var(--ink); max-width: 65ch; }
.prose h3 { font-size: 14px; margin: 14px 0 4px; color: var(--glow); letter-spacing: 0.05em; }
.prose ul { padding-left: 1.2em; margin: 4px 0; }
.prose li { margin: 2px 0; }
.log { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 13px; }
.log li { padding: 4px 0; border-bottom: 1px dashed var(--line); color: var(--ink-dim); }
.log li.mine { color: var(--ink); }

/* discard grid */
.dgrid { display: grid; grid-template-columns: auto repeat(5, 1fr); gap: 4px 6px; align-items: center; font-size: 12px; }
.dgrid .h { color: var(--ink-faint); text-align: center; }
.dgrid .cname { color: var(--col); font-weight: 700; }
.dcell { display: flex; gap: 2px; justify-content: center; }
.dcell i { width: 8px; height: 12px; border-radius: 2px; background: var(--col); }
.dcell i.gone { background: transparent; box-shadow: inset 0 0 0 1px var(--ink-faint); }
.dcell i.played { opacity: 0.25; }
.dcell.last { outline: 1px solid var(--danger); border-radius: 3px; }

/* end screen */
.review-h { font-size: 14px; margin: 14px 0 4px; color: var(--glow); }
.review { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 13px; }
.review li { padding-left: 1em; text-indent: -1em; }
.review li::before { content: '・'; }
.review .bad-m { color: var(--danger); }
.review .good-m { color: var(--ok); }
.stats { font-size: 12px; }
.endscore { font-family: var(--font-display); font-weight: 800; font-size: 54px; color: var(--glow); line-height: 1; }
.endscore small { font-size: 18px; color: var(--ink-dim); }
.reveal { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.reveal .card { width: 44px; cursor: default; }
.reveal .card .n { font-size: 22px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-height: 640px) {
  #app { gap: 6px; }
  .lantern { aspect-ratio: 3 / 2.6; }
  .lantern .n { font-size: 22px; }
}
