/* PhraseCoach — P·Double Learning "Editorial Field Notes" system */
:root {
  --ink: #1b1712;
  --ink-soft: #4f463c;
  --ink-faint: #8a7d6c;
  --paper: #f1e9da;
  --paper-2: #faf5ea;
  --paper-3: #fffdf8;
  --persimmon: #d8431f;
  --persimmon-deep: #b53314;
  --sage: #4f6b4d;
  --amber: #b07314;
  --line: #ddd1bd;
  --line-strong: #c4b69e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', sans-serif;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(27, 23, 18, 0.07) 1px, transparent 0),
    radial-gradient(900px 600px at 100% -10%, rgba(216, 67, 31, 0.10), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, rgba(79, 107, 77, 0.08), transparent 60%);
  background-size: 22px 22px, 100% 100%, 100% 100%;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--persimmon); color: var(--paper-3); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1240px; margin: 0 auto; padding: 56px 40px 96px;
  display: grid; grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  gap: 60px; align-items: start;
}
.rail { position: sticky; top: 40px; align-self: start; }
.content { min-width: 0; }

/* ---------- Brand / masthead ---------- */
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 38px; }
.brand .mark { width: 46px; height: 46px; flex-shrink: 0; }
.brand .wordmark {
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-soft); line-height: 1.4;
}
.brand .wordmark b { color: var(--ink); font-weight: 500; }

.kicker {
  font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: 0.28em;
  text-transform: uppercase; color: var(--persimmon);
  display: flex; align-items: center; gap: 10px; margin-bottom: 20px;
}
.kicker::before { content: ''; width: 28px; height: 2px; background: var(--persimmon); }

.masthead {
  font-family: 'Fraunces', serif; font-weight: 600;
  font-size: clamp(38px, 4.4vw, 56px); line-height: 0.98;
  letter-spacing: -0.02em; color: var(--ink); margin-bottom: 20px;
}
.masthead em { font-style: italic; font-weight: 500; color: var(--persimmon); }

.lede { font-size: 15px; line-height: 1.6; color: var(--ink-soft); max-width: 34ch; margin-bottom: 30px; }

.rail-stats { border-top: 1.5px solid var(--ink); padding-top: 16px; margin-bottom: 24px; }
.rail-stats .rs-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 2px; border-bottom: 1px solid var(--line);
}
.rail-stats .rs-label { font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); }
.rail-stats .rs-val { font-family: 'Fraunces', serif; font-size: 22px; font-weight: 600; color: var(--persimmon); }

.rail-foot { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-soft);
  border: 1px solid var(--line-strong); border-radius: 100px; padding: 5px 11px;
}

.note { color: var(--ink-soft); font-size: 13.5px; line-height: 1.55; margin-bottom: 16px; }

/* ---------- Module grid ---------- */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.module-card {
  cursor: pointer; text-align: left; padding: 18px 18px 16px; border-radius: 5px;
  border: 1.5px solid var(--line-strong); background: var(--paper-3);
  transition: all 0.16s ease; display: flex; flex-direction: column; gap: 8px;
  font-family: 'Inter', sans-serif; position: relative;
}
.module-card:hover { border-color: var(--ink); transform: translate(-2px, -2px); box-shadow: 5px 5px 0 rgba(216, 67, 31, 0.75); }
.module-card .mc-num {
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 30px; line-height: 1;
  color: var(--persimmon); opacity: 0.85;
}
.module-card .mc-title { font-family: 'Fraunces', serif; font-weight: 600; font-size: 18px; color: var(--ink); line-height: 1.15; }
.module-card .mc-desc { font-size: 12.5px; line-height: 1.45; color: var(--ink-soft); }
.module-card .mc-progress {
  margin-top: 4px; font-family: 'JetBrains Mono', monospace; font-size: 9.5px;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint);
}
.module-card .mc-progress b { color: var(--sage); font-weight: 500; }

