:root {
  color-scheme: light;
  --paper: #f1eadc;
  --sheet: #fbf7ee;
  --ink: #24251f;
  --muted: #6f7067;
  --line: #c9bea9;
  --rust: #a4492f;
  --forest: #334f42;
  --soft: #e7ddca;
  --good: #315f45;
  --bad: #9b392a;
  --shadow: 0 1rem 3rem rgb(63 48 30 / 10%);
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgb(70 72 60 / 3.5%) 1px, transparent 1px) 0 0 / 100% 2rem,
    var(--paper);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea, select { font: inherit; }
button, .file-button { cursor: pointer; }
a { color: inherit; }

:focus-visible {
  outline: 3px solid var(--rust);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.login-view {
  min-height: 100dvh;
  padding: clamp(1rem, 4vw, 3rem);
  display: grid;
  place-items: center;
}

.home-link {
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 750;
  letter-spacing: .1em;
  text-decoration: none;
  text-transform: uppercase;
}

.login-card {
  width: min(100%, 31rem);
  padding: clamp(1.5rem, 5vw, 3.5rem);
  display: grid;
  gap: .75rem;
  border: 1px solid var(--line);
  background: var(--sheet);
  box-shadow: var(--shadow);
}

.login-card h1, .view-heading h1, .study-header h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: -.045em;
}

.login-card h1 { margin-bottom: .25rem; font-size: clamp(2.5rem, 8vw, 4.5rem); line-height: .92; }
.login-card > p:not(.eyebrow, .form-status) { color: var(--muted); line-height: 1.6; }

