:root {
  --bg: #0f1115;
  --panel: #151821;
  --text: #e6edf3;
  --muted: #9aa4b2;
  --primary: #5c7cfa;
  --danger: #ef6b73;
  --ok: #3dd68c;
  --border: #242938;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 600px at 20% -10%, #1a1f2d, var(--bg));
}

#app { max-width: 1100px; margin: 0 auto; padding: 16px; }

.app-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.app-header h1 { margin: 8px 0; font-size: 20px; }
.tabs { display: flex; gap: 8px; }
.tab-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.tab-btn.active { border-color: var(--primary); color: #fff; box-shadow: 0 0 0 2px color-mix(in lch, var(--primary) 35%, transparent); }

main { margin-top: 12px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.manage-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
.units { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.units-header { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px; }
.unit-list { list-style: none; padding: 0; margin: 0; max-height: 60vh; overflow: auto; }
.unit-list li { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.unit-list li .meta { color: var(--muted); font-size: 12px; }
.unit-list li.active { border-color: var(--primary); background: #171b26; }

.unit-editor { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-height: 400px; }
.row { display: flex; gap: 12px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.left, .right { display: flex; gap: 8px; align-items: center; }
.bold { font-weight: 600; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.input, .textarea {
  width: 100%;
  background: #0f131c;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
}
.textarea { min-height: 250px; resize: vertical; }

.btn { background: #161a24; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.btn.primary { background: color-mix(in lch, var(--primary) 25%, #161a24); border-color: var(--primary); }
.btn.danger { background: color-mix(in lch, var(--danger) 25%, #161a24); border-color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.file-label { position: relative; overflow: hidden; }
.file-label input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices .choice { background: #0f131c; border: 1px solid var(--border); padding: 6px 10px; border-radius: 999px; }

.quiz-area { margin-top: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; position: relative; overflow: hidden; }
.stats { display: flex; gap: 16px; color: var(--muted); }
.prompt { margin: 12px 0 8px; font-size: 18px; min-height: 28px; }
.input-wrap { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; position: relative; }
.answer-input {
  min-height: 42px;
  background: #0f131c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0.3px;
  caret-color: var(--primary);
}
.type-bar { position: absolute; left: 10%; right: 10%; bottom: -12px; height: 3px; background: #22283a; border-radius: 999px; overflow: hidden; display: none; }
.type-bar #typeDone { height: 100%; width: 0%; background: color-mix(in lch, var(--primary) 80%, #000); }
.answer-input.empty::before { content: attr(aria-label); color: var(--muted); }
.answer-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in lch, var(--primary) 35%, transparent); }

.feedback { min-height: 24px; margin-top: 8px; }
.feedback .ok { color: var(--ok); }
.feedback .bad { color: var(--danger); }

.footer { margin-top: 16px; color: var(--muted); }

/* Power Mode particles */
.pm-particle { position: absolute; width: 6px; height: 6px; border-radius: 50%; pointer-events: none; will-change: transform, opacity; mix-blend-mode: screen; }

/* Shake effect on wrapper */
.shake { animation: shake 120ms linear; }
@keyframes shake {
  0% { transform: translate(1px, 1px); }
  25% { transform: translate(-1px, 1px); }
  50% { transform: translate(1px, -1px); }
  75% { transform: translate(-1px, -1px); }
  100% { transform: translate(0, 0); }
}

@media (max-width: 900px) {
  .manage-layout { grid-template-columns: 1fr; }
}

/* Mode cards */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.mode-card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #101522; cursor: pointer; outline: none; transition: border-color .2s, box-shadow .2s, transform .08s; }
.mode-card:hover { border-color: color-mix(in lch, var(--primary) 35%, var(--border)); box-shadow: 0 0 0 2px color-mix(in lch, var(--primary) 20%, transparent); }
.mode-card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in lch, var(--primary) 35%, transparent); }
.mode-img { height: 160px; background: linear-gradient(135deg, #1f2a44, #1a1f2d); }
.mode-img.m1 { background-image: radial-gradient(600px 220px at 10% 0%, rgba(92,124,250,.25), transparent), linear-gradient(135deg, #202a45, #171c29); }
.mode-img.m2 { background-image: radial-gradient(600px 220px at 90% 0%, rgba(61,214,140,.25), transparent), linear-gradient(135deg, #203b3b, #171c29); }
.mode-body { padding: 12px; }
.mode-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.mode-desc { color: var(--muted); }

/* Focus (简洁) mode */
#quiz.focus .quiz-area { background: transparent; border-color: transparent; box-shadow: none; min-height: 60vh; display: flex; flex-direction: column; justify-content: center; align-items: center; }
#quiz.focus .stats, #quiz.focus .actions, #quiz.focus .prompt + .input-wrap + .actions + .feedback { }
#quiz.focus .stats { display: none; }
#quiz.focus .prompt { display: none; }
#quiz.focus .input-wrap { grid-template-columns: 1fr; width: 100%; justify-items: center; }
#quiz.focus .answer-input {
  background: transparent;
  border: none;
  border-radius: 0;
  font-size: clamp(28px, 6vw, 64px);
  color: color-mix(in lch, var(--primary) 90%, #ddd);
  min-width: 240px; max-width: 640px; width: 52vw; text-align: center;
}
#quiz.focus .type-bar { display: block; left: calc(50% - min(320px, 26vw)); right: calc(50% - min(320px, 26vw)); bottom: -18px; }
#quiz.focus .answer-input:focus { box-shadow: none; }
#quiz.focus .feedback { position: absolute; bottom: 80px; text-align: center; }
/* In focus mode, hide central actions and placeholder text */
#quiz.focus .actions, #quiz.focus #submitBtn { display: none !important; }
#quiz.focus .answer-input.empty::before { content: none; }

.helpbar { position: absolute; left: 16px; bottom: 16px; color: var(--muted); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.kbd { display: inline-flex; gap: 6px; align-items: center; padding: 4px 8px; border: 1px solid var(--border); background: #0f131c; border-radius: 6px; color: var(--text); }
.kbd b { font-weight: 700; opacity: .9; }
.help-item { display: inline-flex; align-items: center; gap: 8px; color: var(--text); background: transparent; border: 1px solid transparent; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.help-item:hover { background: #0f131c; border-color: var(--border); }

.next-arrow { position: absolute; right: 16px; bottom: 12px; font-size: 36px; line-height: 36px; width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--border); background: #0f131c; color: var(--text); cursor: pointer; display: grid; place-items: center; }
.next-arrow:hover { border-color: var(--primary); color: #fff; }
.quiz-header { position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 10px 6px 2px; background: rgba(15,17,21,0.6); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); }
.quiz-header.hidden { display: none; }
.qh-left { display: inline-flex; align-items: center; gap: 10px; }
.qh-menu { opacity: .8; }
.qh-title { font-weight: 600; }
.qh-count { color: var(--muted); }
.qh-right { color: var(--muted); }
.qh-progress { grid-column: 1 / -1; height: 4px; background: #10141d; border-radius: 999px; overflow: hidden; }
#qhProgressInner { height: 100%; width: 0%; background: var(--ok); transition: width .15s ease; }
