/* ---------- DGT Trainer — design tokens ---------- */
:root,
[data-theme="light"] {
  --bg:           #FFF4EB;
  --bg-2:         #FFE9D6;
  --card:         #FFFFFF;
  --card-2:       #FFF1E5;
  --text:         #1A1410;
  --text-muted:   #6B5C50;
  --primary:      #FF6B2A;
  --primary-soft: #FFE0CC;
  --primary-ink:  #FFFFFF;
  --accent:       #1A1410;
  --accent-ink:   #FFFFFF;
  --success:      #16A34A;
  --success-bg:   #DCFCE7;
  --danger:       #E11D48;
  --danger-bg:    #FFE4E6;
  --shadow:       0 6px 24px rgba(26, 20, 16, 0.08);
  --shadow-sm:    0 2px 8px rgba(26, 20, 16, 0.06);
  --radius-lg:    24px;
  --radius-md:    16px;
  --radius-sm:    12px;
}

[data-theme="dark"] {
  --bg:           #15110D;
  --bg-2:         #1F1813;
  --card:         #251C16;
  --card-2:       #2E2419;
  --text:         #F4ECDF;
  --text-muted:   #9A8B7C;
  --primary:      #FF7A3D;
  --primary-soft: #3A241A;
  --primary-ink:  #15110D;
  --accent:       #F4ECDF;
  --accent-ink:   #15110D;
  --success:      #4ADE80;
  --success-bg:   #1B3A24;
  --danger:       #F87171;
  --danger-bg:    #3B1A1F;
  --shadow:       0 6px 24px rgba(0, 0, 0, 0.5);
  --shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; }

/* ---------- Layout ---------- */
.app-shell {
  max-width: 460px;
  margin: 0 auto;
  padding: 16px 16px 110px;
  min-height: 100vh;
}

.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-h h3 { margin: 0; font-size: 15px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 16px; padding: 14px 18px;
  font-weight: 600; cursor: pointer;
  transition: transform .06s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(255, 107, 42, 0.35); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--primary-soft); }
.btn-block { width: 100%; }

.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.icon-btn {
  background: var(--card);
  border: 0;
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--text); cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Header (greeting) ---------- */
.hello { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.hello-l { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink);
  display: grid; place-items: center; font-weight: 700;
}
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.hello-greet { font-weight: 700; }
.hello-sub { color: var(--text-muted); font-size: 13px; }
.wave { display: inline-block; }

/* ---------- Page header ---------- */
.page-h { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.page-h h1 { font-size: 22px; margin: 0; }
.back-btn {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--card); display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}

/* ---------- Readiness card ---------- */
.readiness-card {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(180deg, var(--card) 0%, var(--card-2) 100%);
}
.kicker { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.ready-num { font-size: 44px; font-weight: 800; line-height: 1; }
.ready-num span { font-size: 20px; color: var(--text-muted); font-weight: 600; }
.readiness-sub { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.readiness-ring { width: 100px; height: 100px; flex: 0 0 100px; }
.ring-bg { fill: none; stroke: var(--primary-soft); stroke-width: 10; }
.ring-fg {
  fill: none; stroke: var(--primary); stroke-width: 10; stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 60px 60px;
  transition: stroke-dasharray .6s ease;
}

/* ---------- Action cards ---------- */
.actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.action-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}
.action-card.primary { background: var(--primary); color: var(--primary-ink); }
.action-card.primary .action-sub { color: rgba(255,255,255,.85); }
.action-icon {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center; font-size: 18px;
  background: rgba(255,255,255,.2);
}
.action-card:not(.primary) .action-icon { background: var(--primary-soft); color: var(--primary); }
.action-card .icon-soft { background: var(--primary-soft); color: var(--primary); }
.action-card .icon-warn { background: #FFE4B0; color: #B45309; }
.action-title { font-weight: 700; }
.action-sub { font-size: 12px; color: var(--text-muted); }

/* ---------- Bars ---------- */
.bar { background: var(--primary-soft); border-radius: 99px; height: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s ease; }

/* ---------- Topic list ---------- */
.topic-list { list-style: none; padding: 0; margin: 0; }
.topic-list li { padding: 8px 0; }
.topic-row { display: flex; justify-content: space-between; margin-bottom: 6px; }
.topic-title { font-weight: 600; }
.topic-meta { color: var(--text-muted); font-size: 12px; }

.topics-grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.topic-tile {
  display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.topic-tile h3 { margin: 0; font-size: 16px; }
.topic-tile p { margin: 0; }
.topic-tile form { margin-top: 6px; }
.topic-tile-h { display: flex; justify-content: space-between; align-items: center; }
.topic-tag {
  background: var(--primary-soft); color: var(--primary);
  font-size: 11px; padding: 4px 8px; border-radius: 8px; font-weight: 600;
}

/* ---------- Recent list ---------- */
.recent-list, .review-list, .history-list { list-style: none; padding: 0; margin: 0; }
.recent-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--bg-2); }
.recent-list li:last-child .recent-row { border-bottom: 0; }
.recent-mode { font-weight: 600; }
.recent-score { display: flex; align-items: center; gap: 8px; color: var(--text-muted); }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; font-weight: 600; }
.pill.pass { background: var(--success-bg); color: var(--success); }
.pill.fail { background: var(--danger-bg); color: var(--danger); }

