/* ====== Base / reset ====== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  font-size: 17px;
  line-height: 1.45;
  overscroll-behavior: none;
}
body { user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ====== Screen system ====== */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  padding: max(env(safe-area-inset-top), 16px) 16px max(env(safe-area-inset-bottom), 16px);
}
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ====== Install banner ====== */
.install-banner {
  position: fixed; left: 12px; right: 12px; top: max(env(safe-area-inset-top), 8px);
  background: #1f6feb; color: #fff; padding: 12px 14px; border-radius: 12px;
  display: flex; align-items: center; gap: 12px; z-index: 100;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  font-size: 14px;
}
.install-text { flex: 1; line-height: 1.35; }
.install-actions { display: flex; gap: 8px; flex-shrink: 0; }
.install-btn {
  background: #fff; color: #1f6feb; padding: 8px 14px;
  border-radius: 8px; font-weight: 600; font-size: 14px;
}
.link-btn-small { color: rgba(255,255,255,0.8); padding: 8px; font-size: 13px; }

/* ====== Home screen ====== */
.home-header { padding: 12px 4px 16px; }
.home-header-row { display: flex; align-items: center; justify-content: space-between; }
.home-header h1 { font-size: 28px; font-weight: 700; color: #e6edf3; letter-spacing: -0.02em; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 18px; color: #c9d1d9;
            background: #161b22; border: 1px solid #30363d; }
.icon-btn:active { background: #21262d; }
.deadline { margin-top: 4px; font-size: 13px; color: #7d8590; text-transform: uppercase; letter-spacing: 0.08em; text-align: center; }

.stat-row { display: flex; gap: 10px; margin-bottom: 24px; }
.stat { flex: 1; background: #161b22; border: 1px solid #21262d; border-radius: 12px;
        padding: 14px 8px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 700; color: #58a6ff; }
.stat-label { font-size: 11px; color: #7d8590; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }

.decks { display: flex; flex-direction: column; gap: 12px; flex: 1; }
.deck-card {
  text-align: left; background: #161b22; border: 1px solid #30363d; border-radius: 14px;
  padding: 18px 18px 14px; color: inherit; transition: transform 80ms, background 120ms;
  width: 100%;
}
.deck-card:active { transform: scale(0.98); background: #1c2029; }
.deck-title { font-size: 18px; font-weight: 600; color: #e6edf3; }
.deck-sub { font-size: 12px; color: #7d8590; margin-top: 2px; letter-spacing: 0.03em; }
.deck-progress { position: relative; height: 8px; background: #21262d; border-radius: 4px; margin-top: 14px; overflow: hidden; }
.deck-progress-bar { position: absolute; top: 0; left: 0; height: 100%;
                     background: linear-gradient(90deg, #58a6ff, #1f6feb);
                     transition: width 300ms ease; }
.deck-mastered-bar { position: absolute; top: 0; left: 0; height: 100%;
                     background: linear-gradient(90deg, #3fb950, #2ea043);
                     transition: width 300ms ease; }
.deck-meta { font-size: 12px; color: #7d8590; margin-top: 8px; }

.sync-status { text-align: center; padding: 8px; font-size: 11px; color: #7d8590; }
.sync-status[data-status="synced"]::before { content: '☁ synced'; color: #3fb950; }
.sync-status[data-status="pending"]::before { content: '☁ pending…'; color: #d29922; }
.sync-status[data-status="error"]::before { content: '☁ offline'; color: #7d8590; }
.sync-status[data-status="idle"]::before { content: ''; }

/* ====== Drill screen ====== */
.drill-header { display: flex; align-items: center; gap: 12px; padding: 8px 0 16px; }
.back-btn { font-size: 20px; width: 40px; height: 40px; flex-shrink: 0;
            border-radius: 50%; background: #161b22; border: 1px solid #30363d; }
.back-btn:active { background: #21262d; }

.progress-wrap { flex: 1; }
.progress-bar { height: 6px; background: #21262d; border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #3fb950, #58a6ff); width: 0%; transition: width 200ms ease; }
.progress-text { margin-top: 4px; text-align: right; font-size: 11px; color: #7d8590; letter-spacing: 0.05em; }

.drill-body { flex: 1; display: flex; flex-direction: column; padding-top: 8px; padding-bottom: 24px; }

.case-badge { font-size: 11px; color: #79c0ff; text-transform: uppercase; letter-spacing: 0.08em;
              margin-bottom: 4px; font-weight: 600; }
.quantity-badge { font-size: 13px; color: #d2a8ff; font-weight: 500; margin-bottom: 14px; }

/* ====== Diagram ====== */
.card-diagram {
  background: #0a0e14; border: 1px solid #21262d; border-radius: 10px;
  padding: 12px 8px; margin-bottom: 18px;
}
.beam-diagram { width: 100%; height: auto; display: block; max-height: 240px; }

.stem { font-size: 19px; color: #e6edf3; font-weight: 500; line-height: 1.4; margin-bottom: 22px; }

/* ====== Skip button ====== */
.skip-btn {
  width: 100%; padding: 12px; margin-bottom: 12px;
  background: transparent; border: 1px dashed #30363d; border-radius: 10px;
  color: #7d8590; font-size: 14px; font-weight: 500;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.skip-btn:active { background: #161b22; color: #c9d1d9; border-color: #58a6ff; }

/* ====== Choices ====== */
.choices { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.choice-btn {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 16px 18px; border: 1px solid #30363d; border-radius: 12px;
  background: #161b22; text-align: left; color: #c9d1d9;
  font-size: 16px; line-height: 1.35;
  transition: transform 80ms, background 120ms, border-color 120ms;
  min-height: 64px;
}
.choice-btn:active { transform: scale(0.98); background: #1c2029; }
.choice-label { font-weight: 700; color: #58a6ff; flex-shrink: 0; font-size: 16px; }
.choice-text { flex: 1; }

.choice-btn.correct { background: #0f3820; border-color: #3fb950; }
.choice-btn.correct .choice-label { color: #3fb950; }
.choice-btn.incorrect { background: #401414; border-color: #f85149; }
.choice-btn.incorrect .choice-label { color: #f85149; }
.choice-btn.was-correct-unanswered { border-color: #3fb950; border-style: dashed; }
.choice-btn:disabled { cursor: default; opacity: 0.85; }

/* ====== Introduce panel ====== */
.introduce-panel {
  background: #161b22; border: 1px solid #d29922; border-radius: 14px;
  padding: 18px;
}
.intro-banner { font-size: 13px; color: #d29922; margin-bottom: 14px; font-weight: 600; }
.intro-answer {
  background: #0f3820; border: 1px solid #3fb950; border-radius: 8px;
  padding: 12px 14px; margin-bottom: 14px; color: #e6edf3; font-size: 16px;
}
.intro-answer strong { color: #3fb950; }
.introduce-body { color: #c9d1d9; }

/* ====== Reveal panel + 4-part structure ====== */
.reveal {
  background: #161b22; border: 1px solid #30363d; border-radius: 14px;
  padding: 18px; margin-top: 4px;
}
.reveal-header { margin-bottom: 12px; }
.verdict { display: inline-block; font-size: 13px; font-weight: 700;
           padding: 4px 10px; border-radius: 6px; letter-spacing: 0.04em; }
.verdict.right { background: #0f3820; color: #3fb950; }
.verdict.wrong { background: #401414; color: #f85149; }
.verdict.skipped { background: #2a2615; color: #d29922; }

.reveal-body { font-size: 15px; color: #c9d1d9; line-height: 1.55; }
.reveal-content .reveal-section {
  border-left: 2px solid #30363d;
  padding: 4px 0 4px 12px;
  margin-bottom: 12px;
}
.reveal-section:last-child { margin-bottom: 0; }
.reveal-section .reveal-label {
  font-size: 10px; font-weight: 700; color: #7d8590;
  text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 4px;
}
.reveal-section .reveal-text { color: #c9d1d9; line-height: 1.5; }
.reveal-section:nth-child(1) { border-left-color: #58a6ff; }
.reveal-section:nth-child(1) .reveal-label { color: #58a6ff; }
.reveal-section:nth-child(2) { border-left-color: #d2a8ff; }
.reveal-section:nth-child(2) .reveal-label { color: #d2a8ff; }
.reveal-section:nth-child(3) { border-left-color: #d29922; }
.reveal-section:nth-child(3) .reveal-label { color: #d29922; }
.reveal-section:nth-child(4) { border-left-color: #3fb950; }
.reveal-section:nth-child(4) .reveal-label { color: #3fb950; }

.reveal-source { font-size: 11px; color: #7d8590; margin-top: 12px; padding-top: 10px; border-top: 1px solid #21262d; }

.trap-note { font-size: 13px; color: #d29922; margin-top: 10px; font-style: italic; line-height: 1.45; padding: 10px 12px; background: #2a2615; border-radius: 8px; }
.trap-note:empty { display: none; }

.guess-toggle {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 0 4px; cursor: pointer;
  font-size: 13px; color: #7d8590;
}
.guess-toggle input { margin-top: 2px; transform: scale(1.2); }
.guess-toggle span { line-height: 1.4; }

.btn-primary {
  width: 100%; padding: 16px; margin-top: 18px;
  background: #238636; border-radius: 10px; color: #fff; font-weight: 600; font-size: 16px;
}
.btn-primary:active { background: #1a6b2a; }

/* ====== Done screen ====== */
#screen-done { align-items: center; justify-content: center; }
#screen-done h1 { font-size: 32px; color: #e6edf3; margin-bottom: 28px; }
.done-stats { width: 100%; max-width: 360px; background: #161b22; border: 1px solid #30363d;
              border-radius: 14px; padding: 20px; margin-bottom: 24px; }
.done-row { display: flex; justify-content: space-between; padding: 8px 0;
            font-size: 16px; color: #c9d1d9; border-bottom: 1px solid #21262d; }
.done-row:last-child { border-bottom: none; }
.done-row span:first-child { color: #7d8590; }
.done-row span:last-child { font-weight: 600; color: #e6edf3; }
#screen-done .btn-primary { max-width: 360px; }

/* ====== Settings ====== */
.settings-title { color: #e6edf3; font-size: 22px; font-weight: 700; flex: 1; }
.settings-body { display: flex; flex-direction: column; gap: 18px; padding: 8px 0; }
.settings-group { background: #161b22; border: 1px solid #30363d; border-radius: 12px; padding: 16px; }
.settings-group.danger { border-color: #f85149; }
.settings-label { font-size: 12px; color: #7d8590; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.settings-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
                  color: #e6edf3; word-break: break-all; padding: 8px 10px; background: #0d1117;
                  border: 1px solid #21262d; border-radius: 6px; }
.settings-help { font-size: 12px; color: #7d8590; margin-top: 8px; line-height: 1.4; }
.settings-btn { width: 100%; padding: 12px; background: #21262d; color: #c9d1d9;
                border-radius: 8px; font-size: 15px; font-weight: 500; }
.settings-btn:active { background: #2c333d; }
.settings-btn.danger { background: #401414; color: #f85149; }
.settings-btn.danger:active { background: #5a1717; }

/* ====== Flash animations ====== */
@keyframes flashGreen { 0%, 100% { box-shadow: none; } 30% { box-shadow: inset 0 0 0 3px #3fb950; } }
@keyframes flashRed   { 0%, 100% { box-shadow: none; } 30% { box-shadow: inset 0 0 0 3px #f85149; } }
.screen.flash-correct { animation: flashGreen 400ms ease; }
.screen.flash-wrong { animation: flashRed 400ms ease; }
