:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --text: #17202a;
  --muted: #6f7b87;
  --line: #dfe6ee;
  --accent: #1677ff;
  --accent-dark: #0f5fc9;
  --good: #1d9a66;
  --warn: #d9851f;
  --bad: #d94b4b;
  --key: #f5f7fa;
  --shadow: 0 18px 50px rgba(26, 39, 57, 0.12);
}

body.theme-ink {
  --bg: #11161d;
  --panel: #1a222c;
  --panel-soft: #222d38;
  --text: #eff5fb;
  --muted: #9aa9b7;
  --line: #304050;
  --accent: #55b4ff;
  --accent-dark: #2e95de;
  --key: #263340;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

body.theme-green {
  --bg: #edf4ee;
  --panel: #fbfdf9;
  --panel-soft: #f2f8f0;
  --text: #193024;
  --muted: #617368;
  --line: #d8e4d9;
  --accent: #27886a;
  --accent-dark: #1e6d55;
  --key: #f5faf3;
  --shadow: 0 18px 45px rgba(34, 65, 46, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100vh;
  padding: 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand,
.profile-card,
.daily-card,
.section-head,
.topbar,
.word-actions,
.row-actions,
.top-actions,
.data-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.profile-card p {
  display: block;
  margin: 0;
}

.brand span,
.profile-card span,
.daily-card span,
.metric span,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

.profile-card {
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.avatar-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #17202a;
  color: #fff;
  font-weight: 800;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.daily-card {
  justify-content: space-between;
  margin-top: auto;
  padding: 16px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.daily-card strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.goal-ring {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) 0%, var(--line) 0);
  color: var(--text);
  font-weight: 800;
}

.sidebar-ai {
  display: grid;
  gap: 10px;
}

.sidebar-ai-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 800;
}

.sidebar-ai-toggle strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-width: 24px;
  padding: 0;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  line-height: 1;
  font-size: 18px;
  font-family: Arial, sans-serif;
}

.sidebar-ai-body {
  display: none;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.sidebar-ai-body.open {
  display: grid;
}

.compact-button {
  width: 100%;
}

.sidebar-ai .ai-status {
  padding: 10px;
  font-size: 13px;
}

.sidebar-ai .ai-output {
  min-height: 120px;
  max-height: 190px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  font-size: 13px;
}

.sidebar-ai .ai-question {
  grid-template-columns: minmax(0, 1fr) 42px;
}

.sidebar-ai .ai-question input,
.sidebar-ai .ai-question button {
  min-height: 36px;
}

.ai-context-detail {
  color: var(--muted);
  font-size: 13px;
}

.ai-context-detail summary {
  cursor: pointer;
}

.ai-context-detail pre {
  max-height: 160px;
  margin: 8px 0 0;
  font-size: 12px;
}

.main-content {
  min-width: 0;
  padding: 28px;
}

.topbar {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
}

h2 {
  font-size: 22px;
}

.top-actions,
.word-actions,
.row-actions,
.data-actions {
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.danger-button,
.icon-button,
.file-button,
.toggle {
  border-radius: 8px;
  border: 1px solid var(--line);
  min-height: 40px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--text);
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.danger-button {
  border-color: rgba(217, 75, 75, 0.4);
  color: var(--bad);
}

.icon-button {
  width: 42px;
  padding: 0;
}

.file-button {
  display: inline-grid;
  place-items: center;
}

.file-button input {
  display: none;
}

.toggle.active {
  border-color: var(--accent);
  background: rgba(22, 119, 255, 0.1);
  color: var(--accent);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.practice-grid,
.dashboard-grid,
.library-layout,
.review-layout {
  display: grid;
  gap: 18px;
}

.practice-grid {
  grid-template-columns: minmax(0, 1fr) 260px;
}

.trainer-panel,
.stats-panel,
.keyboard-panel,
.chart-panel,
.session-panel,
.review-panel,
.library-panel,
.settings-form,
.summary-strip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.trainer-panel {
  min-height: 520px;
  overflow: hidden;
}

.practice-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) minmax(130px, 0.8fr) minmax(130px, 0.8fr) 92px;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  min-height: 42px;
  padding: 0 12px;
  outline: 0;
}

textarea {
  min-height: 250px;
  padding: 14px;
  resize: vertical;
  line-height: 1.65;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}

.word-stage {
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 40px 30px;
  text-align: center;
}

.word-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.phonetic,
.translation {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
}

.target-word {
  min-height: 82px;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(42px, 8vw, 82px);
  font-weight: 850;
  line-height: 1;
}

.target-word.hidden {
  color: transparent;
  text-shadow: 0 0 14px var(--muted);
}

.typed-word {
  min-height: 34px;
  font-size: 24px;
  font-weight: 800;
}

.typed-word .ok {
  color: var(--good);
}

.typed-word .bad {
  color: var(--bad);
  text-decoration: underline;
}

#typingInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.stats-panel {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
}

.metric,
.focus-note {
  padding: 14px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 32px;
}

.focus-note p {
  margin: 8px 0 0;
  line-height: 1.6;
}

.keyboard-panel {
  margin-top: 18px;
  padding: 18px;
}

.section-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.keyboard {
  display: grid;
  gap: 8px;
  overflow-x: auto;
}

.key-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  min-width: 720px;
}

