:root {
  --canvas: #f7f5ef;
  --surface: #fffdfa;
  --surface-soft: #f0eee8;
  --ink: #13223f;
  --ink-muted: #6d778a;
  --indigo: #5966b7;
  --indigo-deep: #45519b;
  --indigo-soft: #e7e9f7;
  --mint: #cfeadf;
  --mint-ink: #2c6d57;
  --line: #dfddd5;
  --danger: #b64d58;
  --shadow: 0 16px 34px rgba(24, 39, 73, 0.08);
  --shadow-subtle: 0 7px 18px rgba(24, 39, 73, 0.06);
  --radius: 22px;
  --radius-small: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { min-height: 100vh; margin: 0; background: var(--canvas); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(89, 102, 183, 0.28); outline-offset: 2px; }

.app-shell { width: min(100%, 860px); min-height: 100vh; margin: 0 auto; padding: 0 18px 46px; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 78px; }
.brand-button { border: 0; padding: 0; background: transparent; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 1.75rem; font-weight: 700; letter-spacing: -0.055em; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: 0 2px 7px rgba(24, 39, 73, 0.04); font-size: 1.15rem; line-height: 1; }
.primary-icon { border-color: var(--indigo); background: var(--indigo); color: white; font-size: 1.55rem; }

.view { display: none; animation: reveal 180ms ease-out; }
.active-view { display: block; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.hero-row, .deck-heading-row, .section-row, .mode-topbar, .modal-heading-row, .editor-side-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.hero-row { align-items: flex-end; margin: 20px 0 20px; }
.eyebrow { margin: 0 0 6px; color: var(--indigo); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.13em; }
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; letter-spacing: -0.04em; }
h1 { font-size: clamp(2.25rem, 8vw, 3.35rem); line-height: 0.98; }
h2 { font-size: 1.25rem; }
.deck-total, .progress-label { color: var(--ink-muted); font-size: 0.85rem; font-weight: 700; white-space: nowrap; }

.search-field { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 50px; padding: 0 16px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 253, 250, 0.74); box-shadow: var(--shadow-subtle); }
.search-icon { font-size: 1.38rem; color: var(--ink-muted); transform: rotate(-15deg); }
.search-field input { width: 100%; border: 0; outline: none; background: transparent; color: var(--ink); }
.search-field input::placeholder { color: #9298a4; }

.deck-list { display: grid; gap: 12px; margin-top: 22px; }
.deck-item { border: 1px solid var(--line); border-radius: var(--radius-small); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-subtle); }
.deck-open-button { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 17px; border: 0; background: transparent; color: inherit; text-align: left; }
.deck-open-button:hover { background: #fbfaf6; }
.deck-item-main { display: grid; gap: 5px; min-width: 0; }
.deck-item-title { overflow: hidden; font-family: Georgia, "Times New Roman", serif; font-size: 1.33rem; font-weight: 700; letter-spacing: -0.03em; text-overflow: ellipsis; white-space: nowrap; }
.deck-item-meta { color: var(--ink-muted); font-size: 0.84rem; }
.deck-chevron { color: var(--indigo); font-size: 2rem; font-weight: 300; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 8px; border-radius: 999px; background: var(--mint); color: var(--mint-ink); font-size: 0.7rem; font-weight: 800; }

.empty-state { max-width: 470px; margin: 68px auto 0; padding: 34px 22px; border: 1px dashed #c9c6bc; border-radius: var(--radius); color: var(--ink-muted); text-align: center; }
.empty-state h2 { color: var(--ink); }
.empty-state p { margin: 10px 0 21px; line-height: 1.55; }
.empty-mark { display: grid; width: 50px; height: 50px; margin: 0 auto 16px; place-items: center; border-radius: 16px; background: var(--indigo-soft); color: var(--indigo-deep); font-family: Georgia, "Times New Roman", serif; font-size: 1.75rem; font-weight: 700; }
.compact-empty { margin-top: 28px; }
.hidden { display: none !important; }

.button { min-height: 44px; padding: 0 17px; border: 1px solid transparent; border-radius: 13px; font-weight: 800; transition: transform 140ms ease, background-color 140ms ease; }
.button:hover { transform: translateY(-1px); }
.primary { background: var(--indigo); color: white; }
.primary:hover { background: var(--indigo-deep); }
.secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.compact { min-height: 38px; padding: 0 12px; border-color: var(--indigo-soft); background: var(--indigo-soft); color: var(--indigo-deep); }
.danger { background: var(--danger); color: white; }

.back-link { padding: 8px 0; border: 0; background: transparent; color: var(--indigo-deep); font-size: 0.9rem; font-weight: 800; }
.deck-heading-row { align-items: flex-start; margin: 16px 0 20px; }
.deck-heading-row h1 { margin-bottom: 10px; font-size: clamp(2.1rem, 7vw, 3rem); }
.deck-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0 34px; }
.section-row { align-items: flex-end; margin-bottom: 14px; }
.section-row h2 { font-size: 1.4rem; }
.card-list { display: grid; gap: 10px; }
.card-list-item { display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-small); background: var(--surface); box-shadow: var(--shadow-subtle); }
.card-thumb { display: grid; flex: 0 0 58px; width: 58px; height: 58px; place-items: center; overflow: hidden; border-radius: 12px; background: var(--surface-soft); color: var(--ink-muted); font-family: Georgia, "Times New Roman", serif; font-size: 1.2rem; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-list-copy { flex: 1; min-width: 0; }
.card-list-copy strong, .card-list-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-list-copy strong { color: var(--ink); font-size: 0.9rem; }
.card-list-copy span { margin-top: 4px; color: var(--ink-muted); font-size: 0.78rem; }
.card-more-button { width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-muted); }
.card-more-button:hover { background: var(--surface-soft); }

