:root {
  --bg: #15171b;
  --bg2: #1d2026;
  --card: #23272e;
  --card2: #2b3038;
  --line: #363c46;
  --text: #ece8e1;
  --muted: #9aa0a8;
  --gold: #d6a84a;
  --gold2: #f0cf7a;
  --accent: #c8553d;
  --green: #5fae6e;
  --blue: #5b8fd6;
  --danger: #d9534f;
  --radius: 14px;
  --tabh: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#view {
  padding: calc(var(--safe-t) + 12px) 16px calc(var(--tabh) + var(--safe-b) + 24px);
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
}

/* ---------- タブバー ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabh) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(21, 23, 27, .96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
#tabbar button {
  background: none; border: 0; color: var(--muted);
  font-size: 10px; letter-spacing: .04em; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#tabbar .ti { font-size: 22px; line-height: 1; }
#tabbar button.on { color: var(--gold2); }

/* ---------- 共通 ---------- */
h1 { font-size: 22px; margin: 4px 0 12px; letter-spacing: .02em; }
h2 { font-size: 16px; margin: 0 0 10px; color: var(--gold2); letter-spacing: .04em; }
h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card2); font-weight: 700;
}
.btn.primary { background: linear-gradient(180deg, #e0b457, #b8862f); color: #1b1407; border-color: #e7c06a; }
.btn.danger { background: #3a2323; border-color: #6b3434; color: #ffb4ae; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 60px; font-size: 18px; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.chip {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--card2);
  font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--gold); color: #1b1407; border-color: var(--gold2); font-weight: 700; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--card2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pr { background: #4a3710; color: var(--gold2); border-color: #7a5a1a; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg2); border-radius: 12px; padding: 4px; margin-bottom: 12px; border: 1px solid var(--line); }
.seg button { background: none; border: 0; min-height: 40px; border-radius: 9px; color: var(--muted); font-weight: 700; font-size: 14px; }
.seg button.on { background: var(--card2); color: var(--text); }
.gauge { height: 12px; background: #0e1013; border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.gauge > i { display: block; height: 100%; background: linear-gradient(90deg, #b8862f, var(--gold2)); border-radius: 99px; transition: width .8s ease; }
.gauge.part > i { background: linear-gradient(90deg, #3f6ea8, #7fb0ec); }
input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  background: #121418; border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

/* ---------- HOME ---------- */
.home-head { display: flex; align-items: center; justify-content: space-between; }
.lv-badge { display: flex; align-items: baseline; gap: 6px; }
.lv-badge b { font-size: 34px; color: var(--gold2); line-height: 1; font-variant-numeric: tabular-nums; }
.lv-badge small { color: var(--muted); font-weight: 700; }
.coin { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; background: var(--card); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; }
.coin::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff2b8, #d6a84a 55%, #8a6417); }
.stage {
  position: relative; height: 46vh; min-height: 300px; max-height: 440px;
  display: flex; justify-content: center; align-items: flex-end;
  background: radial-gradient(ellipse at 50% 70%, #2d3440 0%, var(--bg) 70%);
  border-radius: 20px; margin: 8px 0 12px; overflow: hidden;
}
.stage svg { height: 100%; width: auto; }
.stage .title { position: absolute; left: 14px; top: 12px; font-size: 13px; color: var(--gold2); font-weight: 700; letter-spacing: .1em; }
.stage .view-hint { position: absolute; right: 12px; top: 10px; font-size: 12px; color: var(--muted); }
.bubble {
  position: absolute; bottom: 20%; right: 10px; max-width: 36%;
  background: #f4efe6; color: #2a2118; padding: 10px 12px; border-radius: 14px;
  font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.35);
  animation: pop .4s ease;
}
.bubble::after { content: ""; position: absolute; left: -8px; bottom: 14px; border: 8px solid transparent; border-right-color: #f4efe6; border-left: 0; }
button.bubble { border: 0; text-align: left; }
.exp-line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 6px; }
.quest { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.quest:first-of-type { border-top: 0; }
.quest .ck { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 14px; }
.quest.done .ck { background: var(--green); border-color: var(--green); color: #0d1a10; }
.quest.done .qt { color: var(--muted); text-decoration: line-through; }
.quest .rw { font-size: 12px; color: var(--gold2); white-space: nowrap; }
.qprog { height: 6px; margin-top: 4px; }

/* ---------- 閲覧モード ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 60; background: radial-gradient(ellipse at 50% 65%, #333c4a 0%, #0b0c0f 75%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 20px) 16px calc(var(--safe-b) + 20px);
}
.viewer svg { height: 78vh; width: auto; max-width: 100%; animation: breathe 4s ease-in-out infinite; transform-origin: 50% 95%; }
.viewer .cap { color: var(--gold2); font-weight: 700; letter-spacing: .12em; text-align: center; }

/* ---------- TRAINING ---------- */
.tr-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.tr-head input[type=date] { width: auto; min-height: 36px; padding: 4px 8px; font-size: 14px; }
.prev-panel {
  position: sticky; top: calc(var(--safe-t)); z-index: 5;
  min-height: 22vh; max-height: 25vh; overflow-y: auto;
  background: linear-gradient(180deg, #1f2a36, #1b222b); border: 1px solid #34465a;
  border-radius: var(--radius); padding: 12px 14px; margin: 0 -4px 12px;
  box-shadow: 0 8px 18px rgba(0,0,0,.35);
}
.prev-panel .lbl { font-size: 11px; letter-spacing: .12em; color: #8fb4de; font-weight: 700; }
.prev-panel .nm { font-weight: 800; font-size: 17px; }
.prev-sets { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin-top: 6px; font-size: 15px; }
.prev-sets .s { color: var(--muted); font-size: 13px; }
.prev-sets .memo { color: #bcd3ee; font-size: 13px; }
.ex-card { padding: 12px; }
.ex-card.focus { border-color: var(--gold); }
.ex-card .ex-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ex-card .ex-name { font-weight: 800; font-size: 17px; flex: 1; min-width: 0; }
.set-row { display: grid; grid-template-columns: 44px 1fr 1fr 44px; gap: 8px; align-items: center; margin-bottom: 8px; }
.set-row .sn { font-size: 12px; color: var(--muted); font-weight: 800; text-align: center; line-height: 1.1; }
.set-row .sn b { display: block; font-size: 18px; color: var(--text); }
.inp { position: relative; }
.inp input, .memo-row input { scroll-margin-top: 30vh; scroll-margin-bottom: 120px; }
.inp input { min-height: 52px; font-size: 22px; font-weight: 800; text-align: center; padding: 6px 30px 6px 8px; font-variant-numeric: tabular-nums; }
.inp input::placeholder { color: #4d545e; font-weight: 700; }
.inp .u { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--muted); pointer-events: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); display: grid; place-items: center; font-size: 18px; color: var(--muted); padding: 0; }
.icon-btn.has { color: var(--gold2); border-color: #7a5a1a; }
.memo-row { margin: -2px 0 10px 52px; }
.memo-row input { min-height: 40px; font-size: 15px; }
.ex-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.finish-bar { margin-top: 16px; display: grid; gap: 10px; }

/* ---------- シート（モーダル） ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg2); border-top-left-radius: 20px; border-top-right-radius: 20px;
  border-top: 1px solid var(--line);
  padding: 8px 16px calc(var(--safe-b) + 20px);
  max-width: 560px; margin: 0 auto;
  animation: up .25s ease;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; position: sticky; top: -8px; background: var(--bg2); padding: 6px 0; z-index: 2; }
.sheet-head h2 { margin: 0; font-size: 18px; color: var(--text); }
.list-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 8px 12px; margin-bottom: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-align: left; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-sub { font-size: 12px; color: var(--muted); }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-bottom: 14px; }
.opt { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 14px; padding: 4px 8px; }
.opt.on { border-color: var(--gold2); background: #3a2f18; color: var(--gold2); font-weight: 700; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.swatch.on { border-color: var(--gold2); box-shadow: 0 0 0 3px rgba(240,207,122,.3); }
.custom-preview { height: 230px; display: flex; justify-content: center; background: radial-gradient(ellipse at 50% 70%, #2d3440 0%, var(--bg2) 70%); border-radius: 14px; margin-bottom: 12px; }
.custom-preview svg { height: 100%; }

/* ---------- リザルト ---------- */
.result { text-align: center; }
.result .big-exp { font-size: 44px; font-weight: 900; color: var(--gold2); line-height: 1.1; font-variant-numeric: tabular-nums; }
.result .coins { font-size: 20px; font-weight: 800; margin: 4px 0 14px; }
.result .pr-list, .result .q-list { text-align: left; }
.pr-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: linear-gradient(90deg, #3a2c10, #2a2418); border: 1px solid #7a5a1a; border-radius: 12px; margin-bottom: 6px; animation: pop .45s ease both; }
.pr-item .star { color: var(--gold2); font-size: 20px; }
.levelup {
  position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: radial-gradient(circle at 50% 45%, rgba(214,168,74,.45), rgba(10,10,12,.95) 60%);
  animation: fade .3s ease; text-align: center; padding: 20px;
}
.levelup .lv-text { font-size: 20px; letter-spacing: .3em; color: var(--gold2); font-weight: 800; }
.levelup .lv-num { font-size: 88px; font-weight: 900; line-height: 1; color: #fff; text-shadow: 0 0 30px rgba(240,207,122,.8); animation: zoom .7s cubic-bezier(.2,1.6,.4,1) both; }
.levelup .lv-char { height: 38vh; animation: rise 1s ease both; }
.levelup .lv-char svg { height: 100%; }
.levelup.major { background: radial-gradient(circle at 50% 45%, rgba(255,215,106,.7), rgba(10,10,12,.96) 62%); }
.levelup .rays { position: absolute; inset: -50%; background: repeating-conic-gradient(from 0deg, rgba(255,230,160,.12) 0 8deg, transparent 8deg 20deg); animation: spin 18s linear infinite; pointer-events: none; }

/* ---------- HISTORY ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { font-size: 11px; color: var(--muted); text-align: center; padding: 2px 0; }
.cal .dow:first-child { color: #e58a7a; }
.cal .dow:last-child { color: #7aa8e5; }
.cal button { aspect-ratio: 1; border-radius: 10px; border: 1px solid transparent; background: var(--bg2); font-size: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0; position: relative; }
.cal button.out { visibility: hidden; }
.cal button.today { border-color: var(--muted); }
.cal button.sel { border-color: var(--gold2); }
.cal button.t1 { background: #4a3a18; }
.cal button.t2 { background: #7a5a1a; }
.cal button.t3 { background: #b8862f; color: #1b1407; font-weight: 800; }
.cal .dots { display: flex; gap: 2px; height: 5px; }
.cal .dots i { width: 5px; height: 5px; border-radius: 50%; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 12px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.wk { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.wk-entry { margin-bottom: 10px; }
.wk-set { display: flex; gap: 10px; font-size: 14px; padding: 2px 0 2px 8px; border-left: 2px solid var(--line); }
.wk-set .s { color: var(--muted); width: 40px; flex: none; }
.wk-set .memo { color: #bcd3ee; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.bar-row { display: grid; grid-template-columns: 48px 1fr 70px; gap: 8px; align-items: center; font-size: 13px; margin-bottom: 6px; }
.bar-row .bar { height: 14px; background: #0e1013; border-radius: 6px; overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; border-radius: 6px; }
.max-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.max-cell { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.max-cell .v { font-size: 22px; font-weight: 900; color: var(--gold2); font-variant-numeric: tabular-nums; }
.max-cell .k { font-size: 11px; color: var(--muted); }
table.max { width: 100%; border-collapse: collapse; font-size: 14px; }
table.max th { font-size: 11px; color: var(--muted); font-weight: 600; text-align: right; padding: 4px; }
table.max th:first-child, table.max td:first-child { text-align: left; }
table.max td { padding: 8px 4px; border-top: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- CHARACTER ---------- */
.part-row { display: grid; grid-template-columns: 44px 56px 1fr; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 14px; }
.part-row b { color: #9fc4ff; font-variant-numeric: tabular-nums; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--bg2); border-radius: 10px; padding: 8px 10px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px); background: #f4efe6; color: #1b1407; padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 90; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@keyframes zoom { from { transform: scale(.2); opacity: 0; } }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { transform: scale(1.012); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- ダイアログ ---------- */
.dialog-bg { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 24px; animation: fade .15s ease; }
.dialog { width: min(340px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px 18px 16px; animation: pop .2s ease; }
.dialog h3 { margin: 0 0 6px; font-size: 17px; }
.dialog p { margin: 0 0 18px; white-space: pre-wrap; }
.dialog-btns { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; }

/* ---------- ネイティブアプリ向け ---------- */
html.native, html.native body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html.native input, html.native textarea { -webkit-user-select: text; user-select: text; }
html.native .web-only { display: none !important; }
