:root {
  --bg: #081016;
  --surface: #101a21;
  --surface-2: #16242d;
  --line: #29404c;
  --text: #f4f7f8;
  --muted: #94a8b3;
  --cyan: #22d3c5;
  --cyan-dark: #073e3d;
  --amber: #ffb547;
  --danger: #ff6b6b;
  --success: #46dc91;
  font-family: Inter, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.app-shell { min-height: 100vh; }
.topbar { height: 72px; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 max(20px, calc((100vw - 1180px) / 2)); gap: 24px; position: sticky; top: 0; z-index: 20; background: rgba(8,16,22,.94); backdrop-filter: blur(16px); }
.brand { border: 0; color: var(--text); background: none; display: flex; align-items: center; gap: 10px; font: 700 22px/1 "Barlow Condensed", sans-serif; cursor: pointer; letter-spacing: .04em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; background: var(--cyan); color: #041314; font-size: 16px; clip-path: polygon(12% 0, 88% 0, 100% 24%, 100% 76%, 88% 100%, 12% 100%, 0 76%, 0 24%); }
.top-stats { margin-left: auto; display: flex; gap: 22px; color: var(--muted); font-size: 13px; }
.top-stats strong { color: var(--text); }
.icon-button, .back-button { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; font-size: 24px; border-radius: 4px; }
main { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 72px; }
.view { display: none; }
.view.active { display: block; animation: reveal .24s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
.mission-hero { position: relative; min-height: 500px; overflow: hidden; border: 1px solid var(--line); }
.mission-hero img, .story-banner img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero-scrim { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(4,10,14,.96) 0%, rgba(4,10,14,.78) 45%, rgba(4,10,14,.15) 78%); }
.hero-content { position: relative; z-index: 2; width: min(580px, 100%); padding: clamp(42px, 7vw, 84px); }
.eyebrow { color: var(--cyan); font: 700 13px/1.2 "Barlow Condensed", sans-serif; letter-spacing: .13em; margin: 0 0 14px; }
h1, h2 { font-family: "Barlow Condensed", sans-serif; letter-spacing: 0; margin: 0; }
h1 { font-size: clamp(44px, 7vw, 82px); line-height: .95; max-width: 760px; }
h2 { font-size: 29px; }
.hero-content > p:not(.eyebrow) { color: #c2cfd5; font-size: 17px; line-height: 1.65; max-width: 520px; margin: 24px 0 30px; }
.hero-actions, .flow-actions, .result-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.primary-button, .secondary-button { min-height: 50px; padding: 0 22px; border-radius: 4px; font-weight: 700; cursor: pointer; border: 1px solid transparent; }
.primary-button { background: var(--cyan); color: #041415; }
.primary-button:hover { background: #55e7dc; }
.primary-button:disabled { cursor: not-allowed; opacity: .45; background: #4b6668; }
.secondary-button { color: var(--text); border-color: var(--line); background: rgba(16,26,33,.85); }
.secondary-button:hover { border-color: var(--cyan); }
.compact { min-height: 40px; padding: 0 15px; }
.full-width { width: 100%; margin-top: 16px; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); padding: 26px; border-radius: 6px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.rank { color: var(--amber); font-size: 13px; border: 1px solid #66522f; padding: 6px 9px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 30px; }
.metrics div { display: flex; flex-direction: column; border-right: 1px solid var(--line); padding-left: 18px; }
.metrics div:first-child { padding-left: 0; }
.metrics div:last-child { border: 0; }
.metrics strong { font: 700 34px/1 "Barlow Condensed"; }
.metrics span { color: var(--muted); margin-top: 6px; font-size: 12px; }
.level-track, .quiz-progress { height: 5px; background: #24333b; margin-top: 26px; overflow: hidden; }
.level-track span, .quiz-progress span { display: block; height: 100%; background: var(--cyan); width: 0; transition: width .3s ease; }
.saved-lists { margin-top: 20px; min-height: 76px; display: grid; gap: 8px; }
.saved-item { display: flex; justify-content: space-between; align-items: center; color: var(--text); background: var(--surface-2); border: 1px solid transparent; padding: 13px 14px; cursor: pointer; text-align: left; }
.saved-item:hover { border-color: var(--cyan); }
.saved-item small, .empty-state { color: var(--muted); }
.flow-header { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 30px; }
.flow-header h1 { font-size: clamp(42px, 6vw, 68px); }
.subline { color: var(--muted); margin: 10px 0 0; }
.scan-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(260px, .7fr); gap: 18px; }
.drop-zone { min-height: 380px; border: 1px dashed #4c6875; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; cursor: pointer; background: #0b151b; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--cyan); background: #0b1f22; }
.drop-zone input { position: absolute; opacity: 0; pointer-events: none; }
.drop-zone strong { font-size: 20px; margin: 14px 0 8px; }
.drop-zone > span:last-child { color: var(--muted); max-width: 400px; line-height: 1.5; }
.scan-icon { font-size: 54px; color: var(--cyan); }
.preview-wrap canvas { width: 100%; max-height: 470px; object-fit: contain; background: #05090c; display: block; margin-bottom: 12px; }
.scan-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.scan-controls #replaceImageButton { margin-left: auto; }
.enhance-toggle { min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 11px; color: var(--muted); border: 1px solid var(--line); cursor: pointer; font-size: 12px; }
.enhance-toggle input { accent-color: var(--cyan); width: 17px; height: 17px; }
.ocr-status { display: flex; align-items: center; gap: 16px; padding: 18px; background: var(--surface-2); margin-top: 16px; }
.ocr-status div:last-child { display: flex; flex-direction: column; gap: 4px; }
.ocr-status span { color: var(--muted); font-size: 13px; }
.spinner { width: 28px; height: 28px; border: 3px solid #36515e; border-top-color: var(--cyan); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scan-tips { border-top: 2px solid var(--cyan); padding: 24px 20px; background: #0b151b; }
.scan-tips ol { list-style: none; margin: 24px 0; padding: 0; display: grid; gap: 24px; color: #c6d1d6; }
.scan-tips li { display: grid; grid-template-columns: 35px 1fr; gap: 10px; line-height: 1.45; }
.scan-tips li span { color: var(--cyan); font: 700 17px "Barlow Condensed"; }
.text-button { background: none; color: var(--cyan); border: 0; padding: 0; cursor: pointer; font-weight: 700; }
.review-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 14px; color: var(--muted); }
.word-table { display: grid; gap: 8px; }
.word-row { display: grid; grid-template-columns: 38px 1fr 1fr 42px; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); padding: 10px; }
.word-row.uncertain { border-color: #7d6538; }
.word-row .row-number { color: var(--muted); text-align: center; }
.word-row input { width: 100%; background: #081016; border: 1px solid #2e4652; color: var(--text); min-height: 46px; padding: 0 12px; border-radius: 3px; }
.word-row input:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }
.remove-row { color: var(--muted); background: none; border: 0; font-size: 22px; cursor: pointer; }
.flow-actions { justify-content: flex-end; margin-top: 24px; }
.genre-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.genre-card { min-height: 190px; background: var(--surface); border: 1px solid var(--line); color: var(--text); display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; text-align: left; padding: 20px; cursor: pointer; position: relative; border-radius: 5px; }
.genre-card > span { position: absolute; top: 18px; left: 18px; color: var(--muted); font: 700 14px "Barlow Condensed"; }
.genre-card strong { font: 700 25px "Barlow Condensed"; }
.genre-card small { color: var(--muted); margin-top: 4px; }
.genre-card.selected { border-color: var(--cyan); background: #0d292b; }
.genre-card.elite-card { border-top: 3px solid #ef5757; background: #1b1217; }
.genre-card.elite-card.selected { border-color: #ef5757; box-shadow: inset 0 0 0 1px #ef5757; }
.genre-card.vault-card { border-top: 3px solid var(--amber); background: #1b1912; }
.genre-card.vault-card.selected { border-color: var(--amber); box-shadow: inset 0 0 0 1px var(--amber); }
.difficulty-panel { margin-top: 18px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.difficulty-panel p:last-child { color: var(--muted); margin-bottom: 0; }
.segmented { border: 1px solid var(--line); display: flex; }
.segmented button { border: 0; background: transparent; color: var(--muted); min-height: 42px; padding: 0 18px; cursor: pointer; }
.segmented button.selected { color: #061517; background: var(--cyan); }
.story-banner { height: 330px; position: relative; border: 1px solid var(--line); display: flex; align-items: flex-end; padding: 34px; overflow: hidden; }
.story-banner > div:last-child { position: relative; z-index: 2; }
.story-banner h1 { font-size: clamp(48px, 7vw, 76px); }
.story-back { position: absolute; z-index: 3; top: 20px; left: 20px; }
.story-copy { width: min(800px, 100%); margin: 40px auto 0; color: #d5dee2; font-size: 18px; line-height: 1.9; }
.story-copy p { margin: 0; }
.story-chapter { position: relative; padding: 28px 0 28px 54px; border-left: 1px solid var(--line); }
.chapter-index { position: absolute; left: -18px; top: 28px; width: 35px; height: 35px; display: grid; place-items: center; color: #061416; background: var(--cyan); font: 700 13px "Barlow Condensed"; }
.story-chapter h2 { margin-bottom: 11px; font-size: 27px; color: var(--text); }
.story-transmission { margin: 14px 0 0; padding: 12px 15px; border-left: 3px solid var(--amber); background: #181a19; color: #e8d4aa; font: 600 13px/1.5 monospace; }
.story-choice { margin: 28px 0 28px 54px; padding: 22px; border: 1px solid var(--cyan); background: #0b1f22; }
.story-choice h2 { font-size: 27px; }
.story-choice p { color: var(--muted); margin: 8px 0 16px; }
.choice-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.choice-button { min-height: 54px; padding: 12px; color: var(--text); border: 1px solid var(--line); background: var(--surface); text-align: left; cursor: pointer; }
.choice-button:hover, .choice-button.selected { border-color: var(--cyan); color: var(--cyan); }
.decision-result { margin-top: 13px; color: var(--success) !important; }
.vocab-word { color: #081016; background: var(--cyan); border: 0; padding: 2px 5px; font-weight: 700; cursor: help; position: relative; }
.vocab-word.revealed::after { content: attr(data-translation); position: absolute; z-index: 4; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); color: var(--text); background: #17262e; border: 1px solid var(--line); padding: 6px 9px; white-space: nowrap; font-size: 12px; }
.story-legend { width: min(760px, 100%); margin: 20px auto; color: var(--muted); font-size: 13px; }
.story-legend i { display: inline-block; width: 12px; height: 12px; background: var(--cyan); margin-right: 7px; }
.quiz-shell, .result-shell { width: min(760px, 100%); margin: 38px auto; }
.quiz-topline { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.mission-hud { display: grid; grid-template-columns: 1fr 1fr 1fr; border: 1px solid var(--line); margin-top: 16px; }
.mission-hud > div { min-height: 58px; display: flex; align-items: center; justify-content: center; gap: 10px; border-right: 1px solid var(--line); }
.mission-hud > div:last-child { border: 0; }
.mission-hud small { color: var(--muted); font: 700 11px "Barlow Condensed"; letter-spacing: .1em; }
.mission-hud strong { color: var(--cyan); font: 700 21px "Barlow Condensed"; }
.shield-pips { display: flex; gap: 5px; }
.shield-pips i { width: 12px; height: 16px; background: var(--cyan); clip-path: polygon(50% 0, 100% 20%, 88% 80%, 50% 100%, 12% 80%, 0 20%); }
.shield-pips i.lost { background: #26363e; }
.mission-alert { margin: 12px 0 0; color: var(--amber); font: 600 12px/1.4 monospace; min-height: 18px; }
.quiz-shell > .eyebrow { margin-top: 34px; }
.quiz-shell h1 { font-size: clamp(46px, 7vw, 72px); margin-bottom: 34px; }
.answer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.answer { min-height: 68px; padding: 16px; text-align: left; color: var(--text); background: var(--surface); border: 1px solid var(--line); cursor: pointer; border-radius: 4px; }
.answer:hover { border-color: var(--cyan); }
.answer::first-letter { color: var(--cyan); }
.answer.correct { border-color: var(--success); background: #103126; }
.answer.wrong { border-color: var(--danger); background: #351a1d; }
.answer:disabled { cursor: default; }
.quiz-feedback { min-height: 28px; color: var(--muted); }
.result-shell { text-align: center; background: var(--surface); border: 1px solid var(--line); padding: clamp(30px, 7vw, 70px); }
.result-shell h1 { font-size: clamp(50px, 8vw, 80px); }
.result-score { width: 170px; height: 170px; margin: 35px auto; border: 2px solid var(--cyan); border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.result-score strong { font: 700 52px "Barlow Condensed"; }
.result-score span { color: var(--muted); font-size: 12px; }
.result-details { display: flex; justify-content: center; gap: 36px; margin-bottom: 30px; color: var(--muted); }
.result-details strong { color: var(--text); }
.mastery-review { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 0 auto 28px; text-align: left; }
.mastery-item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; background: #0b151b; border-left: 3px solid var(--danger); font-size: 13px; }
.mastery-item.secure { border-left-color: var(--success); }
.mastery-item span:last-child { color: var(--muted); }
.result-actions { justify-content: center; }
.modal-backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 18px; background: rgba(2,7,10,.82); backdrop-filter: blur(8px); }
.profile-modal { width: min(680px, 100%); max-height: calc(100vh - 36px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--cyan); padding: clamp(22px, 5vw, 38px); border-radius: 6px; box-shadow: 0 24px 90px #000b; }
.profile-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.profile-header h2 { font-size: 40px; }
.profile-name { display: grid; gap: 7px; color: var(--muted); font-size: 12px; margin-top: 25px; }
.profile-name input { height: 48px; background: #081016; color: var(--text); border: 1px solid var(--line); padding: 0 13px; font-size: 17px; border-radius: 3px; }
.profile-name input:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }
.profile-rank { display: flex; align-items: center; gap: 16px; margin: 24px 0; }
.rank-emblem { width: 70px; height: 70px; display: grid; place-items: center; flex: 0 0 auto; color: #051315; background: var(--cyan); font: 700 32px "Barlow Condensed"; clip-path: polygon(50% 0, 93% 22%, 93% 74%, 50% 100%, 7% 74%, 7% 22%); }
.profile-rank > div:last-child { display: flex; flex-direction: column; gap: 3px; }
.profile-rank small, .profile-rank span { color: var(--muted); font-size: 11px; }
.profile-rank strong { font: 700 30px "Barlow Condensed"; }
.profile-metrics { display: grid; grid-template-columns: repeat(4, 1fr); border-block: 1px solid var(--line); padding: 22px 0; }
.profile-metrics div { display: flex; flex-direction: column; gap: 5px; text-align: center; border-right: 1px solid var(--line); }
.profile-metrics div:last-child { border: 0; }
.profile-metrics strong { font: 700 30px "Barlow Condensed"; }
.profile-metrics span { color: var(--muted); font-size: 11px; }
.achievement-section { margin-top: 25px; }
.achievement-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.achievement { display: grid; grid-template-columns: 36px 1fr; gap: 10px; align-items: center; padding: 12px; background: #0b151b; color: var(--muted); opacity: .5; }
.achievement.unlocked { color: var(--text); opacity: 1; }
.achievement-icon { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); color: var(--muted); }
.achievement.unlocked .achievement-icon { color: #061416; background: var(--amber); border-color: var(--amber); }
.achievement strong, .achievement small { display: block; }
.achievement strong { font-size: 13px; }
.achievement small { color: var(--muted); margin-top: 3px; font-size: 10px; }
.profile-actions { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-top: 26px; }
.profile-actions > span { color: var(--muted); font-size: 11px; line-height: 1.4; max-width: 290px; }
.toast { position: fixed; z-index: 100; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: #e9fdfa; color: #071415; padding: 13px 18px; opacity: 0; pointer-events: none; transition: .2s ease; box-shadow: 0 12px 35px #0008; border-radius: 4px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hidden { display: none !important; }

@media (max-width: 760px) {
  .topbar { height: 62px; padding: 0 14px; gap: 12px; }
  .top-stats span:first-child { display: none; }
  main { width: min(100% - 24px, 1180px); padding-top: 18px; }
  .mission-hero { min-height: 620px; }
  .mission-hero img { object-position: 62% center; }
  .hero-scrim { background: linear-gradient(0deg, rgba(4,10,14,.98) 0%, rgba(4,10,14,.75) 58%, rgba(4,10,14,.1) 100%); }
  .hero-content { position: absolute; bottom: 0; padding: 28px 22px; }
  .hero-content h1 { font-size: 52px; }
  .hero-actions > * { flex: 1 1 100%; }
  .home-grid, .scan-layout { grid-template-columns: 1fr; }
  .metrics strong { font-size: 29px; }
  .panel { padding: 20px; }
  .drop-zone { min-height: 310px; }
  .scan-controls > * { flex: 1 1 calc(50% - 8px); }
  .scan-controls #replaceImageButton { margin-left: 0; }
  .word-row { grid-template-columns: 26px 1fr 36px; }
  .word-row input:nth-of-type(2) { grid-column: 2; }
  .word-row .remove-row { grid-column: 3; grid-row: 1 / span 2; }
  .genre-grid { grid-template-columns: 1fr 1fr; }
  .genre-card { min-height: 150px; }
  .difficulty-panel { align-items: flex-start; flex-direction: column; }
  .story-banner { height: 300px; padding: 22px; }
  .story-copy { font-size: 17px; line-height: 1.75; }
  .answer-grid { grid-template-columns: 1fr; }
  .flow-actions > * { flex: 1; }
  .profile-metrics { grid-template-columns: 1fr 1fr; gap: 18px 0; }
  .profile-metrics div:nth-child(2) { border: 0; }
  .achievement-grid { grid-template-columns: 1fr; }
  .profile-actions { align-items: stretch; flex-direction: column; }
  .mastery-review { grid-template-columns: 1fr; }
  .story-chapter { padding-left: 34px; }
  .story-choice { margin-left: 34px; }
  .choice-actions { grid-template-columns: 1fr; }
  .mission-hud > div { gap: 6px; }
}

@media (max-width: 420px) {
  .top-stats { gap: 8px; }
  .brand > span:last-child { font-size: 19px; }
  .genre-grid { grid-template-columns: 1fr; }
  .genre-card { min-height: 125px; }
  .review-toolbar { align-items: flex-start; flex-direction: column; }
}