.key {
  display: grid;
  place-items: center;
  width: 58px;
  height: 48px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--key);
  font-weight: 800;
  transition: transform 0.15s ease, background 0.15s ease;
}

.key.hot {
  color: #fff;
  background: var(--bad);
}

.key.warm {
  color: #fff;
  background: var(--warn);
}

.key.cool {
  color: #fff;
  background: var(--accent);
}

.key.active {
  transform: translateY(2px);
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.1);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
}

.summary-strip div {
  padding: 18px;
  background: var(--panel-soft);
}

.summary-strip span {
  color: var(--muted);
  display: block;
}

.summary-strip strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

.chart-panel,
.session-panel,
.review-panel,
.library-panel,
.settings-form {
  padding: 18px;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(10, minmax(34px, 1fr));
  align-items: end;
  gap: 10px;
  min-height: 240px;
  padding-top: 24px;
}

.bar {
  display: grid;
  align-content: end;
  min-height: 180px;
  gap: 6px;
}

.bar span {
  display: block;
  border-radius: 8px 8px 0 0;
  background: var(--accent);
  min-height: 8px;
}

.bar small {
  color: var(--muted);
  text-align: center;
}

.session-list,
.word-list {
  display: grid;
  gap: 10px;
}

.session-item,
.word-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.session-item span,
.word-item span {
  color: var(--muted);
  font-size: 13px;
}

.review-layout,
.library-layout,
.ai-layout {
  grid-template-columns: 1fr 1fr;
}

.wide-panel {
  grid-column: 1 / -1;
}

.catalog-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  margin-bottom: 14px;
}

.catalog-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}

.catalog-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.catalog-item strong {
  overflow-wrap: anywhere;
}

.catalog-item span,
.catalog-item small {
  color: var(--muted);
}

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

.tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.empty {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  max-width: 900px;
}

.settings-form .wide {
  grid-column: 1 / -1;
}

.settings-divider {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.ai-layout {
  display: grid;
  gap: 18px;
}

.ai-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.ai-status {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  line-height: 1.6;
}

.ai-output {
  min-height: 260px;
  margin: 14px 0;
  padding: 16px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  line-height: 1.75;
  white-space: pre-wrap;
}

.ai-output p {
  margin: 0;
}

.ai-question {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

pre {
  max-height: 280px;
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: pre-wrap;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 32, 0.42);
}

.account-modal {
  width: min(520px, calc(100vw - 32px));
  padding: 20px;
}

.account-list {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.account-choice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  padding: 12px 16px;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(5, 1fr);
  }

  .nav-item {
    text-align: center;
  }

  .practice-grid,
  .review-layout,
  .library-layout,
  .ai-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .main-content,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .side-nav,
  .practice-controls,
  .settings-form,
  .summary-strip,
  .ai-question {
    grid-template-columns: 1fr;
  }

  .target-word {
    min-height: 58px;
  }

  .bar-chart {
    grid-template-columns: repeat(5, minmax(32px, 1fr));
  }
}
