/* ================= CE560 Ultra Study App ================= */
:root {
  --bg: #10141b;
  --bg2: #171d27;
  --card: #1d2532;
  --card2: #232d3d;
  --line: #324056;
  --text: #e8ecf3;
  --dim: #9aa7ba;
  --accent: #4da3ff;
  --accent2: #2f7fd4;
  --amber: #ffb300;
  --red: #ff3b30;
  --white-lamp: #f5f7fa;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
}

/* ---------- Header ---------- */
.topbar {
  background: linear-gradient(180deg, #1a2230, #141a24);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px 0;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 1.9rem; color: var(--accent); }
.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: .5px; }
.brand .sub { margin: 2px 0 10px; color: var(--dim); font-size: .8rem; }
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent; color: var(--dim); border: none;
  border-bottom: 3px solid transparent;
  padding: 8px 18px 10px; font-size: .95rem; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-panel { display: none; padding: 18px; max-width: 1200px; margin: 0 auto; }
.tab-panel.active { display: block; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--card2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 16px; font-size: .92rem; cursor: pointer;
  transition: background .15s, border-color .15s;
  text-decoration: none; display: inline-block;
}
.btn:hover { background: #2b374a; border-color: #45566f; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); font-weight: 600; }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.small { padding: 5px 12px; font-size: .82rem; }
.btn.ghost { background: transparent; }
.btn.schematic-btn { margin-top: 12px; background: #24344a; border-color: #38507a; }
.btn.schematic-btn:hover { background: #2d415d; }
.btn.mode.active { background: var(--accent2); border-color: var(--accent2); font-weight: 600; }

/* ---------- Quiz ---------- */
.quiz-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px; padding: 10px 12px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
}
.quiz-toolbar label { color: var(--dim); font-size: .9rem; }
.quiz-toolbar select {
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: .9rem;
}
.count { color: var(--dim); font-size: .85rem; }
.spacer { flex: 1; }

.quiz-pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-bottom: 14px; padding: 8px 12px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
}
.quiz-pager .count { min-width: 150px; text-align: center; }

.quiz-list { display: flex; flex-direction: column; gap: 12px; }
.qcard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px 18px;
}
.qcard .sys-chip {
  display: inline-block; font-size: .7rem; text-transform: uppercase; letter-spacing: 1px;
  background: #23344c; color: var(--accent); border-radius: 20px;
  padding: 2px 10px; margin-bottom: 8px;
}
.qcard h2 { margin: 0 0 12px; font-size: 1.02rem; font-weight: 600; }
.answer {
  border-top: 1px dashed var(--line);
  margin-top: 12px; padding-top: 12px;
  animation: fadeIn .2s ease;
}
.answer h3 {
  margin: 0 0 4px; font-size: .72rem; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--accent);
}
.answer p { margin: 0 0 12px; color: #d6dde8; font-size: .95rem; }
.answer p:last-child { margin-bottom: 0; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px);} to { opacity: 1; transform: none; } }