/* ---------- Module view ---------- */
.back-btn {
  background: transparent; border: none; cursor: pointer; color: var(--ink-soft);
  font-family: 'JetBrains Mono', monospace; font-size: 12px; letter-spacing: 0.08em;
  text-transform: uppercase; padding: 6px 0; margin-bottom: 18px;
}
.back-btn:hover { color: var(--persimmon); }
.module-head { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: start; margin-bottom: 22px; }
.module-num { font-family: 'Fraunces', serif; font-weight: 600; font-size: 46px; line-height: 1; color: var(--persimmon); }
.module-title { font-family: 'Fraunces', serif; font-weight: 600; font-size: 28px; line-height: 1.1; color: var(--ink); margin-bottom: 6px; }
.module-desc { font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; max-width: 60ch; }

.mode-tabs { display: flex; gap: 10px; margin-bottom: 22px; border-bottom: 1.5px solid var(--line); padding-bottom: 14px; }
.mode-tab {
  cursor: pointer; padding: 11px 20px; border-radius: 100px; font-size: 14px; font-weight: 600;
  border: 1.5px solid var(--line-strong); background: var(--paper-3); color: var(--ink-soft);
  font-family: 'Inter', sans-serif; transition: all 0.15s;
}
.mode-tab:hover { border-color: var(--ink); color: var(--ink); }
.mode-tab.active { background: var(--ink); border-color: var(--ink); color: var(--paper-3); box-shadow: 4px 4px 0 rgba(216, 67, 31, 0.85); }

/* ---------- Coach output (heading-parsed cards) ---------- */
.coach-out { margin-bottom: 16px; }
.coach-card {
  background: var(--paper-3); border: 1.5px solid var(--line-strong); border-left: 5px solid var(--persimmon);
  border-radius: 4px; padding: 16px 18px; margin-bottom: 12px;
}
.coach-card h5 {
  font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--persimmon); margin-bottom: 8px;
}
.coach-card .coach-text { font-size: 15.5px; line-height: 1.7; color: var(--ink); white-space: pre-wrap; }
.coach-card.sage { border-left-color: var(--sage); }
.coach-card.sage h5 { color: var(--sage); }
.coach-card.amber { border-left-color: var(--amber); }
.coach-card.amber h5 { color: var(--amber); }

