/* SETUP — 和柄 falling-block puzzle. Warm 墨/藍/朱 palette, portrait-first. */
:root {
  --bg: #14110d;          /* 墨 sumi */
  --bg2: #1e1811;
  --panel: rgba(240, 228, 205, 0.06);
  --panel-brd: rgba(240, 228, 205, 0.14);
  --ink: #f3ead6;         /* 生成り off-white */
  --ink-dim: #b7a684;     /* 亜麻 */
  --ai: #3f7cc0;          /* 藍 indigo */
  --shu: #e0483d;         /* 朱 vermilion */
  --kin: #e6b422;         /* 金 gold */
  --matsu: #5a8a5f;       /* 松葉 */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
html, body {
  margin: 0; height: 100%;
  background:
    radial-gradient(1100px 700px at 50% -12%, #2a2114 0%, var(--bg) 62%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Mincho ProN", "Hiragino Sans",
               "Noto Serif JP", "Noto Sans JP", "PingFang TC", "Microsoft JhengHei", serif;
  overflow: hidden; user-select: none; -webkit-user-select: none;
}
#app { display: flex; flex-direction: column; height: 100dvh; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; flex: 0 0 auto; }
.brand { font-weight: 800; font-size: 20px; letter-spacing: 3px; color: var(--ink); }
.brand span { font-size: 11px; font-weight: 500; color: var(--ink-dim); margin-left: 10px; letter-spacing: 2px; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; font-size: 17px;
  background: var(--panel); border: 1px solid var(--panel-brd); color: var(--ink); cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.on { background: rgba(224, 72, 61, 0.22); border-color: rgba(224, 72, 61, 0.5); }

/* top ad strip (self-hosted promo slot) — compact banner tuned for a short slot */
.ad-wrap { flex: 0 0 auto; padding: 3px 12px 0; }
.ad-wrap .adslot {
  height: 66px; border-radius: 10px; margin: 0 auto; max-width: 760px;
  border: 1px solid var(--panel-brd);
}
.ad-wrap .adslot-card-copy { max-width: 74%; gap: 1px; }
.ad-wrap .adslot-card-title { font-size: clamp(13px, 3.6vw, 20px); line-height: 1.1; }
.ad-wrap .adslot-card-sub { font-size: clamp(9px, 2.1vw, 13px); line-height: 1.2; }
.ad-wrap .adslot-card-cta { font-size: clamp(9px, 2vw, 13px); padding: 4px 12px; margin-top: 3px; }
@media (min-width: 900px) { .ad-wrap .adslot { height: 76px; } }

/* stage: hold | board | next */
.stage { flex: 1 1 auto; min-height: 0; display: flex; align-items: stretch; justify-content: center; gap: 12px; padding: 4px 12px 8px; }
.sidebar { flex: 0 0 auto; width: 128px; display: flex; flex-direction: column; gap: 12px; padding-top: 6px; }
.sidebar.right { align-items: flex-start; }
.panel { background: var(--panel); border: 1px solid var(--panel-brd); border-radius: 14px; padding: 10px; }
.panel-title { font-size: 12px; font-weight: 700; color: var(--ink-dim); margin-bottom: 6px; letter-spacing: 2px; }
.panel-title small { display: block; font-size: 9px; opacity: 0.7; letter-spacing: 2px; }
#hold-cv, #next-cv { display: block; width: 100%; height: auto; }
.next-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.next-mini { width: 100%; height: auto; opacity: 0.9; }

/* stats */
.stats { display: flex; flex-direction: column; gap: 8px; }
.stat { background: var(--panel); border: 1px solid var(--panel-brd); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 11px; color: var(--ink-dim); }
.stat-label small { font-size: 9px; opacity: 0.7; margin-left: 4px; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }
.stat.combo b { color: var(--kin); }

/* board */
.board-wrap { position: relative; flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
#board {
  display: block; max-width: 100%; max-height: 100%;
  background: rgba(10, 8, 6, 0.78);
  border: 2px solid var(--panel-brd); border-radius: 10px;
  box-shadow: 0 0 40px rgba(224, 72, 61, 0.10), inset 0 0 30px rgba(0, 0, 0, 0.55);
}

/* banner */
.banner {
  position: absolute; top: 18%; left: 50%; transform: translate(-50%, -50%) scale(0.8);
  font-weight: 900; font-size: clamp(20px, 5vw, 36px); letter-spacing: 3px; text-align: center;
  pointer-events: none; color: #fff; opacity: 0;
  text-shadow: 0 0 18px var(--kin), 0 2px 6px rgba(0, 0, 0, 0.7);
}
.banner.show { animation: pop 1.1s ease forwards; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  30% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

/* controls */
.controls { flex: 0 0 auto; padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; max-width: 560px; margin: 0 auto; width: 100%; }
.ctrl-row { display: flex; gap: 8px; justify-content: center; }
.pad {
  flex: 1 1 0; height: 56px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--panel-brd); color: var(--ink);
  font-size: 22px; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform 0.05s, background 0.1s;
}
.pad.small { font-size: 15px; letter-spacing: 1px; }
.pad.active, .pad:active { background: rgba(63, 124, 192, 0.22); transform: scale(0.96); }
#btn-rotcw, #btn-rotccw { color: var(--ai); }
#btn-hard { color: var(--shu); }

/* overlays */
.screen { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: rgba(10, 8, 6, 0.84); backdrop-filter: blur(6px); border-radius: 10px; padding: 16px; }
.screen-card {
  text-align: center; max-width: 360px; width: 100%;
  background: linear-gradient(180deg, rgba(42, 33, 22, 0.94), rgba(20, 16, 12, 0.96));
  border: 1px solid var(--panel-brd); border-radius: 18px; padding: 22px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 3px;
  color: var(--kin); background: rgba(230, 180, 34, 0.12); border: 1px solid rgba(230, 180, 34, 0.35);
  border-radius: 999px; padding: 5px 12px; margin-bottom: 12px;
}
.badge.over { color: var(--shu); background: rgba(224, 72, 61, 0.12); border-color: rgba(224, 72, 61, 0.35); }
.screen-card h1 {
  margin: 4px 0 8px; font-size: 40px; font-weight: 900; letter-spacing: 6px;
  color: var(--ink);
  text-shadow: 0 0 22px rgba(224, 72, 61, 0.4);
}
.over-title small { display: block; font-size: 12px; color: var(--ink-dim); letter-spacing: 4px; }
.tag { font-size: 14px; color: var(--ink-dim); line-height: 1.7; margin: 8px 0 16px; }
.tag b { color: var(--kin); }
.btn-primary {
  width: 100%; padding: 14px; border: none; border-radius: 14px; cursor: pointer;
  font-size: 16px; font-weight: 800; color: #fff7ea; letter-spacing: 1px;
  background: linear-gradient(90deg, var(--shu), #ff6a52);
  box-shadow: 0 8px 24px rgba(224, 72, 61, 0.35);
}
.btn-primary:active { transform: translateY(1px); }
.motion-status { margin-top: 10px; font-size: 11px; color: var(--ink-dim); min-height: 14px; }
.best { margin-top: 14px; font-size: 13px; color: var(--ink-dim); }
.best small { font-size: 10px; opacity: 0.7; margin-left: 2px; }
.best b { color: var(--ink); font-size: 16px; margin-left: 4px; }
.howto { margin-top: 14px; font-size: 12px; color: var(--ink-dim); line-height: 1.8; text-align: left; }
.howto-row { margin: 5px 0; }
.howto .k { display: inline-block; background: var(--panel); border: 1px solid var(--panel-brd); border-radius: 6px; padding: 1px 7px; color: var(--ink); font-size: 11px; margin: 0 2px; }
.howto kbd { background: var(--panel); border: 1px solid var(--panel-brd); border-radius: 5px; padding: 1px 5px; font-size: 11px; color: var(--ink); }
.disclaimer { margin-top: 16px; font-size: 10px; color: rgba(183, 166, 132, 0.7); line-height: 1.5; }
.result { display: flex; justify-content: space-around; margin: 14px 0; background: var(--panel); border: 1px solid var(--panel-brd); border-radius: 14px; padding: 14px 8px; }
.result > div { display: flex; flex-direction: column; gap: 4px; }
.result span { font-size: 11px; color: var(--ink-dim); }
.result b { font-size: 22px; font-variant-numeric: tabular-nums; }
.new-best { margin: 8px 0 14px; font-weight: 800; color: var(--kin); font-size: 14px; letter-spacing: 1px; }

/* motion calibration */
.calib-title { letter-spacing: 4px; }
.calib-steps { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 10px; }
.cstep {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--panel-brd); border-radius: 12px;
  color: var(--ink-dim); transition: all 0.18s;
}
.cstep .cico {
  width: 30px; height: 30px; flex: 0 0 30px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: rgba(240, 228, 205, 0.08); font-size: 16px; color: var(--ink);
}
.cstep .ctxt { flex: 1 1 auto; text-align: left; font-size: 14px; color: var(--ink); }
.cstep .ctxt small { color: var(--ink-dim); font-size: 10px; margin-left: 6px; }
.cstep .cchk { font-size: 18px; font-weight: 900; color: transparent; }
.cstep.current {
  background: rgba(230, 180, 34, 0.16); border-color: rgba(230, 180, 34, 0.6);
  color: var(--ink); box-shadow: 0 0 0 1px rgba(230, 180, 34, 0.35);
}
.cstep.current .cico { background: rgba(230, 180, 34, 0.3); }
.cstep.current .ctxt { color: var(--kin); font-weight: 800; }
.cstep.done {
  background: rgba(90, 138, 95, 0.20); border-color: rgba(90, 138, 95, 0.55);
}
.cstep.done .cico { background: rgba(90, 138, 95, 0.35); }
.cstep.done .cchk { color: var(--matsu); }
.cstep.done { animation: cpop 0.28s ease; }
@keyframes cpop { 0% { transform: scale(1); } 45% { transform: scale(1.04); } 100% { transform: scale(1); } }
.calib-motion { font-size: 12px; line-height: 1.5; margin: 4px 0 8px; color: var(--ink-dim); }
.calib-motion.ok { color: var(--matsu); }
.calib-motion.warn {
  color: #ffd9a8; background: rgba(224, 72, 61, 0.12);
  border: 1px solid rgba(224, 72, 61, 0.35); border-radius: 10px; padding: 8px 10px;
}
.calib-hint { font-size: 11px; color: rgba(183, 166, 132, 0.7); margin: 4px 0 12px; }
.btn-ghost {
  width: 100%; padding: 12px; border-radius: 14px; cursor: pointer; font-size: 14px; font-weight: 700;
  color: var(--ink-dim); background: transparent; border: 1px solid var(--panel-brd);
}
.btn-ghost:active { transform: translateY(1px); background: var(--panel); }

/* email + OTP login */
.auth-h { margin: 6px 0 2px; font-size: 24px; font-weight: 800; color: var(--ink); letter-spacing: 2px; }
.auth-input {
  width: 100%; padding: 14px; margin: 4px 0 10px; border-radius: 12px;
  background: rgba(10, 8, 6, 0.6); border: 1px solid var(--panel-brd); color: var(--ink);
  font-size: 16px; text-align: center; outline: none;
}
.auth-input:focus { border-color: rgba(224, 72, 61, 0.6); }
.auth-input.otp { letter-spacing: 12px; font-size: 26px; font-weight: 800; padding-left: 12px; }
.auth-input::placeholder { color: rgba(183, 166, 132, 0.5); letter-spacing: normal; }
.auth-remember {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  font-size: 12px; color: var(--ink-dim); margin: 2px 0 14px; cursor: pointer;
}
.auth-remember input { width: 16px; height: 16px; accent-color: var(--shu); }
.auth-err { min-height: 16px; margin-top: 8px; font-size: 12px; color: var(--shu); }
.auth-links { display: flex; justify-content: space-between; margin-top: 12px; }
.linkbtn { background: none; border: none; color: var(--ink-dim); font-size: 12px; cursor: pointer; text-decoration: underline; padding: 4px; }
.linkbtn:active { color: var(--ink); }
.auth-dev {
  margin-top: 12px; min-height: 0; font-size: 12px; color: var(--kin);
  font-variant-numeric: tabular-nums;
}
.auth-dev:not(:empty) {
  padding: 8px; border: 1px dashed rgba(230, 180, 34, 0.5); border-radius: 8px;
  background: rgba(230, 180, 34, 0.08);
}

/* first-entry age / gender gate */
.gate-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 18px;
  background:
    radial-gradient(900px 600px at 50% -10%, #2a2114 0%, #100d09 65%),
    #100d09;
}
.gate-card {
  text-align: center; max-width: 380px; width: 100%;
  background: linear-gradient(180deg, rgba(42, 33, 22, 0.96), rgba(20, 16, 12, 0.98));
  border: 1px solid var(--panel-brd); border-radius: 20px; padding: 26px 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.gate-mark {
  width: 78px; height: 78px; margin: 0 auto 14px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 900; color: #fff7ea;
  background: linear-gradient(180deg, var(--shu), #b8352c);
  box-shadow: 0 8px 24px rgba(224, 72, 61, 0.4); border: 2px solid rgba(255, 220, 200, 0.4);
}
.gate-mark span { font-size: 20px; margin-left: 1px; }
.gate-mark.block { background: linear-gradient(180deg, #6b6b6b, #3f3f3f); box-shadow: none; }
.gate-card h2 { margin: 6px 0 4px; font-size: 22px; font-weight: 800; color: var(--ink); letter-spacing: 1px; }
.gate-sub { font-size: 13px; color: var(--ink-dim); margin: 2px 0 18px; line-height: 1.6; }
.gate-btns { display: flex; flex-direction: column; gap: 10px; }
.gate-btns.two { flex-direction: row; }
.gender-btn {
  flex: 1 1 0; padding: 18px 10px; border-radius: 16px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 17px; font-weight: 800; color: var(--ink);
  background: var(--panel); border: 1px solid var(--panel-brd); transition: transform 0.06s, background 0.15s, border-color 0.15s;
}
.gender-btn small { font-size: 11px; color: var(--ink-dim); font-weight: 500; }
.gender-btn .g-ico { font-size: 30px; line-height: 1; }
#gate-male .g-ico { color: var(--ai); }
#gate-female .g-ico { color: #e08aa0; }
.gender-btn:active { transform: scale(0.96); }
.gender-btn:hover { border-color: rgba(240, 228, 205, 0.35); background: rgba(240, 228, 205, 0.1); }
.gate-card .disclaimer { margin-top: 18px; }

.mobile-only { display: none; }
.desktop-only { display: block; }

@media (max-width: 640px) {
  .sidebar { width: 84px; }
  .stat b { font-size: 16px; }
  .desktop-only { display: none; }
  .mobile-only { display: block; }
}
@media (max-width: 460px) {
  .stage { gap: 6px; padding: 4px 6px 6px; }
  .sidebar { width: 66px; }
  .panel { padding: 7px; border-radius: 11px; }
  .panel-title small { display: none; }
  .stat { padding: 6px 7px; }
  .stat-label small { display: none; }
  .next-list .next-mini:nth-child(n+3) { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .controls { max-width: none; flex-direction: row; }
  .ctrl-row { flex-direction: column; flex: 1; }
  .pad { height: 44px; }
}
@media (min-width: 900px) and (pointer: fine) { .controls { display: none; } }
