/* ===== DESIGN TOKENS ===== */
:root {
  --bg-base: #F4F1EA;
  --bg-surface: rgba(255, 255, 255, 0.6);
  --color-stone: #78716C;
  --color-sage: #A3B18A;
  --color-clay: #BC8F8F;
  --color-parchment: #EDE8DF;
  --color-sage-dark: #7a9160;
  --color-clay-dark: #9e6b6b;
  --shadow-ambient: 0 10px 30px -10px rgba(120, 113, 108, 0.12),
                    0 4px 10px -5px rgba(120, 113, 108, 0.06);
  --radius-pill: 9999px;
  --radius-card: 2rem;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  min-height: 100%;
  background-color: var(--bg-base);
  font-family: 'Montserrat', sans-serif;
  color: var(--color-stone);
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* Rice paper texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
  z-index: 0;
}

/* ===== SCREEN LAYOUT ===== */
.screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== HOME SCREEN ===== */
.home-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem 3rem;
  gap: 2.5rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.home-hero {
  text-align: center;
}

.home-title {
  font-family: 'Lora', serif;
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 600;
  color: var(--color-stone);
  line-height: 1.2;
  margin-bottom: 0.5rem;
}

.home-subtitle {
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--color-stone);
  opacity: 0.65;
  text-transform: uppercase;
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  padding: 1.5rem 1.75rem;
  border-radius: var(--radius-card);
  border: 1.5px solid rgba(120, 113, 108, 0.18);
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-ambient);
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  font-family: 'Montserrat', sans-serif;
  width: 100%;
}

.mode-card--active:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px -10px rgba(120, 113, 108, 0.18),
              0 6px 14px -5px rgba(120, 113, 108, 0.1);
}

.mode-card--active:active {
  transform: translateY(0);
}

.mode-card--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mode-card__icon {
  font-size: 1.4rem;
  margin-bottom: 0.25rem;
}

.mode-card__title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-stone);
}

.mode-card__desc {
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--color-stone);
  opacity: 0.6;
}

.mode-card__badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--color-parchment);
  color: var(--color-stone);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(120, 113, 108, 0.2);
}

.stats-strip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.82rem;
  color: var(--color-stone);
  opacity: 0.65;
}

.stats-sep { opacity: 0.4; }
.stats-item strong { font-weight: 600; opacity: 1; color: var(--color-stone); }

/* ===== TOPICS SCREEN ===== */
#screen-topics {
  padding-bottom: 7rem;
}

.topics-header {
  padding: 1.25rem 1.25rem 0.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn-back {
  background: none;
  border: none;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-stone);
  opacity: 0.65;
  cursor: pointer;
  padding: 0.4rem 0;
  transition: opacity 0.15s;
}

.btn-back:hover { opacity: 1; }

.topics-title {
  font-family: 'Lora', serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-stone);
}

.pebbles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  padding: 1rem 1.25rem;
}

