:root {
  color-scheme: light;
  --ink: #17231f;
  --muted: #66736e;
  --paper: #fffefa;
  --canvas: #f1f3ec;
  --line: #dce1d8;
  --green: #0d6952;
  --green-dark: #084d3c;
  --green-soft: #e4f2eb;
  --gold: #dba43a;
  --red: #aa3f36;
  --red-soft: #fae9e5;
  --shadow: 0 24px 70px rgba(39, 55, 47, .1);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.portal-page .site-header { position: sticky; top: 0; z-index: 40; box-shadow: 0 1px 0 rgba(23,35,31,.06); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.layout { min-height: calc(100vh - 78px); display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.sidebar { padding: 38px 30px; background: #e9ede4; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 25px; }
.eyebrow { margin: 0 0 8px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 32px; font-weight: 500; letter-spacing: -.035em; }
.intro { margin: 12px 0 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.field { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.field input, .field select { width: 100%; min-height: 43px; padding: 0 12px; color: var(--ink); background: rgba(255,255,255,.72); border: 1px solid #cbd3c7; border-radius: 8px; outline: none; text-transform: none; letter-spacing: 0; }
.field input:focus, .field select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(13,105,82,.1); }
.field > small { color:var(--muted); font-size:10px; font-weight:500; line-height:1.45; letter-spacing:0; text-transform:none; }
.topic-picker { position:relative; color:var(--ink); background:rgba(255,255,255,.72); border:1px solid #cbd3c7; border-radius:8px; text-transform:none; letter-spacing:0; }
.topic-picker > summary { min-height:43px; padding:0 34px 0 12px; display:flex; align-items:center; position:relative; cursor:pointer; list-style:none; font-size:13px; font-weight:650; }
.topic-picker > summary::-webkit-details-marker { display:none; }
.topic-picker > summary::after { content:"⌄"; position:absolute; right:12px; color:var(--muted); font-size:16px; }
.topic-picker[open] > summary { border-bottom:1px solid var(--line); }
.topic-picker-actions { padding:8px 9px; display:flex; gap:7px; border-bottom:1px solid var(--line); }
.topic-picker-actions button { min-height:30px; padding:0 10px; color:var(--green-dark); background:var(--green-soft); border:1px solid #c9ded3; border-radius:6px; font-size:10px; font-weight:800; }
.topic-options { max-height:250px; padding:7px; overflow:auto; display:grid; gap:2px; }
.topic-option { padding:7px 6px; display:grid; grid-template-columns:auto minmax(0,1fr) auto; align-items:start; gap:8px; border-radius:6px; font-size:11px; line-height:1.35; cursor:pointer; }
.topic-option:hover { background:var(--green-soft); }
.topic-option input { width:15px; height:15px; min-height:0; margin:0; accent-color:var(--green); }
.topic-option b { color:var(--muted); font-size:10px; font-weight:650; }
.filter-note { margin:0; padding:11px 12px; color:var(--green-dark); background:var(--green-soft); border-left:3px solid var(--green); border-radius:0 7px 7px 0; font-size:11px; line-height:1.45; }
.topic-list { display: grid; gap: 3px; }
.topic-button { width: 100%; padding: 10px 8px; display: flex; justify-content: space-between; gap: 8px; color: var(--muted); background: transparent; border: 0; border-radius: 7px; text-align: left; font-size: 13px; }
.topic-button:hover, .topic-button.active { color: var(--green-dark); background: rgba(255,255,255,.6); }
.topic-button span:last-child { font-variant-numeric: tabular-nums; }
.text-button { margin-top: auto; padding: 0; align-self: flex-start; color: var(--muted); background: none; border: 0; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }

.study-area { min-width:0; padding:34px clamp(20px,2.5vw,42px) 70px; }
.toolbar { width:100%; max-width:1280px; margin:0 auto 18px; padding:0 4px; display:flex; align-items:center; justify-content:space-between; color:var(--muted); font-size:13px; }
.toolbar small { display: block; margin-top: 3px; font-size: 10px; }
.nav-buttons { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.shuffle-button { min-height:36px; padding:0 12px; color:var(--green-dark); background:var(--green-soft); border:1px solid #c9ded3; border-radius:999px; font-size:11px; font-weight:800; }
.shuffle-button:hover { border-color:#8fbeaa; }
.icon-button { width: 36px; height: 36px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 50%; }
.icon-button:disabled { opacity: .35; cursor: default; }
.question-card { width:100%; max-width:1280px; min-height:520px; margin:auto; padding:clamp(30px,4vw,60px); background:var(--paper); border:1px solid rgba(204,211,201,.8); border-radius:18px; box-shadow:var(--shadow); }
.swipe-hint { display:none; }
.loading, .empty { min-height: 390px; display: grid; place-items: center; color: var(--muted); text-align: center; }
.question-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-bottom: 26px; }
.chip { padding: 6px 9px; color: var(--green-dark); background: var(--green-soft); border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.chip.subtle { color: var(--muted); background: #eef0eb; }
.chip.professor { color: #694b0b; background: #fff0c9; }
.chip.difficulty-easy { color:#2c654c; background:#e7f4eb; }
.chip.difficulty-medium { color:#7a580f; background:#fff1c9; }
.chip.difficulty-hard { color:#8d332d; background:#fae3de; }
.chip.cebraspe-frequency { color:#dffbff; background:#13213d; border:1px solid #315a74; box-shadow:inset 0 0 0 1px rgba(85,232,244,.08); }
.review-flag { margin-left: auto; color: #8a5a09; font-size: 11px; font-weight: 750; }
.question-title { max-width:1080px; margin:0 0 28px; overflow-wrap:anywhere; font-family:Georgia,"Times New Roman",serif; font-size:clamp(21px,1.65vw,27px); font-weight:500; line-height:1.5; letter-spacing:-.012em; white-space:normal; }
.question-title.long-statement { padding: 18px 20px; color: #2c3c36; background: #f3f5ef; border-left: 4px solid var(--green); border-radius: 0 10px 10px 0; font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: 17px; font-weight: 500; line-height: 1.68; letter-spacing: 0; }
.visual-note { margin: -10px 0 20px; padding: 11px 13px; color: #704c0b; background: #fff4d6; border-left: 3px solid var(--gold); font-size: 13px; line-height: 1.45; }
.options { display: grid; gap: 11px; }
.option { width: 100%; padding: 14px 16px; display: grid; grid-template-columns: 32px 1fr; align-items: start; gap: 12px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 10px; text-align: left; line-height: 1.5; transition: border-color .15s, background .15s, transform .15s; }
.option:hover:not(:disabled) { border-color: #9aac9f; transform: translateY(-1px); }
.option.selected { border-color: var(--green); background: #f4faf6; }
.option.correct { border-color: var(--green); background: var(--green-soft); }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option-key { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid #cbd3c7; border-radius: 50%; font-size: 12px; font-weight: 800; }
.card-actions { margin-top: 26px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.primary-button { min-height: 44px; padding: 0 22px; color: white; background: var(--green); border: 0; border-radius: 8px; font-weight: 750; }
.primary-button:hover { background: var(--green-dark); }
.primary-button:disabled { opacity: .45; cursor: default; }
.source { color: var(--muted); font-size: 11px; line-height: 1.45; text-align: right; }
.feedback { margin-top: 30px; padding-top: 26px; border-top: 1px solid var(--line); }
.feedback-heading { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; font-weight: 800; }
.feedback-heading.correct { color: var(--green); }
.feedback-heading.wrong { color: var(--red); }
.explanation { margin: 0; color: #3e4c47; line-height: 1.7; white-space: pre-wrap; }
.no-comment { color: var(--muted); font-style: italic; }

.hidden { display: none !important; }
.library-view { min-height:calc(100vh - 78px); padding:42px clamp(20px,3vw,52px) 80px; background:var(--canvas); }
.library-hero { width:100%; max-width:1500px; margin:0 auto 30px; padding:clamp(30px,4vw,50px); display:flex; align-items:center; justify-content:space-between; gap:42px; overflow:hidden; border-radius:20px; }
.library-hero h1 { font-size:clamp(38px,4.6vw,66px); line-height:1; }
.library-hero .intro { max-width:760px; font-size:16px; line-height:1.65; }
.library-summary { flex: 0 0 auto; padding: 13px 16px; color: var(--green-dark); background: var(--green-soft); border: 1px solid #c9ded3; border-radius: 10px; font-size: 13px; font-weight: 750; }
.library-subjects,.library-materials-panel { width:100%; max-width:1500px; margin:0 auto; }
.library-section-heading { margin-bottom: 18px; display: flex; align-items: end; justify-content: space-between; gap: 30px; }
.library-section-heading h2,.library-panel-heading h2 { margin: 0; font: 500 clamp(27px,3.2vw,38px)/1.15 Georgia,"Times New Roman",serif; letter-spacing: -.025em; }
.library-section-heading > p { max-width: 440px; margin: 0; color: var(--muted); line-height: 1.55; }
.subject-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(310px,1fr)); gap:17px; }
.subject-card { min-width: 0; min-height: 235px; padding: 24px; display: flex; flex-direction: column; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 16px 44px rgba(39,55,47,.07); text-align: left; transition: transform .16s ease,border-color .16s ease,box-shadow .16s ease; }
.subject-card:hover,.subject-card:focus-visible { transform: translateY(-3px); border-color: #9fc8b7; box-shadow: 0 20px 52px rgba(25,75,58,.13); outline: none; }
.subject-card-top { display: flex; align-items: center; justify-content: space-between; }
.subject-number { width: 36px; height: 36px; display: grid; place-items: center; color: white; background: var(--green); border-radius: 10px; font: 750 12px/1 ui-monospace,Consolas,monospace; }
.subject-open { color: var(--green-dark); font-size: 12px; font-weight: 800; }
.subject-card h3 { margin: 24px 0 8px; overflow-wrap: anywhere; font: 500 25px/1.2 Georgia,"Times New Roman",serif; letter-spacing: -.02em; }
.subject-card > p { margin: 0; color: var(--muted); font-size: 13px; }
.subject-progress-row { margin-top: auto; padding-top: 23px; display: flex; justify-content: space-between; gap: 15px; color: var(--muted); font-size: 11px; }
.subject-progress-row strong { color: var(--green-dark); }
.subject-card .progress-track { margin: 9px 0 0; }
.library-panel-heading { margin-bottom: 18px; display: grid; grid-template-columns: auto minmax(0,1fr); align-items: start; gap: 22px; }
.library-panel-heading > div { min-width: 0; }
.library-panel-heading > div > p:last-child { margin: 7px 0 0; color: var(--muted); }
.library-back-button { min-height: 42px; padding: 0 14px; color: var(--green-dark); background: var(--green-soft); border: 1px solid #c9ded3; border-radius: 9px; font-size: 12px; font-weight: 800; }
.library-back-button:hover { border-color: #8fbeaa; }
.library-toolbar { width:100%; max-width:1500px; margin:0 auto; padding:18px; display:grid; grid-template-columns:minmax(260px,1.5fr) minmax(180px,.7fr); gap:15px; background:#e9ede4; border:1px solid var(--line); border-radius:14px; }
.library-results { width:100%; max-width:1500px; margin:18px auto 12px; color:var(--muted); font-size:13px; }
.library-grid { width:100%; max-width:1500px; margin:auto; display:grid; grid-template-columns:repeat(auto-fill,minmax(310px,1fr)); gap:17px; }
.library-empty { grid-column: 1 / -1; min-height: 180px; padding: 30px; display: grid; place-items: center; align-content: center; color: var(--muted); background: var(--paper); border: 1px dashed #cbd3c7; border-radius: 14px; text-align: center; }
.library-empty p { margin: 7px 0 0; }
.material-card { min-width: 0; min-height: 390px; padding: 24px; display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 16px 44px rgba(39,55,47,.07); }
.material-card-top { display: flex; align-items: center; justify-content: space-between; }
.material-number { color: var(--green); font: 700 12px/1 ui-monospace,Consolas,monospace; letter-spacing: .08em; }
.favorite-button { width: 35px; height: 35px; color: #8a744a; background: #f5f2e8; border: 0; border-radius: 50%; font-size: 20px; }
.favorite-button.active { color: #8a5a09; background: #fff0c9; }
.material-subject { margin: 17px 0 7px; color: var(--green); font-size: 10px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.material-card h2 { margin: 0; overflow-wrap: anywhere; font: 500 22px/1.25 Georgia,"Times New Roman",serif; letter-spacing: -.02em; }
.material-excerpt { margin: 14px 0; display: -webkit-box; overflow: hidden; overflow-wrap: anywhere; color: var(--muted); font-size: 13px; line-height: 1.55; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.material-meta { margin-top: auto; display: flex; flex-wrap: wrap; gap: 9px 14px; color: var(--muted); font-size: 11px; }
.progress-track { height: 5px; margin: 15px 0; overflow: hidden; background: #e8ece5; border-radius: 999px; }
.progress-track span { height: 100%; display: block; background: linear-gradient(90deg,var(--green),var(--gold)); border-radius: inherit; }
.material-actions { display: flex; gap: 8px; }
.material-actions .primary-button,.material-actions .secondary-button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.material-actions .primary-button { flex: 1; }
.secondary-button { padding: 0 15px; color: var(--green-dark); background: var(--green-soft); border: 1px solid #c9ded3; border-radius: 8px; font-size: 13px; font-weight: 750; }

.sync-dialog { width: min(440px, calc(100% - 28px)); padding: 30px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.sync-dialog::backdrop { background: rgba(20,35,29,.48); backdrop-filter: blur(3px); }
.sync-dialog h2 { margin: 0 0 8px; font: 500 29px/1.2 Georgia,"Times New Roman",serif; }
.sync-dialog > p:not(.eyebrow) { color: var(--muted); line-height: 1.5; }
.sync-dialog form:not(.dialog-close-form) { display: grid; gap: 16px; }
.sync-dialog .primary-button { width: 100%; }
.dialog-close-form { position: absolute; right: 13px; top: 10px; }
.dialog-close-form button { width: 34px; height: 34px; color: var(--muted); background: transparent; border: 0; font-size: 25px; }
.sync-dialog .text-button { margin-top: 18px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .topic-list { display: none; }
  .text-button { margin-top: 0; }
  .study-area { padding: 24px 14px 50px; }
  .toolbar { gap:10px; }
  .question-card { padding: 28px 20px; border-radius: 12px; }
  .question-title { font-size: 20px; }
  .question-title.long-statement { padding: 15px 16px; font-size: 16px; }
  .swipe-hint { max-width:920px; min-height:48px; margin:14px auto 0; padding:10px 14px; display:flex; align-items:center; justify-content:center; gap:9px; color:var(--green-dark); background:var(--green-soft); border:1px solid #c9ded3; border-radius:999px; font-size:11px; font-weight:750; text-align:center; user-select:none; }
  .swipe-hint span { font-size:20px; line-height:1; animation:swipe-hint-up 1.7s ease-in-out infinite; }
  .swipe-hint.disabled { color:var(--muted); background:#e9ede4; border-color:var(--line); }
  .swipe-hint.disabled span { animation:none; }
  .question-card.swipe-out-up { animation:question-swipe-out-up .18s ease-in both; pointer-events:none; }
  .question-card.swipe-in-up { animation:question-swipe-in-up .22s ease-out both; }
  .card-actions { align-items: stretch; flex-direction: column; }
  .source { text-align: left; }
  .library-view { padding: 30px 14px 55px; }
  .library-hero { align-items: stretch; flex-direction: column; }
  .library-summary { align-self: flex-start; }
  .library-section-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .subject-grid { grid-template-columns: 1fr; }
  .subject-card { min-height: 215px; }
  .library-panel-heading { grid-template-columns: 1fr; gap: 15px; }
  .library-back-button { justify-self: start; }
  .library-toolbar { grid-template-columns: 1fr; padding: 15px; }
  .library-grid { grid-template-columns: 1fr; }
  .material-card { min-height: 0; }
}

@keyframes question-swipe-out-up {
  to { opacity:0; transform:translateY(-42px) scale(.985); }
}

@keyframes question-swipe-in-up {
  from { opacity:0; transform:translateY(34px) scale(.985); }
  to { opacity:1; transform:none; }
}

@keyframes swipe-hint-up {
  0%,100% { transform:translateY(2px); }
  50% { transform:translateY(-3px); }
}

@media (prefers-reduced-motion:reduce) {
  .swipe-hint span,.question-card.swipe-out-up,.question-card.swipe-in-up { animation:none; }
}

@media (max-width:480px) {
  .shuffle-button span { display:none; }
  .shuffle-button { width:36px; padding:0; }
  .nav-buttons { gap:7px; }
}

@media (min-width:821px) and (max-width:1180px) {
  .layout { grid-template-columns:280px minmax(0,1fr); }
}