/* ---------- Question screen ---------- */
.question-h { gap: 10px; }
.question-h .prog { flex: 1; }
.prog-meta { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.prog-meta .timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.prog-meta .timer.warn { color: var(--danger); }
.lang-btn {
  background: var(--card); border: 0; padding: 8px 12px; border-radius: 10px;
  font-weight: 700; color: var(--text); box-shadow: var(--shadow-sm); cursor: pointer;
}

.question-card { display: flex; flex-direction: column; gap: 14px; }
.question-image {
  border-radius: 16px; overflow: hidden;
  background: var(--bg-2);
  display: grid; place-items: center;
  max-height: 50vh;
}
.question-image img {
  max-width: 100%; max-height: 50vh;
  width: auto; height: auto;
  object-fit: contain;
}
.q-text { font-size: 17px; margin: 0; line-height: 1.4; font-weight: 600; }
.lang-es { display: none; }
[data-lang="es"] .lang-ru { display: none; }
[data-lang="es"] .lang-es { display: inline; }

.options { display: flex; flex-direction: column; gap: 8px; padding: 0; margin: 0; list-style: none; }
.opt {
  display: flex; align-items: center; gap: 12px;
  background: var(--card-2); border: 2px solid transparent;
  padding: 12px; border-radius: 16px; text-align: left;
  color: var(--text);
  transition: border-color .15s ease, background .15s ease;
}
button.opt-letter {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card); color: var(--text);
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
  flex: 0 0 44px; border: 0; cursor: pointer;
  transition: transform .08s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
}
button.opt-letter:hover  { background: var(--primary); color: var(--primary-ink); box-shadow: 0 6px 14px rgba(255, 107, 42, 0.35); }
button.opt-letter:active { transform: scale(0.94); }
button.opt-letter:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.opt-text { font-weight: 500; user-select: text; cursor: text; }
.options.static .opt { cursor: default; }
.options.static .opt-letter { cursor: default; pointer-events: none; }

