:root {
  --bg: var(--tg-theme-bg-color, #1a1a2e);
  --text: var(--tg-theme-text-color, #eee);
  --hint: var(--tg-theme-hint-color, #888);
  --accent: var(--tg-theme-button-color, #4a90d9);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --secondary: var(--tg-theme-secondary-bg-color, #16213e);
  --border: rgba(255, 255, 255, 0.08);
  --career: #4a90d9;
  --english: #50c878;
  --music: #c77dff;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 72px;
}

#app {
  max-width: 480px;
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--hint);
  margin-top: 2px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

.hidden {
  display: none !important;
}

main {
  padding: 0 16px 16px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.card {
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card h3 {
  font-size: 0.85rem;
  color: var(--hint);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tracks {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.track {
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 14px;
  border-left: 4px solid var(--career);
}

.track.english {
  border-left-color: var(--english);
}

.track.music {
  border-left-color: var(--music);
}

.track-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.track-title {
  font-weight: 600;
}

.track-level {
  font-size: 0.85rem;
  color: var(--hint);
}

.progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.progress-fill.career { background: var(--career); }
.progress-fill.english { background: var(--english); }

.track-meta {
  font-size: 0.78rem;
  color: var(--hint);
}

.music-tree,
.growth-visual {
  font-size: 2rem;
  text-align: center;
  padding: 8px 0;
}

.quest-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.secondary-btn,
.primary-btn {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
}

.secondary-btn {
  background: var(--secondary);
  color: var(--text);
}

.primary-btn {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  width: 100%;
  margin-top: 8px;
}

.quest-list,
.quest-shelf,
.library-list {
  list-style: none;
}

.quest-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--secondary);
  border-radius: var(--radius);
  margin-bottom: 6px;
}

.quest-item .quest-title {
  flex: 1;
  font-size: 0.9rem;
}

.quest-item.done {
  opacity: 0.85;
}

.quest-date {
  font-size: 0.75rem;
  color: var(--hint);
}

.complete-btn {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
}

.library-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.library-item button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--hint);
  margin-top: 2px;
}

.error-card {
  color: #ffb4b4;
  font-size: 0.9rem;
  line-height: 1.4;
}

.segment {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 4px;
}

.segment button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--hint);
  padding: 10px 6px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.segment button.active {
  background: var(--accent);
  color: var(--accent-text);
}

.checkin-btn {
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--secondary);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.checkin-btn.done {
  opacity: 0.7;
  cursor: default;
}

input, textarea, select {
  width: 100%;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--secondary);
  color: var(--text);
  font-size: 0.95rem;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 6px;
  margin-bottom: 12px;
}

.inline-form input,
.inline-form select {
  margin-bottom: 0;
}

.inline-form button {
  padding: 0 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.2rem;
  cursor: pointer;
}

.word-list, .events-list, .trophy-list {
  list-style: none;
}

.word-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--secondary);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
}

.word-item:active {
  opacity: 0.8;
}

.word-main {
  font-weight: 500;
}

.word-sub {
  font-size: 0.8rem;
  color: var(--hint);
}

.status-badge {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
}

.status-badge.new { color: #ffd166; }
.status-badge.learning { color: #4ecdc4; }
.status-badge.known { color: #50c878; }

.heatmap {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.heatmap.wide {
  max-height: 120px;
  overflow-y: auto;
}

.heat-cell {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
}

.heat-cell.l1 { background: rgba(74, 144, 217, 0.3); }
.heat-cell.l2 { background: rgba(74, 144, 217, 0.5); }
.heat-cell.l3 { background: rgba(74, 144, 217, 0.7); }
.heat-cell.l4 { background: rgba(74, 144, 217, 0.9); }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-box {
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}

.stat-box .label {
  font-size: 0.7rem;
  color: var(--hint);
}

.stat-box .value {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 4px;
}

.event-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--secondary);
  border-radius: var(--radius);
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.event-item span:first-child {
  flex: 1;
}

.event-date {
  color: var(--hint);
  font-size: 0.78rem;
  white-space: nowrap;
}

.event-item button {
  background: none;
  border: none;
  color: var(--hint);
  cursor: pointer;
  padding: 4px 8px;
}

.stage-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.stage-btn {
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--secondary);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.stage-btn.current {
  border-color: var(--accent);
  background: rgba(74, 144, 217, 0.15);
}

.milestone {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--secondary);
  border-radius: var(--radius);
  margin-bottom: 6px;
}

.milestone input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.milestone-title {
  flex: 1;
  font-size: 0.9rem;
}

.milestone-progress input {
  width: 80px;
  margin: 0;
  padding: 6px 8px;
  font-size: 0.85rem;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--secondary);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
}

.bottom-nav button {
  flex: 1;
  border: none;
  background: none;
  font-size: 1.3rem;
  cursor: pointer;
  opacity: 0.5;
  padding: 6px;
}

.bottom-nav button.active {
  opacity: 1;
}

.toast {
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  max-width: 448px;
  margin: 0 auto;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.toast button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}

.banner {
  background: rgba(80, 200, 120, 0.15);
  border: 1px solid rgba(80, 200, 120, 0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.export-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.export-row button {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--secondary);
  color: var(--text);
  cursor: pointer;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

.overlay-card {
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  max-width: 320px;
}

.overlay-card h2 {
  margin-bottom: 8px;
}

.overlay-card button {
  margin-top: 16px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-size: 1rem;
}

.trophy-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.trophy-list li.unlocked {
  color: var(--text);
}

.trophy-list li.locked {
  color: var(--hint);
  opacity: 0.6;
}
