:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --accent: var(--tg-theme-button-color, #2a7ae2);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --good: #2e9d4f;
  --bad: #d64545;
  --warn: #d98a00;
  --radius: 12px;
  --jp: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 72px;
  -webkit-tap-highlight-color: transparent;
}

main { padding: 12px 12px 24px; max-width: 640px; margin: 0 auto; }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 16px; margin: 18px 0 8px; }
.hint { color: var(--hint); font-size: 13px; }
.jp { font-family: var(--jp); }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--bg);
  border-top: 1px solid rgba(127, 127, 127, .2);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
#tabs button {
  flex: 1; border: 0; background: none; color: var(--hint);
  font-size: 11px; padding: 6px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 1px;
}
#tabs button span { font-size: 20px; }
#tabs button.active { color: var(--accent); }

.card {
  background: var(--bg); border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }

button.btn, a.btn {
  border: 0; border-radius: 10px; padding: 11px 14px; font-size: 15px; font-weight: 600;
  background: var(--accent); color: var(--accent-text); cursor: pointer; text-decoration: none;
  display: inline-block; text-align: center;
}
button.btn.secondary { background: var(--bg); color: var(--text); }
.card button.btn.secondary { background: var(--bg2); }
button.btn.danger { background: transparent; color: var(--bad); }
button.btn.block { width: 100%; }
button.btn:disabled { opacity: .5; }
button.link { border: 0; background: none; color: var(--link); padding: 4px 0; font-size: 14px; }

input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg2);
  border: 1px solid transparent; border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label.check { display: flex; align-items: center; gap: 8px; }
input[type=checkbox] { width: auto; flex: none; width: 20px; height: 20px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 0 4px 2px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid rgba(127, 127, 127, .3); background: var(--bg); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font-size: 13px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; color: var(--text); border-radius: 8px; padding: 7px 4px; font-size: 13px; }
.seg button.on { background: var(--bg); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600; }

/* flash card */
.flash { min-height: 300px; display: flex; flex-direction: column; justify-content: center; text-align: center; cursor: pointer; }
.flash .kind { color: var(--hint); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.flash .big { font-family: var(--jp); font-size: 40px; line-height: 1.6; }
.flash .huge { font-family: var(--jp); font-size: 88px; line-height: 1.2; }
.flash .ru-big { font-size: 26px; font-weight: 600; }
.flash .answer { border-top: 1px solid rgba(127, 127, 127, .2); margin-top: 16px; padding-top: 14px; }
.flash .meaning { font-size: 20px; font-weight: 600; }
.flash .example { margin-top: 10px; color: var(--hint); }
.flash .example .jp { color: var(--text); font-size: 17px; }
.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ratings button { border: 0; border-radius: 10px; padding: 9px 2px; color: #fff; font-weight: 600; font-size: 14px; }
.ratings button small { display: block; font-weight: 400; font-size: 11px; opacity: .9; }
.r1 { background: var(--bad); } .r2 { background: var(--warn); } .r3 { background: var(--good); } .r4 { background: #2a7ae2; }

ruby rt { font-size: .5em; color: var(--hint); }
.unknown-k { background: rgba(214, 69, 69, .15); border-radius: 4px; }
.text-jp { font-family: var(--jp); font-size: 22px; line-height: 2.2; }

/* quiz */
.options { display: grid; gap: 8px; }
.options button {
  border: 2px solid transparent; background: var(--bg2); color: var(--text); border-radius: 10px;
  padding: 13px; font-size: 16px; text-align: left;
}
.options button.jp-opt { font-family: var(--jp); font-size: 20px; }
.options button.right { border-color: var(--good); background: rgba(46, 157, 79, .12); }
.options button.wrong { border-color: var(--bad); background: rgba(214, 69, 69, .12); }
.progress { height: 4px; background: var(--bg2); border-radius: 2px; overflow: hidden; margin-bottom: 10px; }
.progress > div { height: 100%; background: var(--accent); }

/* lists */
.list .item { display: flex; gap: 10px; align-items: center; padding: 10px 2px; border-bottom: 1px solid rgba(127, 127, 127, .15); cursor: pointer; }
.list .item:last-child { border-bottom: 0; }
.list .expr { font-family: var(--jp); font-size: 19px; }
.list .reading { color: var(--hint); font-size: 13px; font-family: var(--jp); }
.badge { font-size: 11px; border-radius: 999px; padding: 2px 8px; background: var(--bg2); color: var(--hint); white-space: nowrap; }
.badge.known { background: rgba(46, 157, 79, .15); color: var(--good); }
.badge.learning { background: rgba(42, 122, 226, .12); color: var(--link); }
.badge.ignored { text-decoration: line-through; }
.kanji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.kanji-grid .k { background: var(--bg2); border-radius: 10px; text-align: center; padding: 8px 0 4px; cursor: pointer; }
.kanji-grid .k .c { font-family: var(--jp); font-size: 30px; }
.kanji-grid .k.known { box-shadow: inset 0 0 0 2px var(--good); }

.draft-item { border-bottom: 1px solid rgba(127, 127, 127, .15); padding: 8px 0; }
.draft-item .row input { padding: 7px 9px; }
.draft-item.skipped { opacity: .45; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--bg2); border-radius: 10px; padding: 10px; }
.stat b { font-size: 22px; display: block; }

.feedback { white-space: pre-wrap; }
.center { text-align: center; }
.empty { text-align: center; padding: 40px 12px; color: var(--hint); }
.empty .icon { font-size: 44px; }

#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: rgba(30, 30, 30, .92); color: #fff; padding: 9px 16px; border-radius: 10px;
  font-size: 14px; max-width: 90vw; z-index: 20;
}

.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 30; display: flex; align-items: flex-end; }
.sheet { background: var(--bg); width: 100%; max-height: 88vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px 14px 28px; }
.list .item .grow { flex: 1; min-width: 0; }
