/* Homework Mode overlay — matches the rune-frame menus in style.css
   (uses its :root palette with fallbacks so it also works standalone). */
.hw-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 20% 20%, rgba(110, 181, 255, 0.10), transparent 40%),
    radial-gradient(circle at 80% 85%, rgba(232, 197, 71, 0.10), transparent 45%),
    rgba(4, 7, 12, 0.82);
  color: var(--ink, #e8eef8);
  font-family: "Rajdhani", system-ui, sans-serif;
  pointer-events: auto;
  box-sizing: border-box;
}
.hw-overlay.hidden,
.hw-overlay .hidden { display: none !important; }
.hw-overlay * { box-sizing: border-box; }

html.hw-open .touch-controls,
html.hw-open .fs-float,
html.hw-open .interact-hint { visibility: hidden; pointer-events: none; }

.hw-modal {
  position: relative;
  width: min(760px, 96vw);
  max-height: min(94vh, 94dvh);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px 22px 18px;
  text-align: left;
  /* rune-frame look (also inherited from style.css when present) */
  background: linear-gradient(180deg, rgba(16, 24, 42, 0.97), rgba(8, 10, 18, 0.98));
  border: 1px solid rgba(232, 197, 71, 0.45);
  box-shadow: 0 0 0 6px rgba(12, 18, 32, 0.8), 0 0 40px rgba(78, 205, 196, 0.12), inset 0 0 40px rgba(110, 181, 255, 0.05);
}

