:root,
html.theme-light {
  color-scheme: light;
  --bg: #eef2f7;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --blue: #2563eb;
  --navy: #0f2744;
  --line: #d1d5db;
  --key: #ffffff;
  --key-num: #cfd3da;
  --key-special: #b8bec8;
  --surface: #f8fafc;
  --header: #0f2744;
  --header-ink: #ffffff;
  --ghost: #e5e7eb;
  --ghost-ink: #111827;
  --choice: #f8fafc;
  --choice-on: #dbeafe;
  --danger: #b91c1c;
  --ok-bg: #ecfdf5;
  --ok-ink: #065f46;
  --err-bg: #fef2f2;
  --err-ink: #991b1b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --kb-bar: #dfe3ea;
}

html.theme-dark {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #152033;
  --ink: #e8eef8;
  --muted: #9aa6b8;
  --blue: #5b9cff;
  --navy: #0f2744;
  --line: #2a3a52;
  --key: #1c2b40;
  --key-num: #24364f;
  --key-special: #334860;
  --surface: #101b2c;
  --header: #0a1624;
  --header-ink: #e8eef8;
  --ghost: #243044;
  --ghost-ink: #e8eef8;
  --choice: #1a283c;
  --choice-on: #1e3a5f;
  --danger: #ef4444;
  --ok-bg: #0f3d34;
  --ok-ink: #6ee7b7;
  --err-bg: #3f1d1d;
  --err-ink: #fca5a5;
  --shadow: 0 1px 8px rgba(0, 0, 0, 0.35);
  --kb-bar: #243044;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.wrap { max-width: 720px; margin: 0 auto; padding: 16px 12px 180px; }
.card {
  background: var(--card);
  color: var(--ink);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
h1, h2, h3, h4 { color: var(--ink); }
p { color: var(--muted); }
input, input[type=text], input[type=password], select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  background: var(--surface);
  color: var(--ink);
}
input::placeholder { color: var(--muted); }
.btn, button.btn {
  width: 100%;
  border: 0;
  background: var(--blue);
  color: #fff;
  padding: 12px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 10px;
}
.btn.ghost, button.ghost {
  background: var(--ghost);
  color: var(--ghost-ink);
}
.hidden { display: none !important; }
.q { padding: 12px 0; border-bottom: 1px solid var(--line); }
.q-title { font-weight: 700; margin-bottom: 8px; color: var(--ink); }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices label {
  min-width: 44px;
  text-align: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--choice);
  color: var(--ink);
}
.choices input { display: none; }
.choices input:checked + span,
.choices label:has(input:checked) {
  background: var(--choice-on);
  border-color: var(--blue);
  color: var(--ink);
}
.written { display: grid; gap: 8px; }
.written-row { display: flex; gap: 8px; align-items: center; }
.written-row input { flex: 1; width: auto; }
.kb-toggle {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: 18px;
}
.kb-toggle.active { background: var(--choice-on); border-color: var(--blue); }

.mathkb {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--bg);
  padding: 6px 6px 10px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
  color: var(--ink);
}
.mathkb-top { display: flex; align-items: center; gap: 10px; padding: 4px 8px 8px; font-size: 14px; }
.tabs { display: flex; gap: 16px; font-weight: 600; color: var(--muted); }
.tabs span { padding-bottom: 4px; cursor: pointer; }
.tabs span.active { color: var(--blue); border-bottom: 2px solid var(--blue); }
.deg {
  display: flex;
  background: var(--kb-bar);
  border-radius: 8px;
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
}
.deg b { padding: 6px 10px; cursor: pointer; color: var(--muted); }
.deg b.on { background: var(--blue); color: #fff; }
.kb-tools { margin-left: auto; display: flex; gap: 10px; color: var(--muted); align-items: center; font-size: 13px; }
.kb-tools button { border: 0; background: transparent; color: inherit; cursor: pointer; }
.kb-body { display: none; }
.kb-body.show { display: block; }
.grid { display: grid; gap: 6px; }
.main-grid {
  display: grid;
  grid-template-columns: 1.15fr 1.35fr 0.7fr;
  gap: 8px;
}
.key {
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--key);
  color: var(--ink);
  font-size: 16px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}
.key.num { background: var(--key-num); font-weight: 700; }
.key.special { background: var(--key-special); }
.key.enter { background: var(--blue); color: #fff; font-size: 20px; }
.func-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.abc-row { display: flex; gap: 4px; justify-content: center; margin-bottom: 4px; }
.abc-row .key { flex: 1; max-width: 34px; height: 38px; font-size: 15px; }
.msg { padding: 12px; border-radius: 12px; background: var(--ok-bg); color: var(--ok-ink); }
.err { background: var(--err-bg); color: var(--err-ink); padding: 10px 12px; border-radius: 10px; }
.theme-toggle {
  border: 1px solid var(--line);
  background: var(--ghost);
  color: var(--ghost-ink);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
@media (max-width: 420px) {
  .key { height: 38px; font-size: 14px; }
}
