:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --text: #1c1f26;
  --muted: #6b7180;
  --line: #e2e4ea;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --der: #2563d9;
  --die: #d6334a;
  --das: #1f9a55;
  --pl: #8a6d1f;
  --new: #2563d9;
  --learn: #d97706;
  --review: #1f9a55;
  --danger: #c92a3a;
  --bar: #1f2433;
  --bar-text: #ffffff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1c1f27;
    --text: #e9ebf0;
    --muted: #9198a8;
    --line: #2d313c;
    --accent: #6f8cff;
    --accent-text: #0d1020;
    --der: #6fa0ff;
    --die: #ff6f82;
    --das: #52d18a;
    --pl: #d8b45a;
    --new: #6fa0ff;
    --learn: #ffb04a;
    --review: #52d18a;
    --danger: #ff6f82;
    --bar: #181b23;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bar); color: var(--bar-text);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; text-align: center; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 11px; padding: 6px 0 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }

.panel {
  background: var(--surface); border-radius: 14px; padding: 16px;
  margin-bottom: 16px; border: 1px solid var(--line);
}
.panel h2 { margin: 0 0 12px; font-size: 17px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.big { font-size: 22px; }
code { font-size: 13px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select, textarea {
  width: 100%; font: inherit; font-size: 17px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { resize: vertical; }
input[type=range] { width: 100%; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.check input { width: 20px; height: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 16px; padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.btn.wide { width: 100%; padding: 14px; font-size: 18px; }
.link { border: 0; background: none; color: var(--accent); font: inherit; padding: 4px 0; }
.icon-btn { border: 0; background: none; font-size: 20px; padding: 4px 8px; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.inline { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.inline input:not([type=file]) { flex: 1; min-width: 0; }

/* 性の色: der=青, die=赤, das=緑 */
.art { font-weight: 700; }
.g-der { color: var(--der); }
.g-die { color: var(--die); }
.g-das { color: var(--das); }
.g-pl { color: var(--pl); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 16px; text-align: center; }
.stats b { display: block; font-size: 30px; }
.stats span { font-size: 13px; color: var(--muted); }
.c-new { color: var(--new); }
.c-learn { color: var(--learn); }
.c-review { color: var(--review); }

.session-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.flash {
  background: var(--surface); border: 1px solid var(--line); border-top: 6px solid var(--line);
  border-radius: 16px; padding: 28px 20px; min-height: 240px; text-align: center;
  display: flex; flex-direction: column; justify-content: center; gap: 10px; margin-bottom: 16px;
}
.flash[data-act] { cursor: pointer; }
.g-border-der { border-top-color: var(--der); }
.g-border-die { border-top-color: var(--die); }
.g-border-das { border-top-color: var(--das); }
.flash hr { width: 100%; border: 0; border-top: 1px dashed var(--line); margin: 8px 0; }
.row-center { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; }
.de.huge, .ja.huge { font-size: 34px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.de.big, .ja.big { font-size: 24px; font-weight: 600; overflow-wrap: anywhere; }
.plural { color: var(--muted); }
.example { background: var(--bg); border-radius: 10px; padding: 10px 12px; text-align: left; }
.example .icon-btn { font-size: 15px; padding: 0 4px; }
.note { font-size: 15px; color: var(--muted); white-space: pre-wrap; text-align: left; }

.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate button {
  font: inherit; border: 0; border-radius: 12px; padding: 12px 4px; color: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; font-weight: 600;
}
.rate small { font-weight: 400; font-size: 12px; opacity: .9; }
.rate .r1 { background: #d6334a; }
.rate .r2 { background: #d97706; }
.rate .r3 { background: #1f9a55; }
.rate .r4 { background: #2563d9; }

.toolbar { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.toolbar select { width: auto; max-width: 40vw; }
.words { list-style: none; margin: 0; padding: 0; }
.words li { margin-bottom: 8px; }
.words button {
  width: 100%; text-align: left; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; cursor: pointer;
}
.words .de { font-weight: 600; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { text-align: center; position: relative; font-weight: 600; }
.seg label + label { border-left: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { display: block; padding: 9px 0; }
.seg input:checked + span { color: var(--surface); background: var(--text); }
.seg label.g-der input:checked + span { background: var(--der); }
.seg label.g-die input:checked + span { background: var(--die); }
.seg label.g-das input:checked + span { background: var(--das); }

.umlauts { display: flex; gap: 6px; margin: -6px 0 14px; flex-wrap: wrap; }
.umlauts button {
  font: inherit; font-size: 18px; min-width: 42px; padding: 6px 0; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
}

.decks { list-style: none; margin: 0 0 8px; padding: 0; }
.decks li { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.decks input { flex: 1; min-width: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  max-width: calc(100% - 32px); font-size: 15px; transition: .2s; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
