:root {
  --board: #16302b;
  --board-2: #1d3d36;
  --board-line: #2f5a50;
  --chalk: #f2efe4;
  --chalk-dim: #b9c6bd;
  --paper: #fbf6e9;
  --paper-2: #efe6cf;
  --ink: #2b2620;
  --ink-dim: #6f6656;
  --accent: #f0b429;
  --accent-ink: #3a2a00;
  --danger: #e2574c;
  --ok: #58c28e;
  --str: #d9483b;
  --spd: #1f9e8f;
  --int: #2f6fd0;
  --gut: #d97a1e;
  --sen: #b04fc4;
  --tag: #3f8fc9;
  --shadow: 0 6px 18px rgba(0, 0, 0, .35);
  font-family: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--board); color: var(--chalk); overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
h1, h2, h3 { font-family: "Klee One", "Zen Kaku Gothic New", sans-serif; font-weight: 600; margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  border: 1px solid var(--board-line); background: var(--board-2); color: var(--chalk);
  border-radius: 10px; padding: 10px 16px; min-height: 42px; font-weight: 700;
}
.btn:hover { background: #26493f; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #f7c54d; }
.btn.danger { background: transparent; border-color: var(--danger); color: #ffb3ac; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 14px; color: var(--chalk-dim); }
.field input, .field select, .input {
  background: #0f2420; color: var(--chalk); border: 1px solid var(--board-line); border-radius: 8px;
  padding: 10px 12px; min-height: 42px; width: 100%;
}
.err { color: #ffb3ac; font-size: 14px; min-height: 1.2em; }
.muted { color: var(--chalk-dim); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- ログインとホーム ---- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 20px 16px; }
.auth-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; }
.logo { font-family: "Klee One", sans-serif; font-size: 40px; line-height: 1.15; text-align: center; letter-spacing: .04em; }
.logo small { display: block; font-size: 14px; color: var(--chalk-dim); letter-spacing: .1em; margin-bottom: 6px; }
.tabs { display: flex; border-bottom: 1px solid var(--board-line); }
.tabs button { flex: 1; background: none; border: 0; padding: 10px; color: var(--chalk-dim); border-bottom: 3px solid transparent; font-weight: 700; }
.tabs button.on { color: var(--chalk); border-bottom-color: var(--accent); }

.page { max-width: 1040px; margin: 0 auto; min-height: 100%; padding: 16px 16px 40px; display: flex; flex-direction: column; gap: 18px; }
.topbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar h1 { font-size: 24px; }
.panel { background: var(--board-2); border: 1px solid var(--board-line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { font-size: 19px; }
.menu-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.menu-grid .panel { justify-content: space-between; }
@media (max-width: 640px) { .menu-grid { grid-template-columns: 1fr; } }
.record { display: flex; gap: 18px; font-size: 14px; color: var(--chalk-dim); flex-wrap: wrap; }
.record b { color: var(--chalk); font-size: 18px; }
.history li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--board-line); font-size: 14px; flex-wrap: wrap; }
.history { list-style: none; margin: 0; padding: 0; }
.win { color: var(--ok); font-weight: 700; }
.lose { color: #ff9a90; font-weight: 700; }
.code-box { font-family: "Klee One", monospace; font-size: 34px; letter-spacing: .2em; text-align: center; padding: 10px; border: 2px dashed var(--accent); border-radius: 10px; color: var(--accent); }
.banner { background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 12px 16px; display: flex; gap: 12px; align-items: center; font-weight: 700; flex-wrap: wrap; }

/* ---- カード ---- */
.card {
  --c: var(--ink-dim);
  position: relative; background: var(--paper); color: var(--ink); border-radius: 10px;
  border: 2px solid var(--c); overflow: hidden; display: flex; flex-direction: column;
  text-align: left; padding: 0; box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
.a-str { --c: var(--str); } .a-spd { --c: var(--spd); } .a-int { --c: var(--int); } .a-gut { --c: var(--gut); } .a-sen { --c: var(--sen); }
.t-battle { --c: #3d7a4e; } .t-event { --c: #c24d7c; } .t-item { --c: #8a6d3b; } .t-field { --c: #4a5a9e; }
.card .art {
  position: relative; display: grid; place-items: center; color: rgba(255, 255, 255, .92);
  background: linear-gradient(150deg, var(--c), color-mix(in srgb, var(--c) 55%, #1a1a1a));
  font-family: "Klee One", serif;
}
.art-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 14%; display: block; }
.card .cost { position: absolute; top: 3px; left: 3px; display: flex; gap: 2px; flex-wrap: wrap; z-index: 1; }
.tok {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: 11px; font-weight: 700;
  border: 1px solid rgba(0, 0, 0, .35); background: #fff; color: #333; line-height: 1; font-family: "Zen Kaku Gothic New", sans-serif;
}
.tok.G { background: #5fbf6a; color: #06300c; } .tok.R { background: #e05a4e; color: #fff; }
.tok.Y { background: #f3cf3f; color: #3a2d00; } .tok.B { background: #4a96e0; color: #fff; }
.tok.str { background: var(--str); color: #fff; } .tok.spd { background: var(--spd); color: #fff; }
.tok.int { background: var(--int); color: #fff; } .tok.gut { background: var(--gut); color: #fff; } .tok.sen { background: var(--sen); color: #fff; }
.tok.only { outline: 2px solid #fff; outline-offset: -3px; }

.card-full { width: min(300px, 78vw); flex: none; }
.card-full .art { height: clamp(170px, 30dvh, 280px); font-size: 62px; }
.card-full .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 7px; }
.card-full .name { font-family: "Klee One", sans-serif; font-size: 21px; line-height: 1.2; }
.card-full .role { font-size: 12px; color: var(--ink-dim); }
.card-full .ctype { z-index: 1; position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 99px; }
.card-full .text { font-size: 13.5px; line-height: 1.55; }
.card-full .ab { font-size: 13.5px; line-height: 1.5; background: var(--paper-2); border-radius: 6px; padding: 6px 8px; }
.card-full .ab b { font-size: 13.5px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.stat { text-align: center; border-radius: 6px; padding: 3px 0; background: var(--paper-2); font-size: 11px; color: var(--ink-dim); }
.stat b { display: block; font-size: 18px; line-height: 1.1; color: var(--ink); }
.stat.s-str b { color: var(--str); } .stat.s-spd b { color: var(--spd); } .stat.s-int b { color: var(--int); } .stat.s-gut b { color: var(--gut); } .stat.s-sen b { color: var(--sen); }
.kibar { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.kibar .track { flex: 1; height: 8px; background: #ddd2b8; border-radius: 99px; overflow: hidden; }
.kibar .fill { height: 100%; background: var(--ok); }
.kibar .fill.low { background: var(--danger); }

/* ---- シート（下から出る確認画面） ---- */
.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 70; display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { background: var(--board-2); border: 1px solid var(--board-line); border-radius: 16px; padding: 16px; width: min(560px, 100%); max-height: 90dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.sheet h3 { font-size: 18px; }
.sheet-body { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; align-items: flex-start; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 180px; }
.opt { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--board-line); background: #0f2420; color: var(--chalk); border-radius: 8px; padding: 8px 11px; min-height: 40px; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.chip:disabled { opacity: .35; }
.pay-row { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; border-bottom: 1px dotted var(--board-line); }
.pay-row .lbl { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--chalk-dim); }
@media (max-width: 480px) { .sheet-back { align-items: flex-end; padding: 0; } .sheet { border-radius: 16px 16px 0 0; width: 100%; } }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; background: #000; color: #fff; padding: 9px 16px; border-radius: 99px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 92vw; }
#toast.show { opacity: .92; }

/* ---- デッキ編集 ---- */
.dk-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; height: 100dvh; padding: 12px 14px; }
.dk-col { display: flex; flex-direction: column; min-height: 0; gap: 8px; }
.dk-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.dk-filters select, .dk-filters input { background: #0f2420; color: var(--chalk); border: 1px solid var(--board-line); border-radius: 8px; padding: 7px 9px; min-height: 38px; }
.dk-filters input { flex: 1; min-width: 110px; }
.dk-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 9px; align-content: start; padding: 2px; }
.dk-cell { position: relative; }
.dk-cell .card-hand { width: 100%; }
.dk-count { position: absolute; right: 5px; top: 44px; background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 1px 8px; font-size: 13px; font-weight: 700; pointer-events: none; }
.dk-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.dk-line { display: flex; align-items: center; gap: 6px; background: var(--board-2); border-radius: 7px; padding: 4px 6px 4px 9px; font-size: 13.5px; border-left: 4px solid var(--c, #666); }
.dk-line .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: 0; padding: 4px 0; text-align: left; }
.dk-line .n { width: 22px; text-align: center; font-weight: 700; }
.dk-line button.step { width: 32px; height: 32px; border-radius: 7px; background: #0f2420; border: 1px solid var(--board-line); font-weight: 700; flex: none; }
.dk-line .lead { font-size: 11px; color: var(--accent-ink); background: var(--accent); border-radius: 99px; padding: 0 6px; flex: none; }
.dk-sum { font-size: 13px; color: var(--chalk-dim); display: flex; gap: 10px; flex-wrap: wrap; }
.dk-sum b.bad { color: #ffb3ac; } .dk-sum b.good { color: var(--ok); }
.dk-tabs { display: none; }
.deck-tile { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--board-line); flex-wrap: wrap; }
.deck-tile .nm { font-weight: 700; flex: 1; min-width: 150px; }

.rules { line-height: 1.7; font-size: 15px; }
.rules h1 { font-size: 26px; } .rules h2 { font-size: 20px; margin-top: 18px; color: var(--accent); }
.rules table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rules th, .rules td { border: 1px solid var(--board-line); padding: 6px 8px; text-align: left; vertical-align: top; }
.rules ul, .rules ol { padding-left: 22px; }

/* ---- スマホ ---- */
@media (max-width: 820px) {
  .dk-layout { grid-template-columns: minmax(0, 1fr); padding: 8px 10px; }
  .dk-tabs { display: flex; }
  .dk-col.hide { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
