:root {
  --bg: #f7f0df;
  --surface: rgba(255, 249, 237, 0.82);
  --surface-strong: rgba(255, 252, 246, 0.94);
  --ink: #1d2a3a;
  --muted: #5b6470;
  --line: rgba(29, 42, 58, 0.12);
  --accent: #0e7c7b;
  --accent-soft: #dff2ee;
  --accent-warm: #f28c52;
  --danger: #bb4d39;
  --success: #157f57;
  --shadow: 0 22px 80px rgba(29, 42, 58, 0.14);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 999px;
  --app-height: 100vh;
  --app-stable-height: 100vh;
  --safe-area-top: 0px;
  --safe-area-right: 0px;
  --safe-area-bottom: 0px;
  --safe-area-left: 0px;
  --tg-page-bg: #fbf5e8;
  --tg-surface-bg: #fff9ed;
  --tg-text: #1d2a3a;
  --tg-hint: #5b6470;
  --tg-button: #0e7c7b;
  --tg-button-text: #ffffff;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  background: var(--tg-page-bg);
}

html[data-color-scheme="dark"] {
  color-scheme: dark;
  --bg: #152231;
  --surface: rgba(14, 24, 36, 0.82);
  --surface-strong: rgba(19, 31, 46, 0.94);
  --ink: #edf3f9;
  --muted: #a9b7c6;
  --line: rgba(255, 255, 255, 0.1);
  --shadow: 0 24px 90px rgba(0, 0, 0, 0.34);
}

