:root {
  color-scheme: light dark;
  --background: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f0f3f6;
  --text: #1d1d1f;
  --muted: #68707a;
  --line: #d9dee5;
  --accent: #1769e0;
  --accent-strong: #0b56c5;
  --danger: #c62828;
  --success: #167a4a;
  --warning: #9a6700;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans", "Yu Gothic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #111315;
    --surface: #1c1f23;
    --surface-strong: #262a30;
    --text: #f5f5f7;
    --muted: #a1a7b0;
    --line: #343941;
    --accent: #6aa2ff;
    --accent-strong: #8db8ff;
    --danger: #ff6961;
    --success: #58d68d;
    --warning: #ffd166;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1,
.editor-toolbar h2,
.sidebar-toolbar h2,
.questions-section h3,
.question-editor h3 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: 28px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.auth-area {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.header-link {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.header-link:hover {
  color: var(--accent);
}

.shell {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 78px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 18px;
  min-width: 0;
}

.sidebar-toolbar,
.editor-toolbar,
.section-heading,
.split-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.status {
  margin: 14px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 14px;
  line-height: 1.45;
}

.pro-access-notice {
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--warning) 42%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--warning) 8%, var(--surface));
  color: var(--text);
}

.pro-access-notice strong {
  display: block;
  margin-bottom: 4px;
}

.pro-access-notice p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.deck-list,
.question-list {
  display: grid;
  gap: 8px;
}

.deck-row,
.question-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.deck-row {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.deck-row.is-selected {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.deck-row-title {
  font-weight: 700;
}

.deck-row-meta,
.question-meta,
.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.editor {
  min-width: 0;
  padding: 24px 28px 40px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.editor-toolbar {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.deck-form,
.question-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  resize: vertical;
}

.question-editor,
.questions-section {
  display: grid;
  gap: 12px;
  padding-top: 6px;
}

.study-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.study-head,
.study-meta,
.study-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.study-head h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.study-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  flex-wrap: wrap;
}

.study-card {
  display: grid;
  gap: 14px;
}

.study-prompt {
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-strong);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
  user-select: text;
}

.study-options {
  display: grid;
  gap: 8px;
}

.study-media,
.question-media {
  display: grid;
  gap: 8px;
}

.question-media {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.cloud-image {
  margin: 0;
  display: grid;
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-strong);
}

.cloud-image img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  background: var(--surface-strong);
}

.cloud-image-placeholder {
  display: grid;
  place-items: center;
  min-height: 88px;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.option-button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.option-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.option-button.is-correct {
  border-color: color-mix(in srgb, var(--success) 70%, var(--line));
  background: color-mix(in srgb, var(--success) 14%, var(--surface));
  color: var(--text);
}

.option-button.is-wrong {
  border-color: color-mix(in srgb, var(--danger) 70%, var(--line));
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--text);
}

.study-result {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.study-result[data-result="correct"] {
  border-color: color-mix(in srgb, var(--success) 55%, var(--line));
}

.study-result[data-result="wrong"] {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
}

.study-result strong {
  color: var(--success);
}

.study-result[data-result="wrong"] strong {
  color: var(--danger);
}

.study-result p {
  margin: 0;
}

.question-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 12px;
}

.question-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.question-prompt {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.question-answer,
.question-explanation {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.question-actions {
  display: flex;
  align-items: start;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.file-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 36px;
  padding: 8px 12px;
  font-weight: 700;
}

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

.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.secondary-button,
.icon-button,
.file-button {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--line);
}

.danger-button {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
}

.icon-button {
  width: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.file-button input {
  display: none;
}

.empty-state {
  padding: 20px 8px;
  text-align: center;
}

.legal-shell {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 760px);
  gap: 32px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 28px 56px;
}

.legal-toc {
  position: sticky;
  top: 104px;
  align-self: start;
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.legal-toc a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.legal-doc {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  line-height: 1.75;
}

.legal-doc h2,
.legal-doc h3,
.legal-doc p,
.legal-doc ul {
  margin: 0;
}

.legal-doc h2 {
  padding-top: 10px;
  font-size: 22px;
  line-height: 1.3;
}

.legal-doc h3 {
  padding-top: 4px;
  font-size: 16px;
  line-height: 1.45;
}

.legal-doc ul {
  padding-left: 1.3em;
}

@media (max-width: 820px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .question-row,
  .editor-toolbar,
  .split-actions,
  .study-head,
  .study-meta {
    grid-template-columns: 1fr;
    display: grid;
  }

  .editor-actions {
    width: 100%;
    justify-content: stretch;
  }

  .editor-actions > button,
  .study-head > button {
    width: 100%;
  }

  .legal-shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 22px 18px 40px;
  }

  .legal-toc {
    position: static;
  }

  .legal-doc {
    padding: 20px;
  }
}

@media (max-width: 360px) {
  .app-header {
    padding-inline: 18px;
  }

  .app-header h1 {
    font-size: 24px;
  }

  .legal-doc h2 {
    font-size: 20px;
  }
}
