:root {
  --background: #f5f5f5;
  --surface: #ffffff;
  --text: #171717;
  --muted: #737373;
  --border: #dedede;
  --green: #16784b;
  --green-soft: #e7f5ed;
  --red: #bd3434;
  --red-soft: #fbeaea;
  --theory-surface: #fbf8f0;
  --theory-border: #d8d2c3;
  --theory-text: #414141;
  --theory-accent: #806f45;
  --theory-rule: #e3dece;
  --button-text: #ffffff;
  --button-hover: #333333;
  --focus: #6aa9ff;
}

:root[data-theme="dark"] {
  --background: #121212;
  --surface: #1d1d1d;
  --text: #f2f2f2;
  --muted: #aaaaaa;
  --border: #393939;
  --green: #74c69d;
  --green-soft: #20372b;
  --red: #ff8b8b;
  --red-soft: #482525;
  --theory-surface: #22201c;
  --theory-border: #49453d;
  --theory-text: #dfddd8;
  --theory-accent: #d0bd7f;
  --theory-rule: #49453d;
  --button-text: #121212;
  --button-hover: #d9d9d9;
  --focus: #8bb9ff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --background: #121212;
    --surface: #1d1d1d;
    --text: #f2f2f2;
    --muted: #aaaaaa;
    --border: #393939;
  }
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scrollbar-gutter: stable;
}

body {
  min-height: 100svh;
  margin: 0;
  padding: clamp(24px, 6vw, 56px) clamp(16px, 5vw, 32px);
  color: var(--text);
  background: var(--background);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main {
  width: min(100%, 520px);
  margin: 0 auto;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
}

.page-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 14px;
}

.page-header h1 {
  grid-column: 2;
}

.settings-link {
  grid-column: 1;
  justify-self: start;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
  text-underline-offset: 3px;
}

.theme-toggle {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  grid-column: 3;
  justify-self: end;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--text);
  color: var(--text);
}

.theme-toggle-icon {
  font-size: 1rem;
  line-height: 1;
}

.exercise-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 28px;
  margin-bottom: 10px;
}

.topics-link,
.review-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--text);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  background: var(--surface);
}

.topics-link:hover,
.review-link:hover {
  color: var(--button-text);
  background: var(--text);
}