body {
  margin: 0;
  min-height: var(--app-height);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  padding:
    max(12px, var(--safe-area-top))
    max(12px, var(--safe-area-right))
    max(18px, var(--safe-area-bottom))
    max(12px, var(--safe-area-left));
  background:
    radial-gradient(circle at top left, rgba(242, 140, 82, 0.28), transparent 34%),
    radial-gradient(circle at 85% 18%, rgba(14, 124, 123, 0.18), transparent 24%),
    linear-gradient(180deg, #fbf5e8 0%, #f7efd9 52%, #efe3c8 100%);
  overflow-x: hidden;
}

html[data-color-scheme="dark"] body {
  background:
    radial-gradient(circle at top left, rgba(242, 140, 82, 0.18), transparent 34%),
    radial-gradient(circle at 85% 18%, rgba(14, 124, 123, 0.18), transparent 24%),
    linear-gradient(180deg, #102030 0%, #132433 52%, #0c1722 100%);
}

button {
  font: inherit;
}

.noise,
.orb {
  pointer-events: none;
  position: fixed;
  inset: auto;
  z-index: 0;
}

.noise {
  inset: 0;
  opacity: 0.25;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='none' stroke='rgba(0,0,0,0.06)' stroke-width='1'%3E%3Cpath d='M0 45h180M0 135h180M45 0v180M135 0v180'/%3E%3C/g%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

html[data-color-scheme="dark"] .noise {
  opacity: 0.16;
}

.orb {
  width: 34rem;
  height: 34rem;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.35;
  animation: drift 18s ease-in-out infinite;
}

.orb-a {
  top: -8rem;
  right: -10rem;
  background: rgba(14, 124, 123, 0.24);
}

.orb-b {
  bottom: -12rem;
  left: -10rem;
  background: rgba(242, 140, 82, 0.22);
  animation-delay: -6s;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, 100%);
  min-height: calc(var(--app-stable-height) - var(--safe-area-top) - var(--safe-area-bottom));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.hero {
  padding: 18px 10px 22px;
}

.hero-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.eyebrow,
.telegram-pill,
.panel-label,
.group-title,
.answer-label,
.card-kicker,
.collection-group-title {
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.eyebrow,
.telegram-pill {
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 252, 246, 0.72);
  border: 1px solid rgba(29, 42, 58, 0.08);
  backdrop-filter: blur(10px);
}

html[data-color-scheme="dark"] .eyebrow,
html[data-color-scheme="dark"] .telegram-pill {
  background: rgba(19, 31, 46, 0.78);
  border-color: rgba(255, 255, 255, 0.08);
}

.telegram-pill.is-live {
  background: rgba(14, 124, 123, 0.13);
  color: var(--accent);
}

.hero h1 {
  max-width: 15ch;
  margin: 0 0 14px;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(2.2rem, 7vw, 4.7rem);
  line-height: 0.92;
  letter-spacing: -0.04em;
}

.hero-copy {
  max-width: 62ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 1.02rem;
}

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.panel {
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

html[data-color-scheme="dark"] .panel {
  border-color: rgba(255, 255, 255, 0.08);
}

.control-panel {
  padding: 22px;
}

.study-panel {
  padding: 24px;
}

.panel-head,
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.panel-head strong,
.card-header strong {
  display: block;
  font-size: 1.05rem;
}

.collection-caption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 1.55rem;
}

.control-group + .control-group {
  margin-top: 18px;
}

.group-title,
.collection-group-title {
  margin-bottom: 10px;
  color: var(--muted);
}

.chip-row,
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.collection-groups {
  display: grid;
  gap: 14px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.collection-group {
  display: grid;
  gap: 8px;
}

.collection-stack {
  display: grid;
  gap: 8px;
}

.collection-button,
.chip-button,
.segment-button,
.ghost-button,
.primary-button,
.rating-button {
  border: 0;
  cursor: pointer;
  transition:
    transform 180ms ease,
    background-color 180ms ease,
    color 180ms ease,
    opacity 180ms ease,
    box-shadow 180ms ease;
}

.collection-button {
  width: 100%;
  padding: 12px 14px;
  border-radius: 18px;
  text-align: left;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

html[data-color-scheme="dark"] .collection-button,
html[data-color-scheme="dark"] .chip-button,
html[data-color-scheme="dark"] .segment-button,
html[data-color-scheme="dark"] .ghost-button {
  background: rgba(14, 24, 36, 0.82);
}

.collection-button strong {
  display: block;
  font-size: 0.98rem;
  line-height: 1.25;
}

.collection-button span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.collection-button.is-active {
  background: linear-gradient(135deg, rgba(14, 124, 123, 0.96), rgba(36, 144, 137, 0.94));
  color: white;
  box-shadow: 0 14px 28px rgba(14, 124, 123, 0.24);
}

.collection-button.is-active span {
  color: rgba(255, 255, 255, 0.82);
}

.chip-button,
.segment-button {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--line);
  color: var(--ink);
}

.chip-button.is-active,
.segment-button.is-active {
  background: var(--tg-button);
  color: var(--tg-button-text);
  box-shadow: 0 10px 24px rgba(14, 124, 123, 0.22);
}

.up-next {
  display: grid;
  gap: 10px;
}

.up-next-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.up-next-card strong {
  display: block;
  font-size: 1rem;
}

.up-next-card span {
  color: var(--muted);
  font-size: 0.88rem;
}

.flashcard {
  width: 100%;
  min-height: 410px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  perspective: 1200px;
}

.flashcard-inner {
  position: relative;
  min-height: 410px;
  border-radius: calc(var(--radius-xl) + 4px);
  transform-style: preserve-3d;
  transition: transform 500ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.flashcard.is-revealed .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: calc(var(--radius-xl) + 4px);
  padding: 28px;
  backface-visibility: hidden;
  overflow: hidden;
}

.flashcard-face::before {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.flashcard-front {
  background:
    radial-gradient(circle at top right, rgba(14, 124, 123, 0.25), transparent 35%),
    linear-gradient(145deg, #1f3042 0%, #0b5962 52%, #f28c52 160%);
  color: white;
  box-shadow: 0 30px 90px rgba(20, 32, 44, 0.28);
}

.flashcard-back {
  background:
    radial-gradient(circle at top left, rgba(242, 140, 82, 0.2), transparent 40%),
    linear-gradient(180deg, rgba(255, 251, 245, 0.98), rgba(248, 242, 231, 0.96));
  color: var(--ink);
  transform: rotateY(180deg);
  border: 1px solid rgba(29, 42, 58, 0.08);
  box-shadow: 0 24px 70px rgba(29, 42, 58, 0.12);
}

html[data-color-scheme="dark"] .flashcard-back {
  background:
    radial-gradient(circle at top left, rgba(242, 140, 82, 0.14), transparent 40%),
    linear-gradient(180deg, rgba(16, 27, 40, 0.98), rgba(21, 34, 50, 0.96));
  border-color: rgba(255, 255, 255, 0.08);
}

.front-word {
  margin-top: auto;
  max-width: 12ch;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(2.5rem, 8vw, 4.7rem);
  line-height: 0.96;
  letter-spacing: -0.05em;
}

.front-subline,
.hint-line,
.answer-foot {
  color: rgba(255, 255, 255, 0.78);
}

.flashcard-back .answer-foot,
.flashcard-back .answer-label {
  color: var(--muted);
}

.answer-grid {
  display: grid;
  gap: 18px;
  margin-top: auto;
}

.answer-grid strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.08rem, 3vw, 1.4rem);
  line-height: 1.3;
}

.answer-example {
  padding-top: 4px;
  border-top: 1px solid rgba(29, 42, 58, 0.08);
}

.answer-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.92rem;
}

.hint-line {
  min-height: 24px;
  margin: 14px 2px 0;
  color: var(--muted);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.primary-button,
.ghost-button,
.rating-button {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
}

.primary-button {
  background: var(--tg-button);
  color: var(--tg-button-text);
  box-shadow: 0 12px 26px rgba(14, 124, 123, 0.25);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  border: 1px solid var(--line);
}

.rating-row .rating-button {
  flex: 1 1 160px;
  font-weight: 600;
}

.rating-button.is-danger {
  background: rgba(187, 77, 57, 0.12);
  color: var(--danger);
}

.rating-button.is-neutral {
  background: rgba(29, 42, 58, 0.09);
  color: var(--ink);
}

.rating-button.is-success {
  background: rgba(21, 127, 87, 0.13);
  color: var(--success);
}

.rating-button:disabled,
.ghost-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  box-shadow: none;
}

.collection-button:hover,
.chip-button:hover,
.segment-button:hover,
.ghost-button:hover,
.primary-button:hover,
.rating-button:hover,
.flashcard:hover {
  transform: translateY(-1px);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    order: 2;
  }

  .study-panel {
    order: 1;
  }

  .collection-groups {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: 100%;
    padding-top: 12px;
    padding-bottom: max(28px, var(--safe-area-bottom));
  }

  .hero {
    padding-inline: 4px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .study-panel,
  .control-panel {
    padding: 18px;
  }

  .flashcard,
  .flashcard-inner {
    min-height: 380px;
  }

  .flashcard-face {
    padding: 22px;
  }

  .hero-topline {
    align-items: flex-start;
    flex-direction: column;
  }
}

@keyframes drift {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(14px, -10px, 0) scale(1.05);
  }
}