/* ---------- Enumerated lists inside answers ---------- */
.enum-list { margin: 8px 0 0; padding-left: 26px; }
.enum-list li { margin: 5px 0; color: #d6dde8; }

/* ---------- Annunciator conditions ---------- */
.answer-btns { display: flex; flex-wrap: wrap; gap: 10px; }
.cond-panel {
  margin-top: 14px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px;
}
.cond-block { margin-bottom: 12px; }
.cond-block:last-of-type { margin-bottom: 0; }
.cond-title {
  font-size: .72rem; font-weight: 700; letter-spacing: 1px;
  color: var(--amber); text-transform: uppercase; margin: 10px 0 4px;
}
.cond-list { margin: 4px 0 0; padding-left: 22px; }
.cond-list li { margin: 4px 0; font-size: .9rem; color: #d6dde8; }
.cond-note {
  margin: 12px 0 0; padding-top: 10px; border-top: 1px dashed var(--line);
  font-size: .82rem; color: var(--dim); font-style: italic;
}

/* ---------- Quiz lock ---------- */
.lock-card {
  max-width: 460px; margin: 48px auto; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px 28px;
}
.lock-icon { font-size: 2.2rem; margin-bottom: 8px; }
.lock-card h2 { margin: 0 0 8px; font-size: 1.1rem; }
.lock-card p { color: var(--dim); font-size: .9rem; margin: 0 0 18px; }
.lock-card form { display: flex; gap: 8px; justify-content: center; }
.lock-card input {
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; font-size: .95rem; width: 200px;
}
.lock-card input:focus { outline: 1px solid var(--accent); }
.lock-error { color: #ff6b62 !important; margin-top: 12px !important; }

/* ---------- Schematic modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 8, 12, .82);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  width: min(1150px, 100%); max-height: 94vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1rem; }
.modal-actions { display: flex; gap: 8px; }
.modal-body { overflow: auto; padding: 14px; }
.sch-wrap { position: relative; width: 100%; max-width: none; }
.sch-wrap img { width: 100%; height: auto; display: block; border-radius: 8px; background: #fff; }
.hl-box {
  position: absolute; border: 3px solid #e5205a; border-radius: 6px;
  box-shadow: 0 0 0 2px rgba(229, 32, 90, .25), 0 0 18px rgba(229, 32, 90, .55);
  pointer-events: none;
  animation: pulse 1.6s ease-in-out infinite;
}
.hl-box .hl-tag {
  position: absolute; top: -22px; left: -3px;
  background: #e5205a; color: #fff; font-size: .68rem; font-weight: 700;
  padding: 1px 7px; border-radius: 4px; white-space: nowrap;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
.hl-box.tag-below .hl-tag { top: auto; bottom: -22px; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(229,32,90,.25), 0 0 14px rgba(229,32,90,.45); }
  50% { box-shadow: 0 0 0 4px rgba(229,32,90,.35), 0 0 26px rgba(229,32,90,.75); }
}
.hl-hidden .hl-box { display: none; }
.sch-legend { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.sch-legend .leg {
  font-size: .8rem; color: #f1d9e1;
  background: #3a1b28; border: 1px solid #7a2f49; border-radius: 20px; padding: 3px 12px;
}

/* ---------- Annunciator panel ---------- */
.ann-layout { display: flex; flex-direction: column; gap: 18px; }
.panel-wrap {
  background: #22262b;
  border: 1px solid #3a4048; border-radius: 14px; padding: 18px;
}
.glareshield {
  display: flex; justify-content: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
}
.gs-lamp {
  min-width: 92px; text-align: center;
  background: #0c0d0f; border: 2px solid #43474d; border-radius: 6px;
  padding: 7px 10px; font-size: .68rem; font-weight: 700; letter-spacing: .5px;
  color: #565b63; text-transform: uppercase; line-height: 1.25;
  user-select: none;
}
.gs-lamp.lit.red { color: #ff2d23; text-shadow: 0 0 12px rgba(255,45,35,.9); border-color: #8a2622; background: #1c0806; }
.gs-lamp.lit.white { color: #ffffff; text-shadow: 0 0 12px rgba(255,255,255,.8); border-color: #7d829a; background: #17181c; }

.ann-panel {
  display: grid; grid-template-columns: repeat(9, 1fr); gap: 7px;
  background: #0b0c0e; border: 3px solid #2c2f34; border-radius: 10px;
  padding: 12px; max-width: 1080px; margin: 0 auto;
}
.ann-cell {
  background: #050607; border: 1.5px solid #4a4f56; border-radius: 7px;
  min-height: 86px; padding: 6px 4px;
  display: flex; flex-direction: column; justify-content: space-between;
  cursor: pointer; user-select: none;
  transition: border-color .12s;
}
.ann-cell:hover { border-color: #6b7380; }
.lamp { text-align: center; }
.lamp .legend {
  font-size: .62rem; font-weight: 700; letter-spacing: .3px; line-height: 1.3;
  color: #565b63; text-transform: uppercase;
}
.lamp .lr {
  display: flex; justify-content: space-around; margin-top: 4px;
  font-size: .6rem; font-weight: 700; color: #565b63;
}
.ann-cell:hover .legend, .lamp:focus-visible .legend { color: #8a919c; }
.lamp:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.lamp .bar {
  height: 5px; border-radius: 3px; background: #26282c; margin: 6px 14px 2px;
}
/* lit states */
.lamp.lit-any.amber .legend { color: var(--amber); text-shadow: 0 0 10px rgba(255,179,0,.85); }
.lamp.lit-any.red .legend { color: #ff2d23; text-shadow: 0 0 10px rgba(255,45,35,.9); }
.lamp.lit-any.white .legend { color: #fff; text-shadow: 0 0 10px rgba(255,255,255,.85); }
.lamp.lit-any.amber .bar { background: var(--amber); box-shadow: 0 0 10px rgba(255,179,0,.85); }
.lamp.lit-any.red .bar { background: #ff2d23; box-shadow: 0 0 10px rgba(255,45,35,.9); }
.lamp.lit-any.white .bar { background: #fff; box-shadow: 0 0 10px rgba(255,255,255,.85); }
.lamp .lr .side { opacity: 1; }
.lamp.amber .lr .side.lit { color: var(--amber); text-shadow: 0 0 8px rgba(255,179,0,.9); }
.lamp.red .lr .side.lit { color: #ff2d23; text-shadow: 0 0 8px rgba(255,45,35,.95); }

.panel-hint { color: var(--dim); font-size: .8rem; text-align: center; margin: 12px 0 0; }
.panel-hint a { color: var(--accent); }

.lamp-info {
  max-width: 720px; margin: 12px auto 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; font-size: .9rem;
}
.lamp-info b { color: var(--amber); }

/* ---------- Scenario box ---------- */
.scenario-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px;
}
.scenario-nav { display: flex; gap: 8px; margin-bottom: 12px; }
.scenario-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.scenario-q { font-size: 1.05rem; margin: 6px 0 14px; }
#scenarioArea .answer { border-top: 1px dashed var(--line); }

/* ---------- Footer ---------- */
.foot { text-align: center; color: #5c6980; font-size: .75rem; padding: 24px 16px; }
.foot p { color: #5f6b80; margin: 0; }

@media (max-width: 760px) {
  .ann-panel { grid-template-columns: repeat(9, minmax(64px, 1fr)); overflow-x: auto; }
  .panel-wrap { overflow-x: auto; }
}