/* ---------- Forms & buttons ---------- */
.form-group { margin-bottom: 18px; }
label {
  display: block; margin-bottom: 9px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft);
}
input[type="text"], textarea {
  width: 100%; padding: 13px 15px; border: 1.5px solid var(--line-strong); border-radius: 3px;
  font-family: 'Inter', sans-serif; font-size: 15px; background: var(--paper-3); color: var(--ink);
  transition: border-color 0.16s, box-shadow 0.16s;
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input[type="text"]:focus, textarea:focus {
  outline: none; border-color: var(--ink); background: #fff; box-shadow: 4px 4px 0 rgba(216, 67, 31, 0.18);
}
textarea { resize: vertical; line-height: 1.55; }

.chip-group { display: flex; flex-wrap: wrap; gap: 10px; }
.chip-option input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.chip-option label {
  margin: 0; cursor: pointer; display: inline-flex; align-items: center;
  padding: 11px 18px; font-size: 14px; font-weight: 500; letter-spacing: 0;
  text-transform: none; color: var(--ink-soft); background: var(--paper-3);
  border: 1.5px solid var(--line-strong); border-radius: 100px; transition: all 0.16s ease;
}
.chip-option label:hover { border-color: var(--ink-soft); color: var(--ink); transform: translateY(-1px); }
.chip-option input[type="radio"]:checked + label {
  background: var(--ink); border-color: var(--ink); color: var(--paper-3);
  box-shadow: 4px 4px 0 rgba(216, 67, 31, 0.85);
}

.btn {
  padding: 15px 22px; border: none; border-radius: 3px; font-family: 'Inter', sans-serif;
  font-size: 14px; font-weight: 600; letter-spacing: 0.02em; cursor: pointer;
  transition: transform 0.14s, box-shadow 0.14s, background 0.16s;
}
.btn-primary { background: var(--persimmon); color: var(--paper-3); box-shadow: 5px 5px 0 var(--ink); }
.btn-primary:hover:not(:disabled) { background: var(--persimmon-deep); transform: translate(-2px, -2px); box-shadow: 7px 7px 0 var(--ink); }
.btn-primary:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.btn-secondary { background: var(--paper-3); color: var(--ink); border: 1.5px solid var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--ink); color: var(--paper-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.button-group { display: flex; gap: 12px; }
.button-group .btn { flex: 1; }

.spinner {
  display: inline-block; width: 16px; height: 16px; border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: var(--paper-3); border-radius: 50%; animation: spin 0.7s linear infinite;
  vertical-align: middle; margin-right: 8px;
}
.btn-secondary .spinner { border-color: rgba(27,23,18,0.25); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Roleplay chat ---------- */
.chat {
  background: var(--paper-2); border: 1.5px solid var(--line-strong); border-radius: 6px;
  padding: 18px; max-height: 440px; overflow-y: auto; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.bubble { max-width: 82%; padding: 12px 16px; border-radius: 12px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; }
.bubble.parent { align-self: flex-start; background: var(--paper-3); border: 1.5px solid var(--line-strong); border-bottom-left-radius: 3px; color: var(--ink); }
.bubble.teacher { align-self: flex-end; background: var(--ink); color: var(--paper-2); border-bottom-right-radius: 3px; }
.bubble .who {
  display: block; font-family: 'JetBrains Mono', monospace; font-size: 9px;
  letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 5px; opacity: 0.65;
}
.bubble.typing { color: var(--ink-faint); font-style: italic; }
.chat-input { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.chat-input textarea { min-height: 54px; }
.chat-input .btn { padding: 15px 26px; }

/* ---------- BookGym: setup ---------- */
.step-header { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 18px; margin-bottom: 20px; }
.step-number {
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 40px; line-height: 1;
  color: var(--persimmon); letter-spacing: -0.02em;
}
.step-number::before { content: '0'; opacity: 0.32; }
.step-title { font-family: 'Fraunces', serif; font-weight: 600; font-size: 25px; line-height: 1.1; color: var(--ink); align-self: center; }

.dropzone {
  border: 1.5px dashed var(--line-strong); border-radius: 4px; background: var(--paper-2);
  padding: 34px 20px; text-align: center; cursor: pointer; transition: all 0.16s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--persimmon); background: var(--paper-3); }
.dropzone .dz-icon { font-size: 30px; margin-bottom: 8px; }
.dropzone .dz-label { font-size: 15px; font-weight: 600; color: var(--ink); }
.dropzone .dz-hint { font-size: 12.5px; color: var(--ink-faint); margin-top: 4px; }

.chapter-row {
  display: grid; grid-template-columns: 1fr 90px 90px auto; gap: 10px; align-items: center;
  margin-bottom: 8px;
}
.chapter-row input { padding: 10px 12px; font-size: 14px; }
.chapter-row input.pg { font-family: 'JetBrains Mono', monospace; text-align: center; }
.chapter-row .remove {
  border: none; background: transparent; color: var(--ink-faint); font-size: 17px;
  cursor: pointer; padding: 8px; border-radius: 3px;
}
.chapter-row .remove:hover { color: var(--persimmon); }
.chapter-row-head {
  display: grid; grid-template-columns: 1fr 90px 90px auto; gap: 10px;
  font-family: 'JetBrains Mono', monospace; font-size: 9.5px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 6px; padding: 0 2px;
}

/* ---------- BookGym: training ---------- */
.gym-head { margin-bottom: 20px; }
.gym-chapter-row { display: flex; gap: 14px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.chapter-select {
  padding: 11px 14px; border: 1.5px solid var(--ink); border-radius: 3px; background: var(--paper-3);
  font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 600; color: var(--ink);
  min-width: 240px; cursor: pointer;
}

.word-card {
  background: var(--paper-3); border: 1.5px solid var(--line-strong); border-radius: 4px;
  padding: 14px 16px; margin-bottom: 10px;
}
.word-card .w-top { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.word-card .w-word { font-family: 'Fraunces', serif; font-weight: 600; font-size: 21px; color: var(--ink); }
.word-card .w-syll { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--persimmon); }
.word-card .w-stress { font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.word-card .w-meaning { font-size: 13.5px; color: var(--ink-soft); margin-top: 6px; line-height: 1.5; }
.word-card .w-tip { font-size: 12.5px; color: var(--sage); margin-top: 3px; }
.word-card .w-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.w-btn {
  border: 1.5px solid var(--ink); background: var(--paper-3); color: var(--ink);
  border-radius: 100px; padding: 8px 16px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; transition: all 0.15s; font-family: 'Inter', sans-serif;
}
.w-btn:hover:not(:disabled) { background: var(--ink); color: var(--paper-3); }
.w-btn.listening { background: var(--persimmon); border-color: var(--persimmon); color: var(--paper-3); animation: micPulse 1.2s ease-in-out infinite; }
@keyframes micPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(216, 67, 31, 0.45); } 50% { box-shadow: 0 0 0 9px rgba(216, 67, 31, 0); } }
.mic-result { font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.mic-result.ok { color: var(--sage); }
.mic-result.miss { color: var(--persimmon-deep); }

.vocab-practice { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.vocab-practice input { padding: 10px 12px; font-size: 14px; }
.vocab-verdict { margin-top: 8px; font-size: 13.5px; line-height: 1.55; color: var(--ink); white-space: pre-wrap; }

.sentence-card {
  background: var(--paper-3); border: 1.5px solid var(--line-strong); border-radius: 4px;
  padding: 14px 16px; margin-bottom: 10px;
}
.sentence-card .s-text { font-size: 16.5px; line-height: 1.6; color: var(--ink); font-family: 'Fraunces', serif; }
.sentence-card .s-heard { margin-top: 8px; font-size: 13px; line-height: 1.6; }
.sentence-card .s-heard .hit { color: var(--sage); }
.sentence-card .s-heard .missw { color: var(--persimmon-deep); text-decoration: underline wavy; }

.teach-bar { display: flex; gap: 14px; align-items: center; }
.teach-timer {
  font-family: 'JetBrains Mono', monospace; font-size: 26px; color: var(--ink);
  background: var(--paper-3); border: 1.5px solid var(--line-strong); border-radius: 4px;
  padding: 8px 18px; min-width: 110px; text-align: center;
}
.teach-timer.live { border-color: var(--persimmon); color: var(--persimmon); }

/* ---------- Toasts ---------- */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--paper-3); padding: 15px 20px; border-radius: 4px;
  box-shadow: 0 14px 34px rgba(27, 23, 18, 0.3); font-weight: 500; font-size: 14px;
  display: flex; align-items: center; gap: 12px; animation: slideIn 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
  pointer-events: auto; border-left: 4px solid var(--ink-faint); min-width: 280px;
}
.toast::before { font-weight: 700; font-size: 16px; }
.toast.success { border-left-color: #7fb487; } .toast.success::before { content: "\2713"; color: #7fb487; }
.toast.error { border-left-color: var(--persimmon); } .toast.error::before { content: "\2715"; color: var(--persimmon); }
.toast.warning { border-left-color: #e0a83a; } .toast.warning::before { content: "!"; color: #e0a83a; }
.toast.removing { animation: slideOut 0.3s ease-out forwards; }
@keyframes slideIn { from { transform: translateX(420px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(420px); } }

/* ---------- Login (ink cover) ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 24px;
  background-color: var(--ink);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(241, 233, 218, 0.06) 1px, transparent 0),
    radial-gradient(1000px 700px at 110% -10%, rgba(216, 67, 31, 0.32), transparent 55%),
    radial-gradient(800px 600px at -10% 110%, rgba(216, 67, 31, 0.14), transparent 55%);
  background-size: 24px 24px, 100% 100%, 100% 100%;
}
.login-screen.hidden { display: none; }
.login-box { width: 100%; max-width: 440px; color: var(--paper); }
.login-logo { width: 104px; height: 104px; margin-bottom: 24px; }
.login-box h2 {
  font-family: 'Fraunces', serif; font-weight: 600; font-size: clamp(40px, 6vw, 54px);
  line-height: 1.0; letter-spacing: -0.02em; margin-bottom: 16px; color: var(--paper-3);
}
.login-box h2 em { font-style: italic; font-weight: 500; color: var(--persimmon); }
.login-box > p { color: rgba(241, 233, 218, 0.7); font-size: 15px; margin-bottom: 30px; max-width: 38ch; }
.login-box input {
  width: 100%; padding: 16px 18px; border: 1.5px solid rgba(241, 233, 218, 0.25); border-radius: 3px;
  font-size: 16px; font-family: 'JetBrains Mono', monospace; letter-spacing: 0.1em; margin-bottom: 14px;
  background: rgba(241, 233, 218, 0.06); color: var(--paper-3); transition: all 0.16s;
}
.login-box input::placeholder { color: rgba(241, 233, 218, 0.4); letter-spacing: 0.05em; }
.login-box input:focus { outline: none; border-color: var(--persimmon); background: rgba(241, 233, 218, 0.1); box-shadow: 4px 4px 0 rgba(216, 67, 31, 0.4); }
.login-box button {
  width: 100%; padding: 16px; background: var(--persimmon); color: var(--paper-3); border: none; border-radius: 3px;
  font-family: 'Inter', sans-serif; font-size: 15px; font-weight: 600; letter-spacing: 0.04em; cursor: pointer;
  box-shadow: 5px 5px 0 rgba(241, 233, 218, 0.18); transition: transform 0.14s, box-shadow 0.14s, background 0.16s;
}
.login-box button:hover { background: var(--persimmon-deep); transform: translate(-2px, -2px); box-shadow: 7px 7px 0 rgba(241, 233, 218, 0.22); }
.login-error { color: #ff9b7d; font-size: 13px; margin-top: 14px; display: none; font-family: 'JetBrains Mono', monospace; }
.login-error.show { display: block; }

/* ---------- Entrance motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
.rail > *, .module-card { animation: rise 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.rail > *:nth-child(1) { animation-delay: 0.02s; }
.rail > *:nth-child(2) { animation-delay: 0.06s; }
.rail > *:nth-child(3) { animation-delay: 0.10s; }
.rail > *:nth-child(4) { animation-delay: 0.14s; }
.rail > *:nth-child(5) { animation-delay: 0.18s; }
.module-card:nth-child(1) { animation-delay: 0.10s; }
.module-card:nth-child(2) { animation-delay: 0.14s; }
.module-card:nth-child(3) { animation-delay: 0.18s; }
.module-card:nth-child(4) { animation-delay: 0.22s; }
.module-card:nth-child(5) { animation-delay: 0.26s; }
.module-card:nth-child(6) { animation-delay: 0.30s; }
.module-card:nth-child(7) { animation-delay: 0.34s; }
.module-card:nth-child(8) { animation-delay: 0.38s; }
.module-card:nth-child(9) { animation-delay: 0.42s; }

/* ---------- Responsive ---------- */
@media (max-width: 940px) {
  .layout { grid-template-columns: 1fr; gap: 36px; padding: 40px 28px 80px; }
  .rail { position: static; } .lede { max-width: none; }
}
@media (max-width: 560px) {
  .layout { padding: 32px 18px 64px; }
  .masthead { font-size: 40px; }
  .module-grid { grid-template-columns: 1fr; }
  .mode-tabs { flex-wrap: wrap; }
  .button-group { flex-direction: column; }
  .chat { max-height: 50vh; }
  input[type="text"], textarea { font-size: 16px; }
  .toast-container { left: 16px; right: 16px; bottom: 16px; } .toast { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