.hw-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.hw-head h2 {
  flex: 1;
  margin: 0;
  font-family: "Cinzel", Georgia, serif;
  font-weight: 800;
  font-size: clamp(22px, 4.2vw, 32px);
  color: var(--gold, #e8c547);
  text-shadow: 0 0 18px rgba(232, 197, 71, 0.3);
}
.hw-icon-btn {
  cursor: pointer;
  min-width: 40px;
  min-height: 40px;
  padding: 4px 10px;
  border: 1px solid rgba(232, 197, 71, 0.35);
  background: rgba(18, 26, 44, 0.9);
  color: var(--ink, #e8eef8);
  font-size: 18px;
  line-height: 1;
}
.hw-icon-btn:hover, .hw-icon-btn:focus-visible { border-color: var(--gold, #e8c547); outline: none; }

.hw-lead {
  margin: 2px 0 12px;
  font-size: clamp(16px, 2.6vw, 19px);
  color: #cfd8e6;
}
.hw-small { color: var(--muted, #8b97ad); font-size: 14px; line-height: 1.4; margin: 0 0 12px; }
.hw-sub {
  font-family: "Cinzel", Georgia, serif;
  color: var(--glow, #4ecdc4);
  font-size: 18px;
  margin: 4px 0 8px;
}

/* —— photo picker —— */
.hw-drop {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 150px;
  max-height: 42vh;
  margin-bottom: 12px;
  border: 2px dashed rgba(110, 181, 255, 0.35);
  background: rgba(12, 18, 32, 0.6);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.hw-drop.over, .hw-drop:focus-visible {
  border-color: var(--gold, #e8c547);
  box-shadow: 0 0 18px rgba(232, 197, 71, 0.25);
  outline: none;
}
.hw-drop-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px; color: var(--muted, #8b97ad); text-align: center; }
.hw-drop-icon { font-size: 40px; }
.hw-preview { display: block; max-width: 100%; max-height: 42vh; object-fit: contain; background: #fff; }

.hw-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.hw-actions { justify-content: flex-end; margin-top: 12px; }
.hw-overlay .cta { padding: 12px 20px; font-size: 15px; min-height: 44px; }
.hw-overlay .cta[disabled] { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.4); }
.hw-file-btn { position: relative; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.hw-file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.hw-reader-line { margin: 12px 0 0; font-size: 15px; color: var(--muted, #8b97ad); }
.hw-reader-line.ai { color: #86efac; }
.hw-reader-line.offline { color: #f5d77a; }
.hw-error {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-left: 3px solid #f87171;
  background: rgba(139, 58, 42, 0.25);
  color: #fecaca;
  font-size: 15px;
}

/* —— reading —— */
.hw-step[data-step="reading"] { text-align: center; padding: 22px 0 10px; }
.hw-rune-spin {
  display: inline-block;
  font-family: "Cinzel", Georgia, serif;
  font-size: 58px;
  color: var(--glow, #4ecdc4);
  text-shadow: 0 0 24px rgba(78, 205, 196, 0.6);
  animation: hw-spin 2.4s linear infinite;
}
@keyframes hw-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .hw-rune-spin { animation: none; } }
.hw-reading-text { margin: 12px 0; font-size: 18px; }
.hw-bar { height: 10px; margin: 0 auto; width: min(420px, 90%); background: #121a2c; border: 1px solid rgba(110, 181, 255, 0.25); }
.hw-bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, #2aa89f, #7ee7df); transition: width 0.25s; }

/* —— review —— */
.hw-badge {
  margin: 0 0 10px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 15px;
  border: 1px solid;
}
.hw-badge.ai { color: #bbf7d0; border-color: rgba(134, 239, 172, 0.45); background: rgba(22, 101, 52, 0.25); }
.hw-badge.offline { color: #fde68a; border-color: rgba(232, 197, 71, 0.5); background: rgba(120, 90, 20, 0.25); }
.hw-badge.manual { color: #c4b5fd; border-color: rgba(196, 181, 253, 0.4); background: rgba(76, 29, 149, 0.2); }
.hw-meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 6px; }
.hw-inline-field { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.hw-topic-guess { color: var(--glow, #4ecdc4); font-weight: 600; }
.hw-review-tip { margin: 2px 0 10px; color: var(--muted, #8b97ad); font-size: 14px; }

.hw-qlist { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.hw-q {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 8px;
  background: #121a2c;
  border: 1px solid rgba(110, 181, 255, 0.2);
}
.hw-q:focus-within { border-color: rgba(232, 197, 71, 0.6); }
.hw-q-num {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-top: 4px;
  font-family: "Cinzel", Georgia, serif;
  font-weight: 800;
  color: #0a0e18;
  background: var(--gold, #e8c547);
}
.hw-q-main { display: grid; gap: 6px; min-width: 0; }
.hw-q-answer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.hw-eq { color: var(--muted, #8b97ad); font-weight: 700; font-size: 14px; }
.hw-q-note { color: var(--muted, #8b97ad); font-size: 13px; min-height: 0; }
.hw-q-note:empty { display: none; }
.hw-q-note.warn { color: #fbbf24; }
.hw-empty { padding: 14px; color: var(--muted, #8b97ad); text-align: center; border: 1px dashed rgba(110, 181, 255, 0.25); }
.hw-notes { margin: 6px 0 0; font-size: 14px; color: #cbd5e1; }

.hw-chip { display: inline-block; padding: 2px 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.03em; border: 1px solid; white-space: nowrap; }
.hw-chip.hw-ok { color: #86efac; border-color: rgba(134, 239, 172, 0.45); }
.hw-chip.hw-warn { color: #fbbf24; border-color: rgba(251, 191, 36, 0.5); }
.hw-chip.hw-info { color: var(--ice, #6eb5ff); border-color: rgba(110, 181, 255, 0.45); }

/* —— form controls (style.css sets user-select:none on body) —— */
.hw-overlay input,
.hw-overlay textarea,
.hw-overlay select {
  -webkit-user-select: text;
  user-select: text;
  font-family: "Rajdhani", system-ui, sans-serif;
  font-size: 17px; /* ≥16px stops iOS zoom-on-focus */
  font-weight: 600;
  color: var(--ink, #e8eef8);
  background: #0b1120;
  border: 1px solid rgba(110, 181, 255, 0.3);
  padding: 7px 10px;
  border-radius: 0;
  min-height: 40px;
}
.hw-overlay textarea { width: 100%; resize: vertical; line-height: 1.3; }
.hw-q-answer { width: 9.5em; max-width: 100%; }
.hw-overlay input:focus,
.hw-overlay textarea:focus,
.hw-overlay select:focus { outline: none; border-color: var(--gold, #e8c547); box-shadow: 0 0 10px rgba(232, 197, 71, 0.2); }

.hw-field { display: grid; gap: 4px; margin-bottom: 10px; }
.hw-field > span { font-weight: 700; color: #cbd5e1; font-size: 14px; letter-spacing: 0.04em; }
.hw-field input, .hw-field select { width: 100%; }
.hw-settings-status { min-height: 1.3em; margin: 4px 0 0; color: #cbd5e1; font-size: 15px; }

/* —— small / landscape phones —— */
@media (max-height: 520px) {
  .hw-modal { padding: 10px 14px 12px; max-height: 98vh; max-height: 98dvh; }
  .hw-head h2 { font-size: 22px; }
  .hw-lead { margin-bottom: 8px; font-size: 15px; }
  .hw-drop { min-height: 90px; max-height: 34vh; }
  .hw-preview { max-height: 34vh; }
  .hw-overlay .cta { padding: 9px 14px; min-height: 40px; }
  .hw-actions { margin-top: 8px; }
}
@media (max-width: 520px) {
  .hw-q { grid-template-columns: 26px 1fr auto; padding: 6px; }
  .hw-actions .cta { flex: 1 1 auto; }
}

/* Title menu: keep "Homework Level" the same width as the other title buttons (min-width 220px). */
.title-actions #btn-homework {
  padding-left: 16px;
  padding-right: 16px;
  white-space: nowrap;
}