.mode-topbar { margin-top: 6px; }
.study-heading { margin: 20px 0 18px; }
.study-heading h1 { font-size: clamp(1.95rem, 7vw, 2.75rem); }
.mode-intro { max-width: 560px; margin: 10px 0 0; color: var(--ink-muted); line-height: 1.5; }
.flashcard { min-height: min(61vh, 540px); perspective: 1200px; outline: none; }
.flashcard-inner { position: relative; width: 100%; min-height: inherit; transition: transform 380ms cubic-bezier(.2,.8,.2,1); transform-style: preserve-3d; }
.flashcard.is-flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 26px; border: 1px solid var(--line); border-radius: 27px; background: var(--surface); box-shadow: var(--shadow); backface-visibility: hidden; }
.flashcard-back { transform: rotateY(180deg); background: #fbfbff; }
.card-side-label { margin: 0; color: var(--indigo); font-size: 0.67rem; font-weight: 800; letter-spacing: 0.13em; }
.flashcard-content { display: grid; flex: 1; gap: 17px; place-content: center; overflow: auto; padding: 14px 0; text-align: center; }
.flashcard-text { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.55rem, 6vw, 2.65rem); line-height: 1.18; letter-spacing: -0.035em; white-space: pre-wrap; }
.flashcard-image { width: min(100%, 360px); aspect-ratio: 1; margin: 0 auto; object-fit: cover; border-radius: 19px; box-shadow: 0 8px 20px rgba(24,39,73,.1); }
.tap-hint { margin: 0; color: var(--ink-muted); font-size: 0.76rem; text-align: center; }
.study-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.direction-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,253,250,.7); color: var(--ink-muted); font-size: 0.8rem; font-weight: 700; }
.direction-toggle select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }

