:root {
  color-scheme: dark;
  --bg: #080a0f;
  --surface: #11141c;
  --surface-strong: #171b25;
  --surface-soft: #0d1017;
  --line: #252b38;
  --text: #f4f6fb;
  --muted: #98a2b3;
  --muted-strong: #c0c7d2;
  --teal: #43d9bd;
  --teal-dark: #153b39;
  --amber: #f5b84b;
  --red: #ff6b6b;
  --green: #62d279;
  --violet: #9d8cff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  width: 100%;
  min-width: 0;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(67, 217, 189, 0.12), transparent 30rem),
    radial-gradient(circle at 88% 8%, rgba(245, 184, 75, 0.1), transparent 24rem),
    linear-gradient(135deg, #080a0f 0%, #0b0e15 52%, #080a0f 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 18rem 1fr;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  min-width: 0;
  max-width: 100%;
  padding: 1.25rem;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: rgba(13, 16, 23, 0.9);
}

.brand,
.deck-toolbar,
.review-header,
.panel-heading,
.card-bank-header,
.progress-meta,
.review-actions,
.review-controls {
  display: flex;
  align-items: center;
}

.brand {
  gap: 0.75rem;
  min-width: 0;
}

.brand h1,
.brand p,
.review-header h2,
.panel-heading h2,
.eyebrow,
.card-bank-header h3 {
  margin: 0;
}

.brand h1 {
  font-size: 1.1rem;
  line-height: 1.2;
}

.brand p,
.progress-meta,
.card-bank-header span {
  color: var(--muted);
  font-size: 0.84rem;
}

.brand-mark {
  position: relative;
  width: 2.4rem;
  height: 2.4rem;
  flex: 0 0 auto;
}

.brand-mark span {
  position: absolute;
  width: 1.7rem;
  height: 2.1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: linear-gradient(145deg, #202531, #11151e);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.brand-mark span:nth-child(1) {
  left: 0.05rem;
  top: 0.2rem;
  transform: rotate(-10deg);
  border-color: rgba(245, 184, 75, 0.55);
}

.brand-mark span:nth-child(2) {
  left: 0.38rem;
  top: 0.05rem;
  transform: rotate(2deg);
  border-color: rgba(157, 140, 255, 0.52);
}

.brand-mark span:nth-child(3) {
  left: 0.72rem;
  top: 0.18rem;
  transform: rotate(11deg);
  border-color: rgba(67, 217, 189, 0.62);
}

.deck-toolbar,
.review-header,
.panel-heading,
.card-bank-header,
.progress-meta,
.review-controls {
  justify-content: space-between;
  gap: 0.75rem;
}

label,
.deck-toolbar label {
  color: var(--muted-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

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

input,
select {
  height: 2.6rem;
  padding: 0 0.75rem;
}

textarea {
  min-height: 6rem;
  resize: vertical;
  padding: 0.72rem 0.75rem;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(67, 217, 189, 0.15);
}

.deck-list {
  display: grid;
  gap: 0.55rem;
  min-width: 0;
  overflow: auto;
}

.deck-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  align-items: center;
  width: 100%;
  min-height: 3.9rem;
  min-width: 0;
  padding: 0.72rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.deck-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.deck-item.active {
  border-color: rgba(67, 217, 189, 0.42);
  background: rgba(67, 217, 189, 0.08);
}

.deck-item strong,
.deck-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-item strong {
  font-size: 0.94rem;
}

.deck-item span {
  color: var(--muted);
  font-size: 0.8rem;
}

.study-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24rem;
  gap: 1rem;
  width: 100%;
  min-width: 0;
  max-width: 90rem;
  margin: 0 auto;
  padding: 1rem;
}

.review-panel,
.editor-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 20, 28, 0.82);
  box-shadow: var(--shadow);
}

.review-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 2rem);
  padding: 1.25rem;
}

.editor-panel {
  align-self: start;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1rem;
}