/* Pebble selector */
.pebble {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 1.2rem 0.75rem;
  background: var(--bg-surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid rgba(120, 113, 108, 0.18);
  border-radius: 45% 55% 50% 50% / 50% 45% 55% 50%;
  cursor: pointer;
  text-align: center;
  min-height: 120px;
  transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.2s ease, border-color 0.2s ease;
  font-family: 'Montserrat', sans-serif;
  opacity: 0;
  animation: pebbleIn 0.5s ease forwards;
}

.pebble:hover {
  transform: rotate(2deg) scale(1.04);
  box-shadow: var(--shadow-ambient);
}

.pebble.selected {
  background: var(--color-sage);
  border-color: var(--color-sage-dark);
  color: white;
  box-shadow: 0 8px 24px -6px rgba(163, 177, 138, 0.45);
}

.pebble.selected .pebble__count { color: rgba(255,255,255,0.75); }

.pebble__icon {
  font-size: 1.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pebble__icon svg {
  width: 1.75rem;
  height: 1.75rem;
}

.pebble.selected .pebble__icon svg {
  stroke: white;
}

.pebble__name {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.pebble__progress {
  margin-top: 0.35rem;
  width: 100%;
}
.pebble__progress-bar {
  height: 3px;
  background: rgba(120,113,108,0.15);
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 0.2rem;
}
.pebble__progress-fill {
  height: 100%;
  background: var(--color-sage-dark, #7a9160);
  border-radius: 9999px;
  transition: width 0.4s ease;
}
.pebble.selected .pebble__progress-bar { background: rgba(255,255,255,0.25); }
.pebble.selected .pebble__progress-fill { background: rgba(255,255,255,0.85); }
.pebble__progress-label {
  font-size: 0.62rem;
  opacity: 0.75;
}
.pebble__progress-label strong {
  font-weight: 700;
  opacity: 1;
}

.pebble__count {
  font-size: 0.68rem;
  font-weight: 400;
  opacity: 0.6;
  color: var(--color-stone);
}

@keyframes pebbleIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.topics-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: linear-gradient(to top, var(--bg-base) 70%, transparent);
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.btn-select-all {
  background: none;
  border: 1.5px solid rgba(120, 113, 108, 0.3);
  border-radius: var(--radius-pill);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--color-stone);
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}

.btn-select-all:hover {
  background: var(--color-parchment);
  border-color: rgba(120, 113, 108, 0.5);
}

.btn-start {
  flex: 1;
  max-width: 220px;
  background: var(--color-stone);
  color: white;
  border: none;
  border-radius: var(--radius-pill);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.8rem 1.75rem;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.btn-start:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-start:not(:disabled):hover { opacity: 0.85; }
.btn-start:not(:disabled):active { transform: scale(0.97); }

/* ===== QUESTION SCREEN ===== */
#screen-question {
  padding-bottom: 0;
}

.q-topbar {
  padding: 1rem 1.25rem 0;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-base);
}

.progress-track {
  display: flex;
  gap: 2px;
  height: 5px;
  overflow: hidden;
  margin-bottom: 0.6rem;
}

.progress-seg {
  flex: 1;
  height: 100%;
  border-radius: 2px;
  background: rgba(120, 113, 108, 0.18);
  transition: background 0.25s ease;
}
.progress-seg.correct { background: var(--color-sage); }
.progress-seg.wrong   { background: #D4856A; }
.progress-seg.current { background: rgba(120, 113, 108, 0.38); }

/* legacy, kept for safety */
.progress-fill {
  height: 100%;
  background: var(--color-sage);
  border-radius: var(--radius-pill);
  transition: width 0.4s ease;
  width: 0%;
}

.q-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.q-counter {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  opacity: 0.55;
}

.btn-exit {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--color-stone);
  opacity: 0.4;
  cursor: pointer;
  padding: 0.25rem 0.25rem;
  line-height: 1;
  transition: opacity 0.15s;
}

.btn-exit:hover { opacity: 0.75; }

.q-body {
  flex: 1;
  padding: 1.5rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
  overflow-y: auto;
  min-height: 0;
}

.question-card {
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(120, 113, 108, 0.15);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-ambient);
  padding: 2rem 1.75rem;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.question-card.fade-out {
  opacity: 0;
  transform: translateY(-12px);
}

.question-card.fade-in {
  animation: cardFadeIn 0.3s ease forwards;
}

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.question-text {
  font-family: 'Lora', serif;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  font-weight: 400;
  line-height: 1.65;
  color: var(--color-stone);
}

/* Static controls zone */
.q-controls {
  padding: 0.75rem 1.25rem max(1rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* Answer buttons */
.answers-bar {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
}

.next-bar {
  display: flex;
}

.btn-answer {
  width: 100%;
  min-height: 64px;
  border-radius: var(--radius-pill);
  font-family: 'Montserrat', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.btn-answer:active { transform: scale(0.96); }

.btn-istina {
  background: rgba(163, 177, 138, 0.12);
  border: 2px solid var(--color-sage);
  color: var(--color-stone);
}

.btn-lozh {
  background: rgba(188, 143, 143, 0.12);
  border: 2px solid var(--color-clay);
  color: var(--color-stone);
}

.btn-answer:disabled { cursor: default; }
.btn-answer:not(:disabled):hover { filter: brightness(0.96); }

.btn-answer.btn-correct {
  background: var(--color-sage);
  border-color: var(--color-sage-dark);
  color: white;
}

.btn-answer.btn-incorrect {
  background: var(--color-clay);
  border-color: var(--color-clay-dark);
  color: white;
}

.btn-answer.btn-correct-reveal {
  animation: pulseOutline 1.2s ease 2;
}

@keyframes pulseOutline {
  0%   { box-shadow: 0 0 0 0 rgba(163, 177, 138, 0.6); }
  50%  { box-shadow: 0 0 0 6px rgba(163, 177, 138, 0); }
  100% { box-shadow: 0 0 0 0 rgba(163, 177, 138, 0); }
}


/* ===== EXPLANATION BLOCK ===== */
.explanation-block {
  background: white;
  border-radius: 1.5rem;
  padding: 1.25rem 1.5rem 1.5rem;
  box-shadow: 0 4px 20px -6px rgba(120, 113, 108, 0.18);
  animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.explanation-block--correct {
  border-top: 3px solid var(--color-sage);
}

.explanation-block--incorrect {
  border-top: 3px solid var(--color-clay);
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.expl-verdict {
  display: block;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

.expl-verdict--correct { color: var(--color-sage-dark); }
.expl-verdict--incorrect { color: var(--color-clay-dark); }

.expl-text {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--color-stone);
  margin-bottom: 1.25rem;
}

.btn-next {
  width: 100%;
  min-height: 52px;
  border-radius: var(--radius-pill);
  background: var(--color-stone);
  color: white;
  border: none;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.btn-next:hover { opacity: 0.85; }
.btn-next:active { transform: scale(0.97); }

/* ===== RESULTS SCREEN ===== */
.results-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem 3rem;
  gap: 2rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.results-hero {
  text-align: center;
}

.results-pct-wrap {
  display: inline-flex;
  align-items: flex-start;
  line-height: 1;
  margin-bottom: 0.5rem;
}

.results-pct {
  font-family: 'Lora', serif;
  font-size: clamp(4rem, 16vw, 6rem);
  font-weight: 600;
  color: var(--color-stone);
  letter-spacing: -0.02em;
}

.results-pct-sign {
  font-family: 'Lora', serif;
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 400;
  color: var(--color-stone);
  opacity: 0.6;
  margin-top: 0.75rem;
  margin-left: 0.15rem;
}

.results-sub {
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0.6;
}

.results-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  width: 100%;
}

.topic-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-surface);
  border: 1px solid rgba(120, 113, 108, 0.2);
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 500;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.topic-badge__pct {
  font-weight: 600;
  color: var(--color-sage-dark);
}

.topic-badge--low .topic-badge__pct {
  color: var(--color-clay-dark);
}

.results-actions {
  display: flex;
  gap: 0.75rem;
  width: 100%;
}

/* Pebble progress rings */
.pebble--great { border-color: var(--color-sage) !important; border-width: 2.5px !important; }
.pebble--ok    { border-color: #C9B84C !important; border-width: 2.5px !important; }
.pebble--low   { border-color: #D4856A !important; border-width: 2.5px !important; }

/* "Выбрать другую тему" button */
.btn-topics {
  flex: 1;
  min-height: 52px;
  border-radius: var(--radius-pill);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease;
  background: none;
  color: var(--color-stone);
  border: 1.5px solid rgba(120, 113, 108, 0.35);
}
.btn-topics:hover { opacity: 0.8; }
.btn-topics:active { transform: scale(0.97); }

.btn-repeat, .btn-home {
  flex: 1;
  min-height: 52px;
  border-radius: var(--radius-pill);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.btn-repeat {
  background: var(--color-stone);
  color: white;
  border: none;
}

.btn-home {
  background: none;
  color: var(--color-stone);
  border: 1.5px solid rgba(120, 113, 108, 0.35);
}

.btn-repeat:hover, .btn-home:hover { opacity: 0.8; }
.btn-repeat:active, .btn-home:active { transform: scale(0.97); }

.btn-key {
  display: inline-block;
  font-size: 0.75rem;
  opacity: 0.5;
  font-weight: 400;
  letter-spacing: 0;
}

.btn-answer.btn-correct .btn-key,
.btn-answer.btn-incorrect .btn-key {
  opacity: 0.6;
}

/* ===== UTILITY ===== */
button { font-family: inherit; }
