:root {
  --bg: #141a16;
  --bg2: #1c2420;
  --card: #222b26;
  --ink: #f4f0ea;
  --soft: #c8c2b8;
  --mute: #8a928a;
  --line: #3a4540;
  --accent: #d45a2a;
  --accent2: #e8b45a;
  --good: #3d9a62;
  --blue: #4a8fd4;
  --red: #e04a3a;
  --font: "IBM Plex Sans JP", "Hiragino Sans", sans-serif;
  --serif: "Zen Old Mincho", "Hiragino Mincho ProN", serif;
  --w: min(440px, 100%);
  --tabs: 58px;
  --result: 72px;

  /* checker engine remap */
  --panel: var(--card);
  --panel2: #2a342e;
  --pink: var(--accent);
  --pink-dim: #9a3a18;
  --gold: var(--accent2);
  --cyan: #6fcf97;
  --txt: var(--ink);
  --muted: var(--mute);
  --danger: #ff6b5c;
  --seg: var(--serif);
  --body: var(--font);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  padding:
    calc(10px + env(safe-area-inset-top))
    12px
    calc(var(--tabs) + var(--result) + 12px + env(safe-area-inset-bottom));
}
body.mode-log {
  padding-bottom: calc(var(--tabs) + env(safe-area-inset-bottom));
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.mode-log .bar { flex: none; }
body.mode-log #result { display: none; }
body.mode-dex #result,
body.mode-play:not(.yame-on) #result { display: none; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(80% 40% at 100% 0%, rgba(212,90,42,.22), transparent 50%),
    linear-gradient(180deg, #1a201c, #141a16 40%, #101612);
}

.bar {
  width: var(--w);
  margin: 0 auto 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.brand {
  margin: 0;
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: .04em;
}
.bar h1 {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 900;
  line-height: 1.1;
}
.help-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  width: min(360px, 92vw);
  padding: 18px;
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h2 { margin: 0 0 10px; font-family: var(--serif); }
dialog ol { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14px; }
dialog p { color: var(--soft); font-size: 13px; }

.page { width: var(--w); margin: 0 auto; }
.page[hidden] { display: none !important; }

.box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 10px;
}
.box.focus { border-color: rgba(212,90,42,.45); }
.box.how { border-color: rgba(232,180,90,.35); }
.guide-img {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #121816;
}
.box h2, .box h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
}
.sub {
  margin: 4px 0 12px;
  color: var(--mute);
  font-size: 12px;
}
.body { margin: 8px 0 0; color: var(--soft); font-size: 14px; }
.note {
  margin: 10px 0 0;
  color: var(--mute);
  font-size: 12px;
  line-height: 1.5;
}
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.g-row {
  display: grid;
  grid-template-columns: 68px 1fr 68px;
  gap: 8px;
}
.g-row input {
  width: 100%;
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg2);
  color: var(--accent2);
  font: inherit;
  font-size: 34px;
  font-weight: 800;
  text-align: center;
}
.step {
  min-height: 60px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  align-items: center;
}
.pills button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
}
.pills button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pills.rate span {
  font-size: 12px;
  color: var(--mute);
  font-weight: 700;
}
.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.metrics div {
  background: var(--bg2);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}
.metrics em {
  display: block;
  font-style: normal;
  font-size: 10px;
  color: var(--mute);
  font-weight: 700;
}
.metrics b {
  display: block;
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--accent2);
}

.field {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.field:first-of-type { border-top: none; padding-top: 0; }
.field-h {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
}
.field-h small { color: var(--mute); font-weight: 600; }
.q {
  margin: 10px 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--soft);
}
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.seg button {
  min-height: 48px;
  border: 1px solid var(--line);
  background: var(--bg2);
  border-radius: 12px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  text-align: left;
}
.seg button small {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: var(--mute);
  font-weight: 500;
}
.seg button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.seg button.on small { color: rgba(255,255,255,.8); }
.seg button[data-tone="blue"].on { background: var(--blue); border-color: var(--blue); }
.seg button[data-tone="green"].on { background: var(--good); border-color: var(--good); }
.seg button[data-tone="red"].on { background: var(--red); border-color: var(--red); }
.seg button[data-tone="sand"].on { background: #b8892e; border-color: #b8892e; }
.seg button[data-tone="lava"].on { background: #b8441c; border-color: #b8441c; }

.checks { display: grid; gap: 6px; }
.checks label {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--bg2);
  font-size: 14px;
}
.checks input { width: 18px; height: 18px; accent-color: var(--accent); }

.why-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.why-box ul {
  margin: 8px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  color: var(--soft);
  font-size: 13px;
}
.text-btn {
  border: none;
  background: none;
  color: var(--accent2);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}

/* tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--accent2);
  font-size: 11px;
  font-weight: 800;
  background: var(--bg2);
}
tr:last-child td { border-bottom: none; }
td:first-child { font-weight: 700; color: var(--ink); }
.bullets, .olist {
  margin: 8px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--soft);
}
.branch {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.branch:first-of-type { border-top: none; padding-top: 0; }
.branch h3 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--accent2);
  font-family: var(--serif);
}
.branch p { margin: 0; font-size: 13px; color: var(--soft); }

.btn {
  margin-top: 10px;
  min-height: 46px;
  width: 100%;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
}

/* subtabs */
.subtabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 10px;
  padding-bottom: 2px;
  scrollbar-width: none;
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 15;
  background: rgba(20,26,22,.92);
  backdrop-filter: blur(8px);
}
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--mute);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}
.subtabs button.on {
  background: var(--accent2);
  border-color: var(--accent2);
  color: #1a140c;
}
.dex[hidden], .play[hidden] { display: none !important; }

