:root{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#192b25;background:#e8eee8;font-size:16px;line-height:1.5;color-scheme:light}*{box-sizing:border-box}body{margin:0;padding:30px 12px}main{max-width:440px;margin:auto;background:#f7f8f5;border:1px solid #d9e2d9;border-radius:26px;padding:26px;box-shadow:0 15px 50px #192b2510}header,footer{display:flex;align-items:center;justify-content:space-between;gap:10px}h1{font-size:24px;margin:0;font-weight:650}h2{font-weight:600;font-size:30px;line-height:1.2;margin:20px 0}small,.context,.muted,.fine{font-size:12px;color:#526359}.fine{margin-top:24px}button{font:inherit;color:inherit;cursor:pointer;background:#e8eee8;border:1px solid #d5dfd5;border-radius:12px;min-height:46px;padding:10px 12px}button:hover{background:#dce7dd}button:disabled{opacity:.5;cursor:wait}.primary{background:#245b46;color:white;border-color:#245b46;width:100%}.primary:hover{background:#194735}button:focus-visible,textarea:focus-visible,summary:focus-visible{outline:3px solid #ad7827;outline-offset:3px}.badge{display:inline-block;font-size:12px;padding:4px 8px;background:#e8eee8;border-radius:7px}.question{padding:24px 0 20px}.question h2{font-size:28px;overflow-wrap:anywhere}.question p{margin:8px 0}textarea{width:100%;min-height:90px;resize:vertical;font:inherit;font-size:16px;background:#fff;color:#192b25;border:1px solid #7e9083;border-radius:12px;padding:12px;margin:8px 0 12px}.actions{display:grid;grid-template-columns:1fr;gap:8px}.solution{border-top:1px solid #d5dfd5;margin-top:20px;padding-top:14px}#solution{font-size:24px;font-weight:500;overflow-wrap:anywhere}fieldset{margin:18px 0 8px;border:0;padding:0}legend{margin-bottom:8px}.grades{display:grid;grid-template-columns:repeat(5,1fr);gap:7px}.grades button{padding:10px 0}details{font-size:13px;color:#526359}details summary{cursor:pointer;min-height:32px}footer{border-top:1px solid #d5dfd5;padding-top:16px;margin-top:20px}#count{font-size:13px}.stat{display:flex;justify-content:space-between;border-bottom:1px solid #d5dfd5;padding:6px 0}#error{background:#fff0ed;color:#8c2013;border:1px solid #e4b8ae;border-radius:10px;padding:12px}[hidden]{display:none!important}@media(max-width:380px){body{padding:8px}main{padding:18px;border-radius:18px}header{align-items:flex-start}.question h2{font-size:24px}}@media(prefers-color-scheme:dark){:root{background:#101b16;color:#e8f1e9;color-scheme:dark}main{background:#19261f;border-color:#35473b}small,.context,.muted,.fine,details{color:#bacabe}.badge,button{background:#2d4033;color:#e8f1e9;border-color:#435a49}button:hover{background:#395442}.primary{background:#add9bd;color:#163524;border-color:#add9bd}.primary:hover{background:#c6e9d1}textarea{background:#111e16;color:#e8f1e9;border-color:#6d8876}.solution,footer,.stat{border-color:#435a49}}

input[type=email]{width:100%;padding:12px;font:inherit;border:1px solid #7e9083;border-radius:12px;margin:8px 0 16px}#account{font-size:12px;overflow-wrap:anywhere;margin-bottom:16px}input:focus-visible{outline:3px solid #ad7827;outline-offset:3px}

/* Pastel study controls, shared by light and dark themes. */
#reveal{width:100%;background:#f1c4bd;color:#492720;border-color:#dda49a;font-weight:600}
#reveal:hover{background:#eab1a8}
.grades button{font-weight:650;color:#20352b}
.grades [data-grade="1"]{background:#c5e3cc;border-color:#99c6a4}
.grades [data-grade="2"]{background:#c7dff0;border-color:#9bbfd9;color:#243b4b}
.grades [data-grade="3"]{background:#f4e6ae;border-color:#d7c47d;color:#473c1b}
.grades [data-grade="4"]{background:#f2d0ac;border-color:#dbaf7f;color:#4c3420}
.grades [data-grade="5"]{background:#efbfbd;border-color:#d89b98;color:#4e2625}
.grades button:hover{filter:brightness(.94)}

/* Give the active exercise the full mobile viewport. Longer content can scroll. */
@media (max-width: 600px), (max-height: 500px) and (pointer: coarse) {
  body.in-lesson { padding: 0; }
  .in-lesson main {
    display: flex;
    flex-direction: column;
    max-width: 600px;
    height: 100dvh;
    padding: 8px 14px max(6px, env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
  }
  .in-lesson :is(header, .context, #account, .fine) { display: none; }
  .in-lesson #study, .in-lesson #empty { overflow-y: auto; min-height: 0; }
  .in-lesson .question { padding: 0 0 5px; }
  .in-lesson .question h2 { margin: 6px 0; }
  .in-lesson .question p { margin: 2px 0; }
  .in-lesson label, .in-lesson legend { font-size: 14px; }
  .in-lesson textarea {
    display: block;
    height: 42px;
    min-height: 42px;
    margin: 3px 0 6px;
    padding: 7px 10px;
  }
  .in-lesson button { min-height: 40px; padding: 5px 10px; }
  .in-lesson .solution { margin-top: 6px; padding-top: 4px; }
  .in-lesson #solution { font-size: 22px; line-height: 1.2; }
  .in-lesson fieldset { margin: 6px 0 3px; }
  .in-lesson legend { margin-bottom: 3px; }
  .in-lesson details summary { min-height: 24px; }
  .in-lesson footer { flex-shrink: 0; padding-top: 4px; margin-top: 6px; }
  .in-lesson #save-status { margin: 3px 0 0; }
}

#grammar-question { min-height: 48px; height: 48px; }
#grammar-response { white-space: pre-wrap; line-height: 1.45; }
#grammar-response:empty { display: none; }
@media (max-width: 600px), (max-height: 500px) and (pointer: coarse) {
 .in-lesson main { height: auto; min-height: 100dvh; }
 .in-lesson #study, .in-lesson #empty { overflow-y: visible; }
}

#lesson-footer { align-items: flex-start; }
.lesson-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; margin-left: auto; min-width: 0; }
.lesson-actions button { max-width: 100%; }
#next-help { margin: 4px 0 0; }
#grammar-response { overflow-wrap: anywhere; }
@media (max-width:600px) {
 .in-lesson #lesson-footer {
  position: sticky; bottom: 0; z-index: 2;
  background: #f7f8f5; padding: 8px 0 max(6px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: minmax(0,1fr);
 }
 .in-lesson .lesson-actions { width: 100%; }
}
@media (max-width:600px) and (prefers-color-scheme:dark) {
 .in-lesson #lesson-footer { background: #19261f; }
}

#start { margin-top: 16px; }

#manage-vocabulary { margin-top: 12px; width: 100%; }
.in-admin main { max-width: 1000px; }
.vocabulary-new { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.vocabulary-table { overflow-x: auto; }
.vocabulary-table table { width: 100%; border-collapse: collapse; }
.vocabulary-table th { text-align: left; padding: 8px 4px; }
.vocabulary-table td { vertical-align: top; padding: 4px; border-top: 1px solid #7e9083; }
.vocabulary-table textarea { min-height: 76px; margin: 0; }
.vocabulary-actions { width: 90px; }
.vocabulary-actions button { display: block; width: 100%; margin-bottom: 6px; }
#vocabulary-search { width: 100%; padding: 10px; font: inherit; border-radius: 8px; }
.admin-error { color: #b43b35; }
@media(max-width:600px) {
 .in-admin main { padding: 14px; }
 .vocabulary-table td { padding: 3px; }
 .vocabulary-table textarea { padding: 6px; }
 .vocabulary-actions { width: 65px; }
 .vocabulary-actions button { padding: 5px; font-size: 13px; }
}

#selection-add { position: fixed; z-index: 20; box-shadow: 0 3px 14px #0004; }
#selection-dialog { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 20px; border: 1px solid #7e9083; border-radius: 18px; background: #f7f8f5; color: #192b25; }
#selection-dialog::backdrop { background: #0007; }
#selection-dialog h2 { margin: 0 0 16px; font-size: 24px; }
#selection-dialog textarea { min-height: 64px; height: 64px; }
.selection-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media(prefers-color-scheme:dark) { #selection-dialog { background: #19261f; color: #e8f1e9; } }

#manage-vocabulary { margin-bottom: 20px; }

.lesson-mode-row { display: flex; align-items: center; gap: 10px; width: 100%; }
.lesson-mode-row label { flex: 0 0 auto; }
#mode { flex: 1 1 0; min-width: 0; width: 100%; font: inherit; font-size: 16px; line-height: 1.4; min-height: 42px; padding: 8px 10px; border: 1px solid #7e9083; border-radius: 10px; }
@media (max-width: 480px) { .lesson-mode-row { flex-wrap: wrap; } #mode { flex-basis: 100%; } }

#language-switcher {display:flex;gap:6px;align-items:center;margin-left:auto;flex-shrink:0;}
#language-switcher[hidden] {display:none;}
#language-switcher button {font-size:25px;line-height:1;min-width:44px;min-height:44px;padding:7px;border-radius:10px;}

#last-summary:not(:empty) { margin-top: 32px; }
#last-summary > h3 { margin: 0 0 4px; }
.practice-heading { margin-bottom: 4px; }
.practice-list { margin-top: 4px; }
.fine { text-align: center; }

.fine > span { display: block; }
.fine > span + span { margin-top: 6px; }

#lesson-info { min-width: 0; overflow-wrap: anywhere; }
#lesson-info #save-status { margin: 12px 0 0; }

#sentence:not([hidden]) + #grammar-help { margin-top: 28px; }

.ai-progress { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid #7e9083; border-radius: 10px; }
.ai-progress::before { content: ''; width: 16px; height: 16px; flex: 0 0 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: ai-progress-spin 1s linear infinite; }
@keyframes ai-progress-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ai-progress::before { animation: none; } }

#vocabulary-import { margin: 24px 0; padding: 16px 0; border-top: 1px solid #7e9083; border-bottom: 1px solid #7e9083; }
#import-text { min-height: 150px; }
.import-pair { margin: 16px 0; padding: 12px; border: 1px solid #7e9083; border-radius: 12px; }
.import-pair textarea { min-height: 60px; height: 60px; }
.import-pair p { overflow-wrap: anywhere; }
#pair-settings label, #pair-settings select { display:block; width:100%; margin:8px 0; }

.import-actions { display:flex; flex-wrap:wrap; align-items:center; gap:12px 20px; }

.import-actions button { max-width:100%; white-space:normal; overflow-wrap:anywhere; }

.vocabulary-section-heading { margin-top:28px; margin-bottom:14px; }
#vocabulary-add button { max-width:100%; white-space:normal; overflow-wrap:anywhere; }

#dictionary-actions { display:flex; gap:12px; margin:12px 0; }
#dictionary-actions[hidden] { display:none; }
#dictionary-actions button { flex:1; margin:0; width:auto; }
#active-dictionary { margin:8px 0 20px; }
#dictionary-dialog { width:min(560px, calc(100% - 32px)); box-sizing:border-box; max-height:90dvh; overflow:auto; background:#192b21; color:#e4ede7; border:1px solid #668772; border-radius:16px; padding:24px; }
#dictionary-dialog::backdrop { background:#0009; }
#dictionary-dialog select { display:block; width:100%; margin:8px 0 16px; font:inherit; }
#dictionary-dialog h3 { margin-top:28px; }
@media(max-width:420px){#dictionary-actions{flex-direction:column;}}

textarea { overflow-y:hidden; resize:none; max-height:none; }

.correct-translation { margin:12px 0 18px; padding:12px 14px; border-radius:12px; background:#e0eef8; color:#254d69; border:1px solid #b9d5e8; overflow-wrap:anywhere; }
.correct-translation strong { display:block; margin-bottom:5px; font-size:.9em; }
#correct-translation-text { white-space:pre-wrap; }
@media(prefers-color-scheme:dark){.correct-translation { background:#243b43; color:#badcf4; border-color:#476574; }}
