:root {
  --bg: #d4d4d4;
  --paper: #f3f3f3;
  --ink: #111111;
  --muted: #5a5a5a;
  --line: #c8c8c8;
  --accent: #1a1a1a;
  --accent-soft: #e4e4e4;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
  --sss: #111111;
  --ss: #3a3a3a;
  --s: #595959;
  --q: #737373;
  --n: #000000;
  --w: #8c8c8c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 420px at 50% -80px, #efefef, transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

.app {
  width: min(520px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  position: relative;
}

@media (min-width: 560px) {
  body { padding: 28px 0; }
  .app {
    min-height: calc(100dvh - 56px);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: clip;
  }
}

.screen { min-height: 100dvh; }

.column-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.form-fill {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.dock {
  flex: none;
  padding: 10px 22px calc(12px + var(--safe-bot));
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.dock .check { margin: 0 0 10px; }
.dock .text-link,
.dock .text-btn,
.actions .text-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  text-align: center;
}
.dock .form-error { margin-top: 0; }

@media (min-width: 560px) {
  .screen { min-height: calc(100dvh - 56px); }
  .column-screen,
  .quiz-screen { height: calc(100dvh - 56px); }
}

.screen-body {
  padding: 8px 22px calc(28px + var(--safe-bot));
}

.mast {
  padding: calc(28px + var(--safe-top)) 22px 0;
}

#screen-gate .mast { display: none; }
#screen-gate .scroll {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
#screen-gate .screen-body {
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bot));
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 13px;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  font-family: "Songti SC", "Noto Serif SC", "STSong", serif;
  font-size: 36px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.25;
}

.rule {
  height: 4px;
  margin: 16px 0 8px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.prose p, .lead {
  margin: 12px 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.75;
}

.lead { color: var(--muted); margin-top: 4px; }

.prose { padding: 0 22px; }
.intro-greet {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 650;
}

.block-title {
  margin: 22px 22px 10px;
  font-size: 15px;
  letter-spacing: 0.08em;
}

.legend {
  list-style: none;
  margin: 0 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #f7f7f7;
}

.legend li {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  font-size: 15px;
}

.legend li:first-child { border-top: 0; }

.legend b {
  width: 62px;
  flex: none;
  font-weight: 650;
}

.lv-SSS b, .tone-0 b { color: var(--sss); }
.lv-SS b, .tone-1 b { color: var(--ss); }
.lv-S b, .tone-2 b { color: var(--s); }
.lv-Q b, .tone-3 b { color: var(--q); }
.lv-N b, .tone-4 b { color: var(--n); }
.lv-W b, .tone-5 b { color: var(--w); }

.count-line {
  margin: 14px 22px 0;
  color: var(--muted);
  font-size: 14px;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
}

.check input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex: none;
}

.actions { padding: 18px 22px calc(24px + var(--safe-bot)); }

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 12px 18px;
  background: #fff;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn.primary {
  background: var(--accent);
  color: #f5f5f5;
}

.btn.primary:disabled {
  background: #b0b0b0;
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border-color: #b5b5b5;
}

.btn.block { width: 100%; }

.btn.small { padding: 8px 14px; }

.btn:active:not(:disabled) { transform: translateY(1px); }

.text-link, .text-btn, .icon-btn, .as-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: none;
  padding: 8px 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.text-link, .text-btn { display: inline-block; font-size: 14px; }

.actions .text-link {
  display: block;
  margin-top: 12px;
  text-align: center;
}

.banner {
  margin: 4px 22px 0;
  padding: 14px;
  border-radius: 14px;
  background: var(--accent-soft);
}

.banner p { margin: 0 0 10px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 8px;
}

.topbar .icon-btn { justify-self: start; font-size: 15px; }
.topbar .icon-btn:last-child,
.topbar .topbar-side { justify-self: end; }

.topbar-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  text-align: center;
}

.as-btn { font-weight: 650; font-size: 16px; padding: 8px 4px; }

