:root {
  color-scheme: light;
  --ink: #15212f;
  --muted: #667085;
  --line: #d8e1e5;
  --paper: #fbfcfd;
  --surface: #ffffff;
  --teal: #087f8c;
  --teal-dark: #05606a;
  --green: #2f8f5b;
  --red: #c2413d;
  --amber: #d99a24;
  --blue: #3667b0;
  --shadow: 0 22px 70px rgba(21, 33, 47, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(8, 127, 140, 0.08), rgba(217, 154, 36, 0.08)),
    #f6f8fa;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 0 22px;
  border-bottom: 1px solid rgba(21, 33, 47, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 230px;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: 8px 8px 0 rgba(8, 127, 140, 0.18);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.55rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
  letter-spacing: 0;
}

h3 {
  font-size: 0.98rem;
  line-height: 1.35;
  letter-spacing: 0;
}

.brand p,
.panel-heading p,
.review-strip,
.metric span {
  color: var(--muted);
}

.scorebar {
  display: grid;
  grid-template-columns: repeat(4, minmax(82px, 1fr));
  gap: 10px;
  width: min(520px, 100%);
}

.metric {
  min-height: 70px;
  padding: 12px 14px;
  border: 1px solid rgba(21, 33, 47, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.metric strong {
  display: block;
  font-size: 1.45rem;
  line-height: 1.1;
}

.metric span {
  display: block;
  margin-top: 4px;
  font-size: 0.8rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 420px) minmax(0, 1fr);
  gap: 22px;
  padding-top: 24px;
}

.deck-panel,
.study-panel {
  min-width: 0;
  border: 1px solid rgba(21, 33, 47, 0.13);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.deck-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 142px);
  overflow: hidden;
}

.study-panel {
  padding: 20px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 14px;
}

.study-panel > .panel-heading {
  padding: 0 0 18px;
}

.card-form {
  display: grid;
  gap: 9px;
  padding: 0 18px 18px;
  border-bottom: 1px solid var(--line);
}

label {
  color: #344054;
  font-size: 0.85rem;
  font-weight: 700;
}

textarea,
input[type="number"],
input[type="search"] {
  width: 100%;
  border: 1px solid #c7d2d7;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
  resize: vertical;
  min-height: 84px;
  padding: 11px 12px;
  line-height: 1.35;
}

input[type="number"],
input[type="search"] {
  height: 42px;
  padding: 0 12px;
}

textarea:focus,
input[type="number"]:focus,
input[type="search"]:focus {
  border-color: var(--teal);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(8, 127, 140, 0.14);
}

.form-row {
  display: grid;
  grid-template-columns: auto 82px auto 1fr;
  align-items: end;
  gap: 10px;
}

.points-field {
  align-self: center;
}

.primary-button,
.ghost-button,
.icon-text-button,
.missed-button,
.correct-button,
.flip-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: var(--radius);
  font-weight: 800;
  letter-spacing: 0;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.primary-button:hover,
.ghost-button:hover,
.icon-text-button:hover,
.missed-button:hover,
.correct-button:hover,
.flip-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  padding: 0 14px;
  background: var(--teal);
  color: #ffffff;
}

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

.ghost-button,
.icon-text-button {
  padding: 0 12px;
  border: 1px solid #c7d2d7;
  background: #ffffff;
  color: var(--ink);
}

.icon-text-button[aria-pressed="true"] {
  border-color: rgba(8, 127, 140, 0.36);
  background: #e7f8f8;
  color: var(--teal-dark);
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid transparent;
  background: #f2f5f6;
  color: var(--ink);
}

.icon-button.danger,
.deck-action.danger {
  color: var(--red);
}

.deck-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.search-field {
  position: relative;
  display: block;
}

.search-field svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-field input {
  padding-left: 38px;
}

.card-list {
  display: grid;
  gap: 0;
  overflow: auto;
}

.deck-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.deck-item.active {
  background: #edfafa;
}

.deck-item p {
  display: -webkit-box;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.deck-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.deck-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef2f4;
  color: #475467;
  font-size: 0.75rem;
  font-weight: 800;
}

.deck-actions {
  display: flex;
  align-items: start;
  gap: 7px;
}

.deck-action {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: var(--radius);
  background: #f2f5f6;
  color: var(--ink);
}

.study-tools,
.study-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.flashcard {
  display: grid;
  grid-template-rows: auto minmax(190px, 1fr) auto;
  min-height: 390px;
  padding: 22px;
  border: 1px solid rgba(21, 33, 47, 0.16);
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(54, 103, 176, 0.1), rgba(8, 127, 140, 0.05) 44%, rgba(217, 154, 36, 0.11)),
    #ffffff;
  box-shadow: inset 0 -7px 0 rgba(8, 127, 140, 0.1);
  outline: none;
  transform: rotateY(0deg) scale(1);
  transform-style: preserve-3d;
  transition: transform 220ms ease, background 220ms ease, box-shadow 220ms ease;
  will-change: transform;
}

.flashcard:focus {
  box-shadow: 0 0 0 4px rgba(8, 127, 140, 0.14), inset 0 -7px 0 rgba(8, 127, 140, 0.1);
}

.flashcard.answer-side {
  background:
    linear-gradient(160deg, rgba(47, 143, 91, 0.12), rgba(8, 127, 140, 0.05) 44%, rgba(217, 154, 36, 0.13)),
    #ffffff;
  box-shadow: inset 0 -7px 0 rgba(47, 143, 91, 0.13);
}

.flashcard.is-flipping {
  transform: rotateY(90deg) scale(0.98);
}

.flashcard-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.78rem;
}

#card-points {
  min-width: 64px;
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #fff6df;
  color: #8a5d0a;
}

#card-text {
  align-self: center;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: clamp(1.8rem, 4vw, 3.5rem);
  line-height: 1.08;
  text-align: center;
}

.flip-button {
  justify-self: center;
  min-width: 132px;
  padding: 0 18px;
  background: var(--ink);
  color: #ffffff;
}

.study-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
}

.missed-button,
.correct-button {
  min-height: 54px;
  color: #ffffff;
  font-size: 1rem;
}

.missed-button {
  background: var(--red);
}

.correct-button {
  background: var(--green);
}

.progress-wrap {
  height: 12px;
  margin-top: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef0;
}

.progress-wrap span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--amber));
  transition: width 180ms ease;
}

.review-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  margin-top: 16px;
  padding: 0 2px;
  font-size: 0.95rem;
}

.empty-state {
  padding: 28px 18px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 24px, 680px);
    padding: 18px 0;
  }

  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    gap: 18px;
  }

  .scorebar {
    width: 100%;
  }

  .workspace {
    display: grid;
  }

  .deck-panel {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .scorebar {
    grid-template-columns: repeat(2, 1fr);
  }

  .panel-heading,
  .deck-tools,
  .study-actions,
  .form-row {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: start;
  }

  .study-tools {
    width: 100%;
  }

  .study-tools button,
  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .form-row {
    align-items: stretch;
  }

  .points-field {
    align-self: auto;
  }

  .flashcard {
    min-height: 330px;
    padding: 18px;
  }

  #card-text {
    font-size: clamp(1.55rem, 9vw, 2.25rem);
  }

  .review-strip {
    align-items: start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flashcard,
  .primary-button,
  .ghost-button,
  .icon-text-button,
  .missed-button,
  .correct-button,
  .flip-button,
  .icon-button,
  .progress-wrap span,
  .toast {
    transition: none;
  }
}
