:root {
  --bg-top: #f2f7f5;
  --bg-bottom: #dfe9e6;
  --surface: #ffffff;
  --surface-soft: #f7fbf9;
  --ink: #18231f;
  --ink-muted: #51605a;
  --accent: #006d5b;
  --accent-soft: #daf4ec;
  --danger: #b42318;
  --danger-soft: #fde8e7;
  --ok: #0f7a4a;
  --ok-soft: #e0f5ea;
  --line: #d2ddd8;
  --shadow: 0 12px 30px rgba(24, 35, 31, 0.12);
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 8%, rgba(0, 109, 91, 0.16), transparent 32%),
    radial-gradient(circle at 12% 92%, rgba(199, 107, 0, 0.14), transparent 28%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 18px 28px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  animation: rise-in 0.4s ease-out;
}

.top-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.quick-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.mini-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.88rem;
}

.mini-stat strong {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.06rem;
}

.mini-stat.bad {
  background: var(--danger-soft);
  border-color: #f3c8c5;
}

.settings-dropdown {
  position: relative;
  margin-left: auto;
}

.settings-dropdown > summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.9rem;
  user-select: none;
}

.settings-dropdown > summary::-webkit-details-marker {
  display: none;
}

.settings-dropdown[open] > summary {
  border-color: var(--accent);
}

.settings-content {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 5;
  width: min(760px, calc(100vw - 50px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
  display: grid;
  gap: 12px;
}

.title-wrap h1 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.6rem, 2.8vw, 2.4rem);
  line-height: 1.1;
}

.title-wrap p {
  margin: 8px 0 0;
  color: var(--ink-muted);
  max-width: 680px;
}

.stats-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  min-width: 128px;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: 2px;
}

.stat-card .value {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: "Space Grotesk", sans-serif;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  animation: rise-in 0.45s ease-out;
}

.pill-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-btn {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.92rem;
}

.pill-btn:hover {
  border-color: var(--accent);
}

.pill-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.stack-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.cheat h2,
.trainer h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.cheat p {
  margin-top: 0;
  color: var(--ink-muted);
}

.cheat-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.cheat table {
  width: 100%;
  min-width: 690px;
  border-collapse: collapse;
  font-size: 0.82rem;
  table-layout: fixed;
}

.cheat th,
.cheat td {
  border: 1px solid var(--line);
  padding: 9px 8px;
  vertical-align: top;
  word-break: break-word;
}

.cheat th {
  background: var(--surface-soft);
  font-family: "Space Grotesk", sans-serif;
  text-align: left;
}

.cheat .note {
  margin-top: 10px;
  font-size: 0.86rem;
  color: var(--ink-muted);
}

.cheat-spoiler,
.hint-spoiler,
.exceptions-spoiler {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.cheat-spoiler > summary,
.hint-spoiler > summary,
.exceptions-spoiler > summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 12px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
}

.cheat-spoiler > summary::-webkit-details-marker,
.hint-spoiler > summary::-webkit-details-marker,
.exceptions-spoiler > summary::-webkit-details-marker {
  display: none;
}

.cheat-spoiler-content,
.hint-content {
  border-top: 1px solid var(--line);
  padding: 10px 10px 2px;
}

.mobile-cheat {
  display: none;
}

.trainer .sentence {
  font-size: clamp(1rem, 1.3vw, 1.2rem);
  line-height: 1.45;
  background: var(--surface-soft);
  border: 1px dashed #b7cbc3;
  border-radius: var(--radius-md);
  padding: 13px;
  margin-bottom: 14px;
}

.blank {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-width: 110px;
  border-bottom: 2px solid #879f96;
  margin: 0 4px;
  font-weight: 700;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0.02em;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.block-label {
  font-size: 0.82rem;
  color: var(--ink-muted);
  margin-bottom: 7px;
}

.option-grid {
  display: grid;
  gap: 7px;
}

.option-btn {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
}

.option-btn:hover {
  border-color: #87a79c;
}

.option-btn.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.text-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 1rem;
  background: #fff;
}

.text-input:focus {
  outline: 2px solid #84b9aa;
  border-color: var(--accent);
}

.action-row {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 13px;
  cursor: pointer;
  font-size: 0.94rem;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.secondary {
  background: var(--surface-soft);
  border-color: var(--line);
}

.btn.primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.feedback {
  margin-top: 12px;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.93rem;
}

.feedback.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.feedback.bad {
  background: var(--danger-soft);
  color: var(--danger);
}

.meta-row {
  margin-top: 8px;
  color: var(--ink-muted);
  font-size: 0.86rem;
}

.hint-spoiler {
  margin: 10px 0 12px;
}

.hint-content .meta-row:first-child {
  margin-top: 0;
}

.exception-note ul,
.exceptions-spoiler ul {
  margin: 6px 0 10px 18px;
  padding: 0;
  color: var(--ink-muted);
  font-size: 0.88rem;
}

.exceptions-spoiler {
  margin-top: 10px;
}

@keyframes rise-in {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 940px) {
  .settings-content {
    width: min(720px, calc(100vw - 42px));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px 10px 22px;
  }

  .top-strip {
    flex-wrap: wrap;
    align-items: stretch;
  }

  .settings-dropdown {
    width: 100%;
    margin-left: 0;
  }

  .settings-dropdown > summary {
    width: 100%;
    text-align: center;
  }

  .settings-content {
    position: static;
    width: 100%;
    margin-top: 8px;
  }

  .stats-bar {
    width: 100%;
  }

  .stat-card {
    min-width: calc(50% - 8px);
    flex: 1;
  }

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

  .cheat-table-wrap {
    display: none;
  }

  .mobile-cheat {
    display: block;
    font-size: 0.9rem;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
  }
}