/* For feedback mode where opt is just a div, keep the inert letter rendering */
.opt.is-correct                 { background: var(--success-bg); border-color: var(--success); }
.opt.is-correct .opt-letter,
.opt.is-correct  button.opt-letter { background: var(--success); color: #fff; }
.opt.is-wrong                   { background: var(--danger-bg);  border-color: var(--danger); }
.opt.is-wrong  .opt-letter,
.opt.is-wrong  button.opt-letter   { background: var(--danger);  color: #fff; }

/* Word hints */
.w { display: inline; }
.lang-es .w.hintable {
  cursor: pointer;
  border-bottom: 1px dashed var(--primary);
  padding-bottom: 1px;
}
.lang-es .w.hintable:hover { color: var(--primary); }
.hint-tooltip {
  position: absolute;
  background: var(--accent); color: var(--accent-ink);
  padding: 8px 12px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  max-width: 260px; z-index: 100;
  pointer-events: none;
}
.hint-tooltip .hint-word { font-weight: 700; font-size: 13px; opacity: .8; }
.hint-tooltip .hint-trans { font-size: 15px; margin-top: 2px; }
.hint-row { margin-top: -4px; }

/* Toast for translation-limit warnings etc */
.lang-toast {
  position: fixed; left: 50%; bottom: 100px;
  transform: translateX(-50%) translateY(8px);
  background: var(--accent); color: var(--accent-ink);
  padding: 12px 16px; border-radius: 14px;
  font-weight: 500; font-size: 14px; max-width: 340px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; z-index: 200;
  transition: opacity .2s ease, transform .2s ease;
}
.lang-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.feedback .verdict {
  font-weight: 700; padding: 10px 12px; border-radius: 12px;
  background: var(--card-2); color: var(--text);
}
.feedback.ok  .verdict { background: var(--success-bg); color: var(--success); }
.feedback.bad .verdict { background: var(--danger-bg);  color: var(--danger); }

/* ---------- Result ---------- */
.result-card { text-align: center; padding: 24px 18px; }
.result-badge {
  display: inline-block; font-weight: 700;
  background: var(--primary-soft); color: var(--primary);
  padding: 6px 14px; border-radius: 99px; margin-bottom: 8px;
}
.result-card.pass .result-badge { background: var(--success-bg); color: var(--success); }
.result-card.fail .result-badge { background: var(--danger-bg);  color: var(--danger); }
.result-score { font-size: 56px; font-weight: 800; line-height: 1; }
.result-score span { font-size: 24px; color: var(--text-muted); }
.result-meta { color: var(--text-muted); margin-top: 6px; }

.rev { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--bg-2); }
.rev:last-child { border-bottom: 0; }
.rev-num {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--card-2); font-weight: 700; flex: 0 0 36px;
}
.rev.ok  .rev-num { background: var(--success-bg); color: var(--success); }
.rev.bad .rev-num { background: var(--danger-bg);  color: var(--danger); }
.rev-q { font-weight: 500; }
.rev-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---------- History ---------- */
.history-row a {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 6px;
}
.hist-mode { font-weight: 600; }
.hist-score { font-weight: 700; font-size: 18px; }
.hist-meta { grid-column: 1 / -1; color: var(--text-muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }

.empty { text-align: center; color: var(--text-muted); padding: 32px; }

/* ---------- Profile ---------- */
.prof-h { display: flex; gap: 14px; align-items: center; }
.prof-name { font-weight: 700; font-size: 18px; }
.kv { display: grid; gap: 8px; }
.kv > div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--bg-2); }
.kv > div:last-child { border-bottom: 0; }
.kv span { color: var(--text-muted); }

/* ---------- Bottom nav (dark pill, like screenshot) ---------- */
.bottom-nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 16px; z-index: 50;
  display: flex; gap: 4px;
  background: var(--accent); color: var(--accent-ink);
  padding: 8px; border-radius: 999px;
  box-shadow: 0 12px 28px rgba(0,0,0,.25);
}
.bn-item {
  width: 56px; height: 48px; border-radius: 999px;
  display: grid; place-items: center;
  color: var(--accent-ink); opacity: .65; transition: opacity .15s, background .15s;
}
.bn-item:hover { opacity: 1; }
.bn-item.active { background: var(--primary); color: var(--primary-ink); opacity: 1; }
.bn-item svg { width: 22px; height: 22px; }

/* ---------- Login ---------- */
body.auth .app-shell { padding-top: 40px; }
.auth-wrap { display: flex; flex-direction: column; gap: 20px; }
.brand { text-align: center; padding: 12px 0; }
.brand-mark {
  display: inline-block; padding: 6px 12px; border-radius: 10px;
  background: var(--primary); color: var(--primary-ink); font-weight: 800; margin-bottom: 6px;
}
.brand-title { margin: 0; font-size: 26px; }
.brand-sub { color: var(--text-muted); margin-top: 4px; }
.auth-card h2 { margin: 0 0 12px; }
.auth-card label { display: block; margin-bottom: 12px; }
.auth-card label > span { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.auth-card input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  background: var(--card-2); color: var(--text);
  border: 1px solid transparent; font-size: 16px;
}
.auth-card input:focus { outline: 0; border-color: var(--primary); }
.auth-card .hint { color: var(--text-muted); font-size: 12px; margin-top: 12px; text-align: center; }
.alert { background: var(--danger-bg); color: var(--danger); padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; }