.topic-context {
  min-height: 19px;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px 12px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.google-sign-in {
  display: inline-flex;
  width: fit-content;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.google-sign-in:hover,
.auth-sign-out:hover {
  border-color: var(--text);
}

.google-sign-in:disabled {
  cursor: wait;
  opacity: 0.65;
}

.google-mark {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #4285f4;
  font-size: 0.72rem;
  font-weight: 800;
}

.auth-user {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.auth-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
}

.auth-name {
  overflow: hidden;
  font-size: 0.84rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-statistics,
.auth-status {
  color: var(--muted);
  font-size: 0.72rem;
}

.auth-statistics {
  grid-column: 1;
}

.auth-status {
  grid-column: 1 / -1;
}

.auth-sign-out {
  grid-column: 2;
  grid-row: 1;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.learning-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.learning-summary-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.learning-summary-label,
.learning-summary-note {
  color: var(--muted);
  font-size: 0.75rem;
}

.progress-summary-link {
  grid-column: 1 / -1;
  justify-self: end;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
  text-underline-offset: 3px;
}

.daily-goal-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.daily-goal-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 180ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .daily-goal-track span {
    transition: none;
  }
}

.level-selector {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  margin-bottom: 14px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.level-button {
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.level-button:not(:disabled):not([aria-pressed="true"]):hover {
  color: var(--text);
  background: var(--background);
}

.level-button[aria-pressed="true"] {
  color: var(--text);
  background: var(--background);
}

.level-button:disabled {
  cursor: default;
  opacity: 0.6;
}

.card {
  padding: clamp(18px, 5vw, 28px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.meta {
  height: 20px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.theory {
  margin: 0 0 22px;
  overflow: hidden;
  border: 1px solid var(--theory-border);
  border-radius: 13px;
  background: var(--theory-surface);
}

.theory-toggle {
  display: flex;
  width: 100%;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.theory-kicker,
.theory-title {
  display: block;
}

.theory-kicker {
  margin-bottom: 3px;
  color: var(--theory-accent);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.theory-title {
  font-size: 1rem;
  font-weight: 750;
}

.theory-toggle-label {
  flex: none;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 650;
}

.theory-content {
  padding: 0 16px 16px;
}

.theory-summary {
  margin: 0;
  font-size: 0.93rem;
  font-weight: 650;
  line-height: 1.5;
}

.theory-rules {
  display: grid;
  gap: 6px;
  margin: 13px 0 0;
  padding-left: 20px;
  color: var(--theory-text);
  font-size: 0.86rem;
  line-height: 1.45;
}

.theory-examples {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 14px;
}

.theory-examples span {
  padding: 8px 10px;
  border: 1px solid var(--theory-rule);
  border-radius: 8px;
  background: var(--surface);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 650;
}

.theory-tip {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--theory-rule);
  color: var(--theory-accent);
  font-size: 0.8rem;
  line-height: 1.45;
}

h2 {
  min-height: 88px;
  margin: 0 0 16px;
  font-size: clamp(1.3rem, 4.5vw, 1.75rem);
  line-height: 1.3;
}

.empty-practice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 2px 2px 0;
  color: var(--muted);
}

.session-result {
  padding: 14px 0 2px;
  text-align: center;
}

.session-result-mark {
  display: grid;
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  place-items: center;
  border: 2px solid var(--text);
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: 800;
}

.session-result.perfect .session-result-mark {
  border-color: var(--green);
  color: var(--button-text);
  background: var(--green);
  font-size: 2rem;
}

.session-result h2 {
  min-height: 0;
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.session-result p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.retry-button {
  width: 100%;
  height: 48px;
  border: 1px solid var(--text);
  border-radius: 10px;
  color: #fff;
  background: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.retry-button:hover {
  background: var(--button-hover);
}

.empty-practice-mark {
  display: grid;
  width: 28px;
  height: 28px;
  flex: none;
  place-items: center;
  border: 1px dashed #b9b9b9;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
}

.empty-practice strong {
  color: var(--text);
  font-size: 0.86rem;
}

.empty-practice p {
  margin: 4px 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
}

.options {
  display: grid;
  gap: 10px;
}

.option,
.next {
  width: 100%;
  height: 60px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
}

.option:not(:disabled):hover {
  border-color: var(--text);
}

.option.correct {
  border-color: var(--green);
  background: var(--green-soft);
}

.option.wrong {
  border-color: var(--red);
  background: var(--red-soft);
}

.option:disabled {
  color: var(--text);
  cursor: default;
}

.next {
  height: 48px;
  margin-top: 10px;
  border-color: var(--text);
  color: var(--button-text);
  background: var(--text);
  text-align: center;
  visibility: hidden;
  pointer-events: none;
}

.next.visible {
  visibility: visible;
  pointer-events: auto;
}

.next:hover {
  background: var(--button-hover);
}

.translation {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.translation-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.translation-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.translation select,
.translate-button {
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
}

.translation select {
  min-width: 0;
  padding: 0 34px 0 12px;
}

.translate-button {
  padding: 0 16px;
  cursor: pointer;
}

.translate-button:not(:disabled):hover {
  border-color: var(--text);
}

.translate-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.translation-status {
  min-height: 18px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.error {
  margin: 0;
  color: var(--red);
}

[hidden] {
  display: none !important;
}

.site-footer {
  padding: 18px 0 2px;
  text-align: center;
}

.site-footer a {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 390px) {
  .translation-controls {
    grid-template-columns: 1fr;
  }

  .translate-button {
    width: 100%;
  }
}