.eyebrow {
  margin: 0 0 .6rem;
  color: var(--rust);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

label { display: grid; gap: .45rem; font-size: .78rem; font-weight: 750; }
label span { color: var(--muted); font-weight: 500; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: #fffdf8;
}

input { min-height: 2.8rem; padding: .65rem .8rem; }
textarea { padding: .9rem; resize: vertical; line-height: 1.65; }

.button {
  min-height: 2.8rem;
  padding: .7rem 1rem;
  border: 1px solid var(--ink);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.primary { color: var(--sheet); background: var(--ink); }
.primary:hover { background: var(--forest); }
.secondary { color: var(--ink); background: transparent; }
.secondary:hover { background: var(--soft); }
.login-card .button { width: 100%; }
.login-actions { margin-top: .5rem; display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.login-divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.login-divider::before, .login-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.google-button { color: var(--ink); background: var(--sheet); }
.google-button:hover { background: var(--soft); }
.form-status { min-height: 1.4em; margin: .8rem 0 0; color: var(--bad); font-size: .8rem; }

.app { min-height: 100dvh; }

.app-header {
  min-height: 4rem;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  background: rgb(241 234 220 / 92%);
}

.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.3rem;
  font-weight: 700;
  text-decoration: none;
}

.header-actions { display: flex; align-items: center; gap: 1.25rem; color: var(--muted); font-size: .72rem; }
.header-actions #user-email { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions a, .text-button { font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.text-button { padding: 0; border: 0; color: inherit; background: transparent; text-decoration: underline; }

.app-shell {
  width: min(100%, 90rem);
  min-height: calc(100dvh - 4rem);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2.5rem);
  display: grid;
  grid-template-columns: 12rem minmax(0, 1fr);
  gap: clamp(1.5rem, 5vw, 5rem);
}

.nav { display: flex; flex-direction: column; gap: .25rem; }
.nav-button {
  padding: .85rem 0;
  display: flex;
  justify-content: space-between;
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  text-align: left;
}
.nav-button:hover, .nav-button.active { border-color: var(--rust); color: var(--ink); }
.nav-button span { min-width: 1.5rem; text-align: right; }

main { min-width: 0; }
.view { width: 100%; }
.view-heading { min-height: 8rem; display: flex; align-items: end; justify-content: space-between; gap: 2rem; }
.view-heading h1 { font-size: clamp(2.8rem, 7vw, 6rem); line-height: .86; }
.heading-note { max-width: 27rem; margin: 0; color: var(--muted); line-height: 1.55; text-align: right; }

.search { width: min(100%, 22rem); }
.card-list { margin-top: 2rem; display: grid; gap: .75rem; }
.empty {
  padding: 3rem 1rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.passage-card {
  padding: 1.1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--line);
  background: rgb(251 247 238 / 82%);
}
.passage-card h2 { margin: 0 0 .25rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.4rem; }
.passage-card p { margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }
.card-actions { display: flex; align-items: center; gap: .5rem; }
.small-button { padding: .55rem .7rem; border: 1px solid var(--line); background: transparent; font-size: .7rem; font-weight: 750; text-transform: uppercase; }
.small-button:is(a) { display: inline-flex; align-items: center; text-decoration: none; }
.small-button:hover { border-color: var(--rust); }
.danger { color: var(--bad); }

.backup-bar {
  margin-top: 2rem;
  padding: 1.25rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--line);
}
.backup-bar strong, .backup-bar span { display: block; }
.backup-bar span { margin-top: .25rem; color: var(--muted); font-size: .78rem; }
.backup-actions { display: flex; gap: .5rem; }
.file-button { display: inline-grid; place-items: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.passage-form { margin-top: 2rem; padding: clamp(1rem, 3vw, 2rem); display: grid; gap: 1.25rem; border: 1px solid var(--line); background: var(--sheet); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.form-actions .form-status { margin: 0; }

.wikiquote-search { margin-top: 2rem; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .75rem; }
.browse-status { min-height: 1.5em; margin: 1rem 0 0; color: var(--muted); }
.browse-results { margin-top: 1rem; display: grid; gap: .75rem; }
.browse-card { padding: 1.1rem; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 1rem; border: 1px solid var(--line); background: rgb(251 247 238 / 82%); }
.browse-card h2, .browse-toolbar h2 { margin: 0 0 .35rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.4rem; }
.browse-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.browse-toolbar { padding: 1rem 0; display: flex; align-items: center; gap: .6rem; border-bottom: 1px solid var(--line); }
.browse-toolbar h2 { margin: 0 auto 0 0; }
.quote-result { padding: clamp(1rem, 3vw, 1.5rem); border: 1px solid var(--line); background: var(--sheet); }
.quote-result blockquote { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.1rem, 2.5vw, 1.4rem); line-height: 1.55; white-space: pre-wrap; }
.quote-result-footer { margin-top: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .75rem; }
.wikiquote-credit { margin: 2rem 0 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }

.study {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: var(--sheet);
}
.study::backdrop { background: rgb(36 37 31 / 55%); }
.study-shell { width: min(100%, 70rem); min-height: 100%; margin: 0 auto; padding: clamp(1rem, 4vw, 3rem); display: grid; grid-template-rows: auto auto 1fr auto; }
.study-header { display: flex; justify-content: space-between; gap: 2rem; }
.study-header h1 { font-size: clamp(2.2rem, 6vw, 5rem); line-height: .9; }
.study-header p:last-child { margin: .7rem 0 0; color: var(--muted); }
.icon-button { width: 2.7rem; height: 2.7rem; border: 1px solid var(--line); border-radius: 50%; background: transparent; font-size: 1.5rem; }
.progress { height: 3px; margin: 1.5rem 0; background: var(--soft); }
.progress span { display: block; width: 0; height: 100%; background: var(--rust); transition: width .2s ease; }
.progress .p15 { width: 15%; }
.progress .p35 { width: 35%; }
.progress .p55 { width: 55%; }
.progress .p75 { width: 75%; }
.progress .p90 { width: 90%; }
.progress .p100 { width: 100%; }
.study-content { min-height: 0; padding: clamp(1rem, 5vw, 4rem) 0; }
.study-copy { max-width: 52rem; margin: 0 auto; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.35rem, 3vw, 2.15rem); line-height: 1.65; white-space: pre-wrap; }
.study-copy p { margin: 0 0 1em; }
.revealed-answer { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.typing-instructions, .typing-status { max-width: 52rem; margin: 0 auto 1rem; color: var(--muted); line-height: 1.5; }
.typing-status { min-height: 1.5em; margin-top: 1rem; color: var(--bad); }
.inline-typing { max-width: 52rem; min-height: 12rem; margin: 0 auto; padding: clamp(1rem, 4vw, 2.5rem); position: relative; border: 1px solid var(--line); background: #fffdf8; cursor: text; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.35rem, 3vw, 2.15rem); line-height: 1.8; white-space: pre-wrap; }
.inline-typing.focused { border-color: var(--rust); box-shadow: 0 0 0 2px var(--rust); }
.typing-slot { min-width: .62em; display: inline-block; border-bottom: 2px solid var(--line); color: var(--ink); line-height: 1.25; text-align: center; }
.typing-slot.current { background: var(--soft); border-color: var(--rust); }
.typing-slot.correct { color: var(--good); }
.typing-slot.wrong { color: var(--bad); border-color: var(--bad); }
.typing-keyboard { width: 1px; min-width: 1px; height: 1px; min-height: 1px; padding: 0; position: absolute; opacity: 0; pointer-events: none; }
.recall-label { max-width: 52rem; margin: 0 auto; }
.recall-label textarea { min-height: 18rem; margin-top: .6rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.15rem; }
.feedback { max-width: 52rem; margin: 0 auto; }
.score { margin: 0 0 1rem; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 5vw, 4rem); }
.diff { padding: 1.25rem; border: 1px solid var(--line); font-family: Georgia, "Times New Roman", serif; font-size: 1.1rem; line-height: 2; }
.diff span { margin-right: .28em; }
.diff .missing { color: var(--bad); text-decoration: underline wavy; }
.diff .changed { padding: .1em .2em; color: var(--bad); background: #f3d7cf; }
.diff .extra { color: var(--rust); text-decoration: line-through; }
.feedback-note { color: var(--muted); line-height: 1.6; }
.chunk-note { max-width: 52rem; margin: 0 auto 1.5rem; color: var(--muted); text-align: center; }
.chunk-copy { padding: clamp(1rem, 4vw, 3rem); border: 1px solid var(--line); background: var(--paper); }
.cloze-copy { line-height: 2.4; }
.cloze-blank { min-width: 3.5em; margin: 0 .12em; padding: 0 .2em; display: inline-block; border-bottom: 2px solid var(--line); color: var(--muted); line-height: 1.3; text-align: center; }
.cloze-blank.active { border-color: var(--rust); color: var(--rust); background: var(--soft); }
.cloze-picker { width: min(100%, 34rem); margin: 2rem auto 0; }
.cloze-status { min-height: 1.5em; margin: 0 0 .75rem; color: var(--muted); text-align: center; }
.cloze-choices { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.cloze-choice { min-height: 3.5rem; padding: .7rem; border: 1px solid var(--line); color: var(--ink); background: var(--sheet); font-weight: 750; }
.cloze-choice:hover { border-color: var(--rust); background: var(--paper); }
.cloze-choice.wrong, .cloze-choice.wrong:hover { border-color: var(--bad); color: var(--bad); background: #f3d7cf; opacity: 1; cursor: default; }
.technique-menu { max-width: 60rem; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.technique-card { min-height: 10rem; padding: 1.25rem; display: flex; flex-direction: column; align-items: flex-start; gap: .65rem; border: 1px solid var(--line); color: var(--ink); background: var(--sheet); text-align: left; }
.technique-card:hover { border-color: var(--rust); background: var(--paper); }
.technique-title { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .75rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; }
.technique-description { color: var(--muted); line-height: 1.5; }
.technique-progress { margin-top: auto; color: var(--forest); font-size: .72rem; font-weight: 750; letter-spacing: .04em; }
.recommended { padding: .25rem .4rem; color: var(--sheet); background: var(--rust); font-family: ui-sans-serif, sans-serif; font-size: .58rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.full-recall-card { grid-column: 1 / -1; min-height: 7rem; }
.study-actions { padding-top: 1rem; display: flex; justify-content: flex-end; gap: .75rem; border-top: 1px solid var(--line); }

.study.cloze-mode { overflow: hidden; }
.study.cloze-mode .study-shell {
  height: 100dvh;
  min-height: 0;
  padding-block: clamp(.5rem, 1.5dvh, 1rem);
  grid-template-rows: 8dvh auto minmax(0, 1fr) auto;
  overflow: hidden;
}
.study.cloze-mode .study-header { min-height: 0; align-items: center; overflow: hidden; }
.study.cloze-mode .study-header > div {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "stage byline" "title title";
  align-content: center;
  column-gap: .75rem;
}
.study.cloze-mode #study-stage { grid-area: stage; margin: 0; }
.study.cloze-mode #study-title { grid-area: title; overflow: hidden; font-size: clamp(1.4rem, 3.5dvh, 2.5rem); line-height: 1; text-overflow: ellipsis; white-space: nowrap; }
.study.cloze-mode #study-byline { min-width: 0; grid-area: byline; margin: 0; overflow: hidden; font-size: .72rem; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.study.cloze-mode .icon-button { width: 2.4rem; height: 2.4rem; flex: 0 0 auto; }
.study.cloze-mode .progress { margin: .5dvh 0; }
.study.cloze-mode .study-content { min-height: 0; padding: 0; display: grid; grid-template-rows: minmax(0, 1fr) 25dvh; overflow: hidden; }
.study.cloze-mode .cloze-copy { width: min(100%, 52rem); height: 100%; min-height: 0; margin: 0 auto; padding: clamp(1rem, 3dvh, 2rem) .5rem; position: relative; overflow-y: auto; scrollbar-gutter: stable; scroll-behavior: smooth; }
.study.cloze-mode .cloze-picker { width: min(100%, 34rem); height: 100%; min-height: 0; margin: 0 auto; padding: clamp(.5rem, 1.2dvh, 1rem) 0; display: grid; grid-template-rows: auto minmax(0, 1fr); border-top: 1px solid var(--line); }
.study.cloze-mode .cloze-status { margin-bottom: clamp(.35rem, 1dvh, .75rem); }
.study.cloze-mode .cloze-choices { height: 100%; min-height: 0; }
.study.cloze-mode .study-actions:empty { display: none; }

.toast { min-height: 1.5rem; margin: 0; position: fixed; right: 1rem; bottom: 1rem; z-index: 10; padding: .75rem 1rem; color: var(--sheet); background: var(--ink); opacity: 0; pointer-events: none; transition: opacity .15s ease; }
.toast.visible { opacity: 1; }

@media (max-width: 720px) {
  .header-actions #user-email { display: none; }
  .login-actions { grid-template-columns: 1fr; }
  .app-shell { padding-bottom: 5.5rem; grid-template-columns: 1fr; }
  .nav { padding: .5rem; position: fixed; right: 0; bottom: 0; left: 0; z-index: 5; flex-direction: row; background: var(--sheet); border-top: 1px solid var(--line); }
  .nav-button { flex: 1; padding: .7rem; justify-content: center; gap: .5rem; border: 0; }
  .nav-button.active { color: var(--rust); }
  .view-heading { min-height: auto; align-items: flex-start; flex-direction: column; gap: 1rem; }
  .heading-note { text-align: left; }
  .search { width: 100%; }
  .passage-card { grid-template-columns: 1fr; }
  .wikiquote-search, .browse-card { grid-template-columns: 1fr; }
  .browse-toolbar { align-items: stretch; flex-direction: column; }
  .browse-toolbar h2 { margin-right: 0; }
  .card-actions { flex-wrap: wrap; }
  .form-row { grid-template-columns: 1fr; }
  .backup-bar { align-items: flex-start; flex-direction: column; }
  .study-actions { flex-wrap: wrap; }
  .study-actions .button { flex: 1; }
  .technique-menu { grid-template-columns: 1fr; }
  .full-recall-card { grid-column: auto; }
}

@media (max-height: 680px) {
  .study.cloze-mode { overflow-y: auto; }
  .study.cloze-mode .study-shell { height: auto; min-height: 100dvh; grid-template-rows: auto auto auto auto; overflow: visible; }
  .study.cloze-mode .study-header { min-height: 4rem; }
  .study.cloze-mode .study-content { min-height: 28rem; grid-template-rows: minmax(14rem, 1fr) minmax(12rem, auto); overflow: visible; }
  .study.cloze-mode .cloze-copy { max-height: 50dvh; }
  .study.cloze-mode .cloze-picker { min-height: 12rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
