:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #eef5f0;
  --ink: #1d2528;
  --muted: #677277;
  --line: #dbe2e5;
  --teal: #087f8c;
  --teal-dark: #065b63;
  --coral: #d65f42;
  --amber: #f2b84b;
  --mint: #dceee7;
  --shadow: 0 18px 45px rgba(34, 45, 48, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(8, 127, 140, 0.12), transparent 31rem),
    linear-gradient(135deg, #f6f7f9 0%, #edf3f1 42%, #f9f5ef 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  font-size: 1.35rem;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand small {
  color: var(--muted);
  margin-top: 3px;
}

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

.user-chip {
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.9rem;
}

main {
  flex: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.login-view {
  min-height: calc(100vh - 150px);
  display: grid;
  align-items: center;
}

.login-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 28px;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(219, 226, 229, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-copy {
  padding: clamp(28px, 5vw, 58px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-copy h1 {
  max-width: 11ch;
  margin: 0 0 28px;
  font-size: clamp(2.4rem, 7vw, 5.8rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.login-art {
  width: 100%;
  height: 100%;
  min-height: 390px;
  object-fit: cover;
  background: var(--mint);
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--coral);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-form,
.answer-form,
.crypto-form {
  display: grid;
  gap: 10px;
}

label {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 750;
}

.inline-field {
  display: flex;
  gap: 10px;
  align-items: center;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 140, 0.15);
}

input[readonly] {
  background: var(--surface-muted);
  color: var(--teal-dark);
  font-weight: 750;
}

.primary,
.secondary,
.ghost,
.icon-button,
.tab {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.primary {
  background: var(--teal);
  color: white;
  padding: 0 18px;
  font-weight: 800;
}

.primary:hover {
  background: var(--teal-dark);
}

.secondary {
  background: var(--mint);
  color: var(--teal-dark);
  padding: 0 16px;
  font-weight: 800;
}

.ghost {
  background: rgba(255, 255, 255, 0.68);
  border-color: var(--line);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 750;
}

.ghost.small {
  min-height: 30px;
  padding: 0 9px;
  border-radius: 6px;
  font-size: 0.78rem;
}

.icon-button {
  width: 38px;
  height: 38px;
  background: white;
  border-color: var(--line);
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
}

.practice-grid,
.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 18px;
  align-items: start;
}

.problem-card,
.progress-panel,
.admin-panel,
.admin-note {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(219, 226, 229, 0.95);
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(34, 45, 48, 0.08);
}

.problem-card,
.admin-panel {
  padding: clamp(20px, 4vw, 34px);
}

.progress-panel,
.admin-note {
  padding: 20px;
}

.card-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 22px;
}

.card-heading.compact {
  align-items: center;
  margin-bottom: 16px;
}

h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.25rem, 3vw, 2rem);
}

h3 {
  font-size: 1.25rem;
  line-height: 1.25;
}

.problem-display {
  min-height: 160px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(8, 127, 140, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(8, 127, 140, 0.05) 1px, transparent 1px),
    #fbfdfc;
  background-size: 22px 22px;
  color: var(--ink);
  font-size: clamp(1.8rem, 6vw, 4.8rem);
  font-weight: 850;
  line-height: 1.05;
  text-align: center;
  overflow-wrap: anywhere;
  padding: 24px;
  margin-bottom: 22px;
}

.feedback {
  min-height: 50px;
  margin-top: 14px;
  padding: 13px 14px;
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--muted);
  line-height: 1.4;
}

.feedback.correct {
  background: #e4f5e8;
  color: #246338;
}

.feedback.incorrect {
  background: #fff0eb;
  color: #9c3e25;
}

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

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

.stats-grid div {
  min-height: 88px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfcfd;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stats-grid span {
  font-size: 1.8rem;
  line-height: 1;
  font-weight: 850;
  color: var(--teal-dark);
}

.stats-grid small,
.history-item small {
  color: var(--muted);
  margin-top: 5px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.history-item strong {
  display: block;
}

.history-badge {
  min-width: 34px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
}

.history-badge.ok {
  background: var(--teal);
}

.history-badge.no {
  background: var(--coral);
}

.mode-tabs {
  display: flex;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 18px;
}

.tab {
  border: 0;
  border-radius: 0;
  background: white;
  color: var(--muted);
  padding: 0 18px;
  font-weight: 850;
}

.tab.active {
  background: var(--teal);
  color: white;
}

.crypto-form {
  margin-bottom: 14px;
}

.split-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.admin-note {
  background: linear-gradient(180deg, #ffffff 0%, #eef5f0 100%);
}

.admin-note p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.form-error {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: #a64028;
  font-weight: 700;
}

.admin-dialog {
  width: min(430px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

.admin-dialog::backdrop {
  background: rgba(29, 37, 40, 0.46);
}

.admin-dialog form {
  padding: 20px;
  display: grid;
  gap: 10px;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
  margin-top: 8px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .login-panel,
  .practice-grid,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .login-copy h1 {
    max-width: 12ch;
  }

  .login-art {
    min-height: 260px;
    max-height: 340px;
  }
}

@media (max-width: 620px) {
  .topbar {
    width: min(100% - 20px, 1180px);
    align-items: flex-start;
  }

  main {
    width: min(100% - 20px, 1180px);
    padding-top: 10px;
  }

  .session-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .user-chip {
    max-width: 100%;
    flex-basis: 100%;
    text-align: right;
  }

  .inline-field,
  .split-fields {
    grid-template-columns: 1fr;
    display: grid;
  }

  .primary,
  .secondary,
  .ghost {
    width: 100%;
  }

  .practice-controls .ghost,
  .practice-controls .secondary {
    flex: 1 1 180px;
  }

  .card-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .card-heading.compact {
    flex-direction: row;
    align-items: center;
  }

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

  .problem-display {
    min-height: 132px;
  }
}
