:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #625e58;
  --paper: #fff8ed;
  --panel: #ffffff;
  --line: #ddd1bf;
  --accent: #d8432e;
  --accent-strong: #b72f20;
  --green: #23865b;
  --blue: #256d9d;
  --amber: #f4c542;
  --shadow: 0 22px 50px rgba(39, 30, 20, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(216, 67, 46, 0.1), transparent 28%),
    linear-gradient(315deg, rgba(37, 109, 157, 0.12), transparent 30%),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

input,
select,
textarea {
  font-size: 16px;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

.auth-screen,
.app-shell {
  height: 100dvh;
  min-height: 560px;
  padding:
    calc(18px + var(--safe-top))
    calc(18px + var(--safe-right))
    calc(18px + var(--safe-bottom))
    calc(18px + var(--safe-left));
}

.auth-screen {
  display: grid;
  place-items: center;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(330px, 0.75fr);
  gap: clamp(18px, 4vw, 40px);
  width: min(1040px, 100%);
  max-height: 100%;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
}

.brand img {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}

.auth-copy {
  display: grid;
  gap: 16px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(2.7rem, 7vw, 6.4rem);
  line-height: 0.88;
  letter-spacing: 0;
}

.auth-copy p:not(.eyebrow) {
  max-width: 600px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.3vw, 1.15rem);
  line-height: 1.55;
}

.preview-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.preview-strip span {
  min-width: 104px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  font-size: 1.1rem;
  font-weight: 900;
  text-align: center;
}

.account-card {
  display: grid;
  gap: 18px;
  width: 100%;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5ecdf;
}

.auth-tab,
.view-tab,
.ghost-button,
.primary-action,
.sound-button,
.choice-button,
.match-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.auth-tab {
  min-height: 42px;
  border-color: transparent;
  background: transparent;
  font-weight: 900;
}

.auth-tab.active {
  border-color: var(--line);
  background: white;
}

.account-form {
  display: grid;
  gap: 14px;
}

.field-group,
.control-group {
  display: grid;
  gap: 6px;
}

label,
.stats span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(37, 109, 157, 0.25);
  outline-offset: 2px;
}

.primary-action,
.ghost-button,
.sound-button {
  min-height: 42px;
  padding: 0 15px;
  font-weight: 900;
}

.primary-action {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.full-width {
  width: 100%;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.76);
}

.primary-action:hover,
.ghost-button:hover,
.sound-button:hover,
.choice-button:hover,
.match-card:hover,
.auth-tab:hover {
  transform: translateY(-1px);
}