.logout-form { margin-top: 18px; }

/* Segment control (RU/ES picker) */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 4px 0;
}
.setting-title { font-weight: 600; }
.seg {
  display: inline-flex; gap: 2px; padding: 4px;
  background: var(--card-2); border-radius: 12px;
}
.seg-opt {
  position: relative; padding: 8px 14px; border-radius: 8px;
  font-weight: 600; cursor: pointer; color: var(--text-muted);
  transition: background .15s, color .15s;
  user-select: none;
}
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt.active { background: var(--primary); color: var(--primary-ink); }
.seg-opt:hover:not(.active) { color: var(--text); }

/* ============================================================ */
/* Tablet (>= 700px) and Desktop (>= 1024px) responsive layouts  */
/* ============================================================ */

@media (min-width: 700px) {
  .app-shell {
    max-width: 720px;
    padding: 24px 24px 110px;
  }

  /* Topics: two-column grid */
  .topics-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }

  /* Action cards become horizontal on the dashboard */
  .actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .actions .action-card {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
  }
  .actions .action-card.primary { flex-basis: 100%; }

  /* Readiness card: bigger numbers and ring */
  .ready-num { font-size: 56px; }
  .readiness-ring { width: 130px; height: 130px; flex-basis: 130px; }

  /* Hover lift on tappable cards */
  .action-card,
  .topic-tile,
  .history-row {
    transition: transform .15s ease, box-shadow .15s ease;
  }
  .action-card:hover,
  .topic-tile:hover,
  .history-row:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(26, 20, 16, 0.12);
  }
  [data-theme="dark"] .action-card:hover,
  [data-theme="dark"] .topic-tile:hover,
  [data-theme="dark"] .history-row:hover {
    box-shadow: 0 12px 30px rgba(0,0,0,.55);
  }

  /* Larger header */
  .hello-greet { font-size: 18px; }
  .avatar { width: 52px; height: 52px; }

  /* Question card centered with more breathing room */
  .question-card { padding: 24px; gap: 18px; }
  .q-text { font-size: 19px; }
}

@media (min-width: 1024px) {
  .app-shell {
    max-width: 1100px;
    padding: 32px 40px 120px;
  }

  /* Topics: 3-column grid */
  .topics-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; }

  /* Dashboard: 2-column grid. Header / actions / cards / logout flow nicely. */
  body.page-dashboard .app-shell {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 20px;
    align-content: start;
  }
  body.page-dashboard .app-shell > .hello,
  body.page-dashboard .app-shell > .logout-form {
    grid-column: 1 / -1;
  }
  body.page-dashboard .app-shell > .actions { grid-column: 1 / -1; }
  body.page-dashboard .actions { flex-direction: row; }
  body.page-dashboard .actions .action-card { flex: 1 1 calc(33.33% - 7px); }
  body.page-dashboard .actions .action-card.primary { flex-basis: calc(33.33% - 7px); }

  /* Question screen on desktop: limit width, centered */
  .question-card { max-width: 720px; margin: 0 auto; }
  .question-image { max-height: 360px; }

  /* Larger question text */
  .q-text { font-size: 20px; }

  /* Centered result card narrower */
  .result-card { max-width: 600px; margin: 0 auto 14px; }

  /* Bottom nav slightly wider with more padding */
  .bottom-nav { padding: 10px; gap: 6px; }
  .bn-item { width: 64px; height: 52px; }
  .bn-item svg { width: 24px; height: 24px; }
}

/* Pointer / hover refinements */
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { filter: brightness(1.04); }
  .lang-btn:hover { background: var(--primary-soft); }
}