.eyebrow {
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.review-header h2,
.panel-heading h2 {
  margin-top: 0.2rem;
  font-size: 1.45rem;
  line-height: 1.15;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0e15;
  color: var(--muted-strong);
}

.icon-button:hover {
  border-color: rgba(67, 217, 189, 0.45);
  color: var(--text);
}

.icon-button svg,
.control-button svg,
.submit-button svg {
  width: 1.05rem;
  height: 1.05rem;
}

.progress-wrap {
  display: grid;
  gap: 0.55rem;
  margin-top: 1.3rem;
}

.progress-track {
  height: 0.55rem;
  overflow: hidden;
  border-radius: 999px;
  background: #080a0f;
}

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

.flashcard {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 1rem;
  width: 100%;
  min-height: 25rem;
  margin: auto 0;
  padding: clamp(1rem, 4vw, 2.5rem);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(67, 217, 189, 0.12), transparent 42%),
    linear-gradient(315deg, rgba(245, 184, 75, 0.1), transparent 38%),
    var(--surface-strong);
  color: var(--text);
  text-align: left;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.flashcard::before {
  content: "";
  position: absolute;
  inset: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  pointer-events: none;
}

.flashcard.flipped {
  background:
    linear-gradient(135deg, rgba(157, 140, 255, 0.14), transparent 42%),
    linear-gradient(315deg, rgba(67, 217, 189, 0.1), transparent 38%),
    var(--surface-strong);
}

.card-side {
  position: relative;
  z-index: 1;
  width: max-content;
  max-width: 100%;
  padding: 0.4rem 0.65rem;
  border: 1px solid rgba(67, 217, 189, 0.35);
  border-radius: 999px;
  background: rgba(67, 217, 189, 0.1);
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.card-text {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  max-width: 52rem;
  min-width: 0;
  color: var(--text);
  font-size: clamp(1.65rem, 4vw, 3.2rem);
  font-weight: 800;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.review-controls {
  margin-top: 1rem;
}

.control-button,
.submit-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.48rem;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-weight: 800;
}

.control-button {
  min-width: 0;
  padding: 0 1rem;
}

.secondary {
  background: #0b0e15;
}

.danger {
  border-color: rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.12);
}

.success {
  border-color: rgba(98, 210, 121, 0.36);
  background: rgba(98, 210, 121, 0.12);
}

.card-form {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
}

.submit-button {
  width: 100%;
  margin-top: 0.15rem;
  background: linear-gradient(135deg, #174640, #173129);
  border-color: rgba(67, 217, 189, 0.45);
}

.card-bank-header {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.card-bank-header h3 {
  font-size: 0.95rem;
}

.card-bank {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.7rem;
}

.bank-card {
  display: grid;
  gap: 0.45rem;
  padding: 0.72rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.bank-card p {
  margin: 0;
  color: var(--muted-strong);
  font-size: 0.84rem;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.bank-card .answer {
  color: var(--muted);
}

.empty-state {
  padding: 0.9rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(22rem, calc(100vw - 2rem));
  padding: 0.78rem 0.9rem;
  border: 1px solid rgba(67, 217, 189, 0.35);
  border-radius: 8px;
  background: rgba(9, 13, 18, 0.95);
  color: var(--text);
  opacity: 0;
  transform: translateY(0.6rem);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  pointer-events: none;
}

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

.review-actions form {
  margin: 0;
}

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

.auth-page {
  display: grid;
  place-items: center;
  width: 100%;
}

.auth-panel {
  width: min(100%, 24rem);
  padding: 1.15rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 20, 28, 0.9);
  box-shadow: var(--shadow);
}

.auth-brand {
  align-items: center;
}

.auth-brand h1 {
  margin: 0.2rem 0 0;
  font-size: 1.55rem;
  line-height: 1.1;
}

.auth-form {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.auth-form .submit-button {
  margin-top: 0.25rem;
}

.auth-error {
  margin: -0.15rem 0 0;
  color: var(--red);
  font-size: 0.88rem;
}

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .deck-list {
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  }

  .study-area {
    grid-template-columns: 1fr;
  }

  .review-panel {
    min-height: auto;
  }

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

@media (max-width: 620px) {
  body {
    background:
      radial-gradient(circle at 12% 0%, rgba(67, 217, 189, 0.11), transparent 18rem),
      linear-gradient(160deg, #080a0f 0%, #0b0e15 60%, #080a0f 100%);
  }

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

  .sidebar {
    position: static;
    order: 2;
    gap: 0.75rem;
    padding:
      max(0.85rem, env(safe-area-inset-top))
      max(0.85rem, env(safe-area-inset-right))
      0.85rem
      max(0.85rem, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    border-bottom: 0;
  }

  .study-area {
    order: 1;
    gap: 0.85rem;
    padding:
      0.85rem
      max(0.85rem, env(safe-area-inset-right))
      max(0.85rem, env(safe-area-inset-bottom))
      max(0.85rem, env(safe-area-inset-left));
  }

  .review-panel,
  .editor-panel {
    padding: 0.85rem;
  }

  .review-header,
  .panel-heading {
    align-items: flex-start;
  }

  .brand-mark {
    width: 2.1rem;
    height: 2.1rem;
  }

  .brand-mark span {
    width: 1.48rem;
    height: 1.86rem;
  }

  .deck-list {
    display: flex;
    gap: 0.55rem;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 0.25rem;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .deck-item {
    flex: 0 0 10.75rem;
    min-height: 4.15rem;
    scroll-snap-align: start;
  }

  .review-panel {
    min-height: calc(100dvh - 1.7rem);
  }

  .review-header h2,
  .panel-heading h2 {
    font-size: 1.25rem;
  }

  .icon-button {
    width: 2.75rem;
    height: 2.75rem;
  }

  .progress-wrap {
    margin-top: 1rem;
  }

  .flashcard {
    min-height: clamp(20rem, 52dvh, 30rem);
    margin: 1rem 0 0;
    padding: 1rem;
  }

  .flashcard::before {
    inset: 0.65rem;
  }

  .card-text {
    font-size: clamp(1.8rem, 9vw, 2.55rem);
    line-height: 1.05;
  }

  .review-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
  }

  .control-button {
    min-height: 3.1rem;
    padding: 0 0.7rem;
  }

  input,
  select {
    height: 3rem;
  }

  textarea {
    min-height: 7.25rem;
  }

  .toast {
    right: max(0.85rem, env(safe-area-inset-right));
    bottom: max(0.85rem, env(safe-area-inset-bottom));
    left: max(0.85rem, env(safe-area-inset-left));
    max-width: none;
  }
}

@media (max-width: 360px) {
  .sidebar,
  .study-area,
  .review-panel,
  .editor-panel {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .deck-list {
    padding-right: 0;
  }

  .deck-item {
    flex-basis: 10rem;
  }

  .card-text {
    font-size: clamp(1.55rem, 8.7vw, 2.2rem);
  }

  .flashcard {
    min-height: clamp(16rem, 46dvh, 18rem);
  }

  .control-button {
    gap: 0.36rem;
    padding: 0 0.52rem;
  }
}