.field { display: block; margin: 0 0 14px; }

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.field em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.field input, .field textarea {
  width: 100%;
  border: 1px solid #c6c6c6;
  border-radius: 12px;
  background: #f7f7f7;
  padding: 13px 14px;
  font-size: 16px;
  outline: none;
}

.field textarea { resize: vertical; min-height: 96px; }

.field input:focus, .field textarea:focus {
  border-color: var(--accent);
}

.form-error {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 14px;
  line-height: 1.5;
}

.quiz-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

@media (min-width: 560px) {
  .quiz-screen { height: calc(100dvh - 56px); }
}

.progress {
  height: 3px;
  margin: 0 16px;
  background: #d0d0d0;
  border-radius: 99px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}

.progress-label {
  margin: 8px 22px 0;
  color: var(--muted);
  font-size: 13px;
}

.quiz-body {
  flex: 1;
  overflow: auto;
  padding-top: 18px;
}

.ask {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.q-title {
  margin: 8px 0 0;
  font-family: "Songti SC", "Noto Serif SC", "STSong", serif;
  font-size: 34px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.02em;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  border: 1px solid #cfcfcf;
  border-radius: 14px;
  background: #f7f7f7;
  text-align: left;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.option .mark {
  width: 64px;
  flex: none;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.option .name { font-size: 16px; }

.option.lv-SSS .mark, .option.tone-0 .mark { color: var(--sss); }
.option.lv-SS .mark, .option.tone-1 .mark { color: var(--ss); }
.option.lv-S .mark, .option.tone-2 .mark { color: var(--s); }
.option.lv-Q .mark, .option.tone-3 .mark { color: var(--q); }
.option.lv-N .mark, .option.tone-4 .mark { color: var(--n); }
.option.lv-W .mark, .option.tone-5 .mark { color: var(--w); }

.option.selected.lv-SSS,
.option.selected.tone-0 {
  background: #111111;
  border-color: #111111;
  color: #f5f5f5;
}
.option.selected.lv-SS,
.option.selected.tone-1 {
  background: #3a3a3a;
  border-color: #3a3a3a;
  color: #f5f5f5;
}
.option.selected.lv-SSS .mark,
.option.selected.lv-SS .mark,
.option.selected.tone-0 .mark,
.option.selected.tone-1 .mark { color: #f5f5f5; }

.option.selected.lv-S,
.option.selected.tone-2 {
  background: #d9d9d9;
  border-color: #a6a6a6;
}
.option.selected.lv-Q,
.option.selected.tone-3 {
  background: #e8e8e8;
  border-color: #b0b0b0;
}
.option.selected.lv-N,
.option.selected.tone-4 {
  background: var(--n);
  border-color: var(--n);
  color: #f5f5f5;
}
.option.selected.lv-N .mark,
.option.selected.tone-4 .mark { color: #f5f5f5; }
.option.selected.lv-W,
.option.selected.tone-5 {
  background: #f0f0f0;
  border-color: #c0c0c0;
}

.bulk { margin-top: 16px; }
.bulk-confirm {
  margin-top: 8px;
  padding: 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}
.bulk-confirm p { margin: 0 0 8px; font-size: 14px; line-height: 1.5; }

.card {
  padding: 14px 16px;
  border-radius: 14px;
  background: #f7f7f7;
  border: 1px solid var(--line);
}

.card p { margin: 0 0 6px; line-height: 1.55; }
.card p:last-child { margin-bottom: 0; }
.card .muted { color: var(--muted); }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12px;
}

.cat-block { margin: 0 0 16px; }
.cat-block h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.answer-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  touch-action: manipulation;
}

.answer-row span:first-child { line-height: 1.4; }
.answer-row .tag {
  flex: none;
  font-size: 13px;
  font-weight: 700;
}
.tag.lv-SSS, .tag.tone-0 { color: var(--sss); }
.tag.lv-SS, .tag.tone-1 { color: var(--ss); }
.tag.lv-S, .tag.tone-2 { color: var(--s); }
.tag.lv-Q, .tag.tone-3 { color: var(--q); }
.tag.lv-N, .tag.tone-4 { color: var(--n); }
.tag.lv-W, .tag.tone-5, .tag.empty { color: var(--w); }

.sheet[hidden], [hidden] { display: none !important; }

.sheet {
  position: fixed;
  z-index: 5;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, 100%);
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

@media (min-width: 560px) {
  .sheet {
    top: 28px;
    bottom: 28px;
    border-radius: 18px;
    overflow: hidden;
  }
}

.sheet-mask {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.4);
}

.sheet-panel {
  position: relative;
  max-height: min(78dvh, 640px);
  overflow: auto;
  padding: 16px 16px calc(16px + var(--safe-bot));
  border-radius: 18px 18px 0 0;
  background: var(--paper);
}

@media (min-width: 560px) {
  .sheet-panel { border-radius: 0 0 18px 18px; }
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.sheet-head h2 { margin: 0; font-size: 18px; }

.map-list { display: flex; flex-direction: column; margin-bottom: 12px; }

.map-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 2px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  font-size: 16px;
}

.map-item small { color: var(--muted); }

.result {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f7f7f7;
  overflow: hidden;
}

.result summary {
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.result summary::-webkit-details-marker { display: none; }

.result summary strong { display: block; font-size: 17px; }
.result summary em {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}

.result .inner { padding: 0 16px 14px; }

.result .danger {
  margin-top: 8px;
  color: var(--accent);
  background: transparent;
  border: 0;
  padding: 8px 0;
}

.editor-card { margin: 0 0 14px; }
.editor-card .btn { margin-top: 10px; }
.editor-label {
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: 0.06em;
}
h2.editor-label {
  margin: 26px 0 8px;
  font-size: 16px;
}
.add-row input[data-field="level-mark"] {
  flex: 0 0 96px;
}
.editor-card input,
.editor-card textarea {
  width: 100%;
  margin-top: 8px;
  border: 1px solid #c6c6c6;
  border-radius: 12px;
  background: #f7f7f7;
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
}
.editor-card textarea { resize: vertical; }
.editor-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cat-bar {
  display: flex;
  align-items: center;
  gap: 2px;
}
.cat-bar input {
  flex: 1;
  min-width: 0;
  margin-top: 0;
  font-weight: 650;
}
.cat-count {
  min-width: 1.5em;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}
.cat-body { padding-top: 4px; }
.icon-act {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex: none;
  touch-action: manipulation;
}
.icon-act svg { width: 20px; height: 20px; }
.icon-act.open svg { transform: rotate(90deg); }
.icon-act.danger { color: var(--accent); }
.icon-act:disabled { opacity: 0.28; }

.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  flex: none;
  border-top: 1px solid var(--line);
  background: #f7f7f7;
  padding: 4px 4px calc(4px + var(--safe-bot));
}
.tabbar button {
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  padding: 6px 0 4px;
  touch-action: manipulation;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.active { color: var(--accent); }
.progress-card { margin: 0 0 12px; }
.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.progress-head strong { font-size: 17px; }
.progress-head span { color: var(--accent); font-weight: 650; }
.meter {
  height: 6px;
  margin-top: 10px;
  background: #d0d0d0;
  border-radius: 99px;
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  background: var(--accent);
}
.editor-head input { margin-top: 0; font-weight: 650; }
.editor-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 2px;
  align-items: center;
}
.editor-item input { margin-top: 8px; min-width: 0; }
.mini {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px;
  font-size: 13px;
  touch-action: manipulation;
}
.mini:disabled { opacity: 0.35; }
.mini.danger { color: var(--accent); }
.add-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.add-row input { flex: 1; margin-top: 0; }
.add-row .btn { margin-top: 0; flex: none; }

.empty {
  color: var(--muted);
  line-height: 1.6;
}