.form-note {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.form-note.error {
  color: var(--accent-strong);
  font-weight: 850;
}

.form-note.good {
  color: var(--green);
  font-weight: 850;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.app-topbar {
  display: grid;
  grid-template-columns: auto minmax(240px, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 46px;
}

.view-tabs {
  display: flex;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.view-tab {
  min-height: 36px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.9rem;
  font-weight: 900;
}

.view-tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.user-area {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.user-pill {
  max-width: 180px;
  min-height: 36px;
  padding: 8px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  font-size: 0.9rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.panel-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.panel-heading,
.friend-search {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
}

.panel-heading h2 {
  margin: 4px 0 0;
  font-size: clamp(1.5rem, 4vw, 2.6rem);
  line-height: 1;
}

.toolbar,
.stats,
.game-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(140px, 0.8fr) auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
}

.play-board {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.stats {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  min-height: 0;
}

.stats div {
  display: grid;
  gap: 5px;
  min-height: 0;
  align-content: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.stats div:last-child {
  border-bottom: 0;
}

.stats strong {
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1;
}

.game-stage {
  display: grid;
  min-height: 0;
  overflow: hidden;
  padding: clamp(14px, 2.5vw, 28px);
}

.question-card,
.matching-card,
.round-complete {
  display: grid;
  min-height: 0;
}

.question-card {
  grid-template-rows: minmax(0, 0.95fr) auto auto;
  gap: 14px;
}

.prompt-area {
  display: grid;
  gap: 10px;
  min-height: 0;
  align-content: center;
  justify-items: center;
  text-align: center;
}

.prompt-label {
  color: var(--muted);
  font-weight: 850;
}

.russian-word {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(3.1rem, 10vw, 7.2rem);
  font-weight: 950;
  line-height: 0.95;
}

.translation-word {
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  font-weight: 850;
}

.sound-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  justify-content: center;
}

.sound-button svg {
  width: 19px;
  height: 19px;
}

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

.choice-button {
  min-height: clamp(58px, 9vh, 82px);
  padding: 12px;
  overflow-wrap: anywhere;
  font-size: clamp(1rem, 2.5vw, 1.28rem);
  font-weight: 900;
}

.choice-button.correct,
.match-card.matched {
  border-color: rgba(35, 134, 91, 0.42);
  background: rgba(35, 134, 91, 0.13);
}

.choice-button.wrong,
.match-card.wrong {
  border-color: rgba(216, 67, 46, 0.44);
  background: rgba(216, 67, 46, 0.12);
}

.feedback {
  min-height: 24px;
  text-align: center;
  font-weight: 900;
}

.feedback.good {
  color: var(--green);
}

.feedback.bad {
  color: var(--accent-strong);
}

.matching-card {
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
}

.matching-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-height: 0;
}

.match-column {
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
}

.match-card {
  min-height: 0;
  padding: 10px;
  overflow: hidden;
  font-size: clamp(0.95rem, 2.2vw, 1.16rem);
  font-weight: 900;
  text-overflow: ellipsis;
}

.match-card.selected {
  border-color: var(--blue);
  background: rgba(37, 109, 157, 0.13);
}

.round-complete {
  place-items: center;
  text-align: center;
}

.round-complete h2 {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 4.5rem);
  line-height: 1;
}

.round-complete p {
  max-width: 520px;
  color: var(--muted);
  line-height: 1.5;
}

.dashboard-grid,
.friends-grid {
  display: grid;
  min-height: 0;
  gap: 12px;
}

.dashboard-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(88px, auto);
  overflow: hidden;
}

.friends-grid {
  grid-template-rows: auto minmax(0, 1fr);
}

.friends-stage {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.metric-card,
.list-card,
.mini-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
}

.metric-card {
  display: grid;
  gap: 8px;
  align-content: center;
  padding: 14px;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1;
}

.list-card,
.mini-card {
  padding: 14px;
  overflow: hidden;
}

.list-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.list-card.wide {
  grid-column: span 2;
}

.list-card h3 {
  margin: 0;
  font-size: 1rem;
}

.list-card ul {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.list-card li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f6efe2;
  font-weight: 850;
}

.list-card li span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-card li strong {
  flex: 0 0 auto;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: min(520px, 100%);
}

.compact {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.86rem;
}

@media (max-width: 780px) {
  .auth-screen,
  .app-shell {
    min-height: 100dvh;
    padding:
      calc(10px + var(--safe-top))
      calc(10px + var(--safe-right))
      calc(10px + var(--safe-bottom))
      calc(10px + var(--safe-left));
  }

  .auth-panel {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .auth-copy {
    gap: 10px;
  }

  .auth-copy p:not(.eyebrow) {
    font-size: 0.96rem;
  }

  .preview-strip {
    display: none;
  }

  .account-card {
    padding: 14px;
  }

  .brand span {
    font-size: 0.95rem;
  }

  .app-topbar {
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .view-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: stretch;
  }

  .view-tab {
    flex: 1;
  }

  .user-area {
    flex-wrap: wrap;
  }

  .user-pill {
    max-width: 120px;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
    padding: 10px;
  }

  .toolbar .primary-action {
    grid-column: 1 / -1;
  }

  .play-board {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto;
  }

  .stats div {
    min-height: 56px;
    padding: 9px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .stats div:last-child {
    border-right: 0;
  }

  .game-stage {
    padding: 12px;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .friends-stage {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: clamp(2.25rem, 13vw, 3.6rem);
  }

  .app-shell {
    gap: 8px;
  }

  .app-topbar {
    min-height: 42px;
  }

  .brand img {
    width: 30px;
    height: 30px;
  }

  .ghost-button {
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.85rem;
  }

  .toolbar {
    gap: 8px;
  }

  .panel-heading,
  .friend-search {
    align-items: stretch;
    flex-direction: column;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric-card {
    padding: 10px;
  }

  .metric-card strong {
    font-size: 1.55rem;
  }

  .list-card {
    padding: 10px;
  }

  .list-card.wide {
    grid-column: span 2;
  }

  input,
  select {
    min-height: 40px;
    padding: 0 9px;
  }

  label,
  .stats span {
    font-size: 0.68rem;
  }

  .stats strong {
    font-size: 1.12rem;
  }

  .question-card {
    gap: 10px;
  }

  .choices-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .choice-button {
    min-height: clamp(50px, 7.5vh, 64px);
  }
}