.matching-status { min-height: 22px; margin: 8px 0 12px; color: var(--mint-ink); font-size: 0.82rem; font-weight: 800; }
.matching-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.matching-label { margin: 0 0 8px; color: var(--ink-muted); font-size: 0.68rem; font-weight: 800; letter-spacing: .12em; }
.matching-column { display: grid; gap: 9px; max-height: 61vh; overflow-y: auto; padding: 2px 3px 3px; }
.matching-choice { min-height: 68px; padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--ink); text-align: left; box-shadow: var(--shadow-subtle); }
.matching-choice:hover { border-color: #b8c0e9; }
.matching-choice.selected { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(89,102,183,.15); }
.matching-choice.matched { border-color: #a8d8c0; background: #eff9f3; color: var(--mint-ink); cursor: default; }
.matching-choice img { display: block; width: 100%; aspect-ratio: 1; margin-bottom: 8px; object-fit: cover; border-radius: 8px; }
.matching-choice span { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 3; font-size: 0.82rem; line-height: 1.25; }

.modal { width: min(94vw, 680px); max-height: min(92vh, 900px); padding: 0; border: 0; border-radius: 22px; background: transparent; box-shadow: 0 30px 70px rgba(11, 21, 44, 0.28); }
.modal::backdrop { background: rgba(19,34,63,.36); backdrop-filter: blur(3px); }
.modal-card { max-height: inherit; overflow-y: auto; padding: 22px; background: var(--surface); }
.small-modal-card { width: min(94vw, 430px); }
.modal-heading-row { align-items: flex-start; }
.modal-heading-row h2 { font-size: 1.55rem; }
.close-dialog { flex: 0 0 auto; font-size: 1.45rem; }
.field-label { display: grid; gap: 7px; margin-top: 18px; color: var(--ink); font-size: .84rem; font-weight: 800; }
.field-note { color: var(--ink-muted); font-weight: 500; }
.field-label input, textarea { width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 12px; outline: none; background: #fffefa; color: var(--ink); resize: vertical; }
.modal-copy { margin: 11px 0 18px; color: var(--ink-muted); line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.card-editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card-side-editor { padding: 13px; border: 1px solid var(--line); border-radius: 15px; background: #fcfbf7; }
.editor-side-heading { margin-bottom: 9px; color: var(--ink); font-size: .82rem; font-weight: 800; }
.clear-side-button { padding: 2px 0; border: 0; background: transparent; color: var(--indigo-deep); font-size: .72rem; font-weight: 800; }
.card-side-editor textarea { min-height: 130px; }
.file-input { display: none; }
.image-picker-button { width: 100%; min-height: 38px; margin-top: 10px; border: 1px dashed #bfc3d7; border-radius: 10px; background: var(--indigo-soft); color: var(--indigo-deep); font-size: .8rem; font-weight: 800; }
.image-preview { position: relative; width: 100%; aspect-ratio: 1; margin-top: 10px; overflow: hidden; border-radius: 11px; background: var(--surface-soft); }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview button { position: absolute; top: 7px; right: 7px; width: 28px; height: 28px; border: 0; border-radius: 50%; background: rgba(19,34,63,.78); color: white; font-size: 1rem; }
.form-error { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: .8rem; font-weight: 700; }
.crop-modal-card { width: min(94vw, 540px); }
.crop-stage { position: relative; width: 100%; aspect-ratio: 1; overflow: hidden; border-radius: 16px; background: #d8d6cf; cursor: grab; touch-action: none; }
.crop-stage:active { cursor: grabbing; }
.crop-stage img { position: absolute; top: 50%; left: 50%; max-width: none; user-select: none; -webkit-user-drag: none; transform-origin: center; }
.crop-range-label { display: grid; gap: 8px; margin-top: 15px; color: var(--ink-muted); font-size: .8rem; font-weight: 800; }
.crop-range-label input { width: 100%; accent-color: var(--indigo); }

@media (max-width: 560px) {
  .app-shell { padding: 0 14px 34px; }
  .topbar { min-height: 68px; }
  .deck-actions { grid-template-columns: 1fr; }
  .card-editor-grid { grid-template-columns: 1fr; }
  .card-modal-card { padding: 18px; }
  .flashcard { min-height: 57vh; }
  .matching-layout { gap: 8px; }
  .matching-choice { min-height: 60px; padding: 8px; }
  .matching-choice span { font-size: .75rem; }
}