/* result bar */
.result {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(440px, calc(100% - 12px));
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: #2a221c;
  border: 1px solid #5a4030;
  border-radius: 16px 16px 0 0;
  padding: 10px 12px;
  box-shadow: 0 -8px 24px rgba(0,0,0,.35);
}
.result[data-rank="skip"] { background: #2a221c; }
.result[data-rank="short"] { background: #1c3326; border-color: #2f5a40; }
.result[data-rank="sit"] { background: #174c34; border-color: #2f7a4e; }
.result[data-rank="strong"] { background: #6a2814; border-color: #a04a28; }
.result-main strong {
  display: block;
  font-family: var(--serif);
  font-size: 20px;
}
.result-main span {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  opacity: .9;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-side {
  text-align: right;
  display: grid;
  gap: 4px;
  justify-items: end;
}
.result-side b {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1;
}
.result-side button {
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.2);
  color: #fff;
  border-radius: 8px;
  min-height: 32px;
  padding: 0 10px;
  font: inherit;
  font-size: 11px;
  font-weight: 800;
}

/* bottom tabs */
.tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(440px, 100%);
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: #101612;
  border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.tabs button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--mute);
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  min-height: 50px;
  border-radius: 10px;
}
.tabs button.on {
  color: #fff;
  background: rgba(212,90,42,.22);
}

/* log / checker */
.checker-page {
  display: none;
  width: min(440px, 100%);
  margin: 0 auto;
}
body.mode-log .checker-page {
  display: flex !important;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.log-head {
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 0 0 8px;
}
.log-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
}
.log-tools { display: flex; gap: 6px; }
.tool {
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}
.tool.mode.on, #modeBtn.mode.on {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.feed {
  flex: none;
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--mute);
  min-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feed b { color: var(--cyan); }
.log-body {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  background: var(--card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}
.log-tabs {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 14px 14px;
  margin-bottom: 8px;
}
.log-tabs button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--mute);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  min-height: 46px;
  border-top: 2px solid transparent;
}
.log-tabs button.on {
  color: var(--accent2);
  border-top-color: var(--accent2);
}

/* engine pieces */
.sec { margin-bottom: 16px; }
.sec-h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent2);
  margin-bottom: 8px;
}
.sec-h .sub { font-size: 10px; font-weight: 500; color: var(--mute); letter-spacing: 0; margin: 0; }
.cgrid { display: grid; gap: 6px; }
.crow {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}
.crow .lbl { flex: 1; min-width: 0; }
.crow .lbl .nm { font-size: 13px; font-weight: 700; }
.crow .lbl .mn { font-size: 10px; color: var(--mute); }
.crow .num {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--accent);
  min-width: 34px;
  text-align: right;
}
.crow .pct {
  font-size: 11px;
  color: var(--cyan);
  min-width: 62px;
  text-align: right;
}
.crow .plus {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--pink-dim);
  background: rgba(212,90,42,.14);
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.inrow {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 8px;
}
.inrow input {
  flex: 1;
  font-family: var(--serif);
  font-size: 20px;
  text-align: right;
  color: var(--accent2);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  min-height: 44px;
}
.hint { font-size: 10px; color: var(--mute); line-height: 1.5; margin-top: 6px; }
.cardwrap {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
#cardCanvas, #detailCanvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
  background: #000;
}
.btnrow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.btnrow.one { grid-template-columns: 1fr; }
.act {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 800;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--pink-dim);
  background: rgba(212,90,42,.14);
  color: var(--accent);
}
.act.gold { border-color: #8a6c1e; background: rgba(232,180,90,.12); color: var(--accent2); }
.act.plain { border-color: var(--line); background: var(--panel2); color: var(--ink); }
.credit {
  display: none;
}
.out-hero {
  margin: 0 0 12px;
  padding: 14px 14px 12px;
  border-radius: 14px;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(212,162,74,.18), transparent 55%),
    linear-gradient(160deg, #1a261e, #121a16);
  border: 1px solid rgba(212,162,74,.28);
}
.out-kicker {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  color: var(--accent2);
}
.out-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  color: #f3efe4;
}
.out-lead {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--mute);
  line-height: 1.45;
}
.cardwrap.hunt-out {
  border-color: rgba(212,162,74,.3);
  background: linear-gradient(180deg, rgba(26,38,30,.9), rgba(16,22,18,.95));
}
.icon-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.icon-choice {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  min-height: 44px;
  border-radius: 10px;
}
.icon-choice.on {
  border-color: rgba(212,162,74,.55);
  background: rgba(212,162,74,.14);
  color: var(--accent2);
}
textarea#tpl {
  width: 100%;
  height: 220px;
  margin-top: 10px;
  background: #0c1210;
  color: #dfe8dc;
  border: 1px solid rgba(212,162,74,.25);
  border-radius: 12px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.55;
  font-family: var(--font);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(70px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 99;
}
.toast.show { opacity: 1; }
body.minus .crow .plus {
  border-color: #7a3040;
  background: rgba(255,92,92,.14);
  color: var(--danger);
}
.cycle-btn {
  height: 44px;
  min-width: 54px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-weight: 900;
  font-size: 12px;
  padding: 0 8px;
}
.cycle-btn.win { color: #ffc94d; }
.jump-back {
  bottom: calc(var(--tabs) + 12px + env(safe-area-inset-bottom)) !important;
}
.hd-btn { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
