:root {
  color-scheme: dark;
  --bg: #080b10;
  --panel: rgba(17, 23, 34, .84);
  --panel2: rgba(14, 20, 31, .92);
  --line: rgba(148, 163, 184, .15);
  --text: #f8fafc;
  --muted: #8b95a7;
  --soft: #626c7e;
  --green: #22c55e;
  --green2: #35e87d;
  --red: #ff4050;
  --yellow: #f8c04e;
  --shadow: 0 24px 80px rgba(0,0,0,.42);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% -10%, rgba(34,197,94,.18), transparent 34%),
    radial-gradient(circle at 82% 12%, rgba(59,130,246,.10), transparent 34%),
    linear-gradient(180deg, #070a0f 0%, var(--bg) 100%);
  color: var(--text);
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1480px, calc(100vw - 28px));
  margin: 16px auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(9, 13, 20, .86);
  box-shadow: var(--shadow);
}

.topbar, .bottom-bar, .top-actions, .brand, .record-row, .mini-stat, .wave-footer, .section-title, .control-head, .scale, .device-box, .level-box, .preview-btn, .export-btn { display: flex; align-items: center; }
.topbar { justify-content: space-between; gap: 18px; margin-bottom: 16px; background: linear-gradient(180deg, rgba(21,28,42,.86), rgba(12,17,27,.86)) }
.brand { gap: 14px; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  background: rgba(34,197,94,.13); box-shadow: 0 0 24px rgba(34,197,94,.12);
}
.brand-mark span { width: 4px; border-radius: 999px; background: var(--green2); box-shadow: 0 0 12px rgba(34,197,94,.75); }
.brand-mark span:nth-child(1){ height:18px}.brand-mark span:nth-child(2){ height:28px}.brand-mark span:nth-child(3){ height:38px}.brand-mark span:nth-child(4){ height:26px}.brand-mark span:nth-child(5){ height:16px}
.brand-title { font-size: 21px; font-weight: 750; letter-spacing: -.03em; }
.brand-title b { color: var(--green); font-size: 13px; border: 1px solid rgba(34,197,94,.5); border-radius: 6px; padding: 2px 6px; margin-left: 5px; }
.brand-subtitle { color: var(--muted); margin-top: 4px; }
.top-actions { gap: 10px; }
.preset-select, .icon-btn, .typing-card, .wave-card, .enhance-card, .device-box, .level-box, .preview-btn, .export-btn {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(21,28,42,.86), rgba(12,17,27,.86));
  border-radius: 14px;
}
.preset-select { height: 48px; padding: 0 12px; display: flex; align-items:center; gap:10px; }
.preset-select select { color: var(--text); background: transparent !important; border: 0; outline: 0; min-width: 198px; }
.keyboard-icon { color: var(--green2); }
.icon-btn { width: 48px; height: 48px; color: #dbe4f0; font-size: 20px; }

.typing-card {
  min-height: 270px;
  padding: 34px 30px;
  text-align: center;
  display: flex; flex-direction: column; justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03);
}
.typing-text {
  outline: 0;
  user-select: none;

  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;

  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;

  min-height: 180px;

  font: 500 clamp(18px, 5.2vw, 38px)/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: -0.04em;
  color: var(--soft);
}

.typing-line {
  width: 100%;
  max-width: 100%;
  min-width: 0;

  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.typing-text .done {
  color: var(--text);
}

.typing-text .wrong {
  color: var(--red);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 8px;
}

.typing-text .current {
  position: relative;
  color: var(--green2);
  text-shadow: 0 0 20px rgba(34,197,94,.18);
}

.typing-text .current::before,
.typing-text .end-caret::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8%;
  width: 2px;
  height: 84%;
  border-radius: 999px;
  background: var(--green2);
  transform: translateX(-100%);
  animation: blink 1s steps(1) infinite;
}

.typing-text .end-caret {
  position: relative;
  display: inline-block;
  width: 1px;
  height: 1em;
  vertical-align: -0.12em;
}

.typing-text .typing-fade {
  color: rgba(139, 149, 167, .42);
}

@keyframes blink { 50% { opacity: 0; } }
.hidden-input { position: fixed; left: -9999px; opacity: 0; }

.record-row { position: relative; justify-content: center; gap: 120px; padding: 18px 10px 28px; }
.mini-stat { gap: 14px; min-width: 160px; color: var(--text); }
.mini-stat.right { justify-content: flex-start; }
.stat-icon { color: #cbd5e1; font-size: 24px; }
.mini-stat small { display:block; color: var(--muted); margin-bottom: 4px; }
.mini-stat strong { font-size: 26px; font-weight: 650; }
.record-btn { min-width: 350px; height: 74px; display:flex; align-items:center; justify-content:center; gap:24px; border: 2px solid var(--red); border-radius: 999px; background: rgba(255,64,80,.05); color: var(--text); box-shadow: 0 0 34px rgba(255,64,80,.12); font-size: 32px; font-weight: 750; }
.record-btn:not(.recording) { border-color: rgba(34,197,94,.8); background: rgba(34,197,94,.07); box-shadow: 0 0 34px rgba(34,197,94,.08); }
.rec-dot { width: 22px; height: 22px; border-radius: 999px; background: var(--red); box-shadow: 0 0 18px rgba(255,64,80,.65); }
.record-btn:not(.recording) .rec-dot { background: var(--green); box-shadow: 0 0 18px rgba(34,197,94,.65); }
.record-hint { position:absolute; bottom: 4px; color: var(--muted); }

.wave-card { height: 200px; padding: 18px 28px; position: relative; overflow: hidden; }
#waveCanvas { width: 100%; height: 150px; display: block; }
.wave-footer { justify-content: space-between; color: var(--muted); }
.wave-footer i { display:inline-block; width:10px; height:10px; background: var(--green); border-radius:50%; margin-right:8px; }
.wave-footer b { color: var(--green2); margin-left: 10px; }

.enhance-card { margin-top: 18px; padding: 20px 26px 24px; }
.section-title { color: #cbd5e1; font-size: 14px; font-weight: 750; letter-spacing: .03em; gap: 10px; margin-bottom: 18px; }
.ghost-btn { margin-left: auto; color: #cbd5e1; background: transparent; border: 0; }
.enhance-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 22px; }
.control-block { padding-right: 28px; border-right: 1px solid var(--line); min-height: 116px; }
.control-block:last-child { border-right: 0; padding-right: 0; }
.control-head { gap: 10px; font-size: 17px; margin-bottom: 22px; }
.control-head span { color: var(--green2); }
.control-head i { margin-left: 2px; color: var(--soft); border: 1px solid var(--line); border-radius: 50%; width: 18px; height: 18px; font-size: 12px; text-align: center; line-height: 17px; font-style: normal; }
input[type="range"] { width: 100%; accent-color: var(--green); }
.scale { justify-content: space-between; color: var(--muted); margin-top: 12px; }
.score { margin-top: 10px; display:flex; gap: 12px; align-items:center; }
.score b { color: #cbd5e1; border: 1px solid var(--line); border-radius: 7px; padding: 3px 8px; font-weight: 500; }
.score em { color: var(--green2); font-style: normal; }
.control-block p { color: var(--muted); margin: 12px 0 0; }

.bottom-bar { gap: 16px; margin-top: 18px; }
.device-box {
  width: 340px;
  padding: 16px 20px;
  gap: 14px;

  appearance: none;
  color: var(--text);
  text-align: left;
  border: 1px solid var(--line);
}
.device-box small, .level-box small, .preview-btn small, .export-btn small { display:block; color: var(--muted); font-weight: 400; margin-bottom: 6px; }
.device-box strong { display:block; font-weight: 650; }
.device-box b { margin-left: auto; color: #cbd5e1; }
.level-box { flex: 1; min-width: 330px; padding: 18px; justify-content: space-between; gap: 18px; }
#levelBars { display:flex; gap:5px; height:18px; align-items:flex-end; }
#levelBars i { display:block; width:6px; height:16px; border-radius:999px; background: rgba(148,163,184,.22); }
#levelBars i.on { background: var(--green2); }
#levelBars i.hot { background: var(--yellow); }
.level-box b { color: #cbd5e1; font-weight: 500; }
.preview-btn, .export-btn { min-width: 230px; height: 84px; justify-content: center; flex-direction: column; color: var(--text); }
.preview-btn { background: linear-gradient(180deg, rgba(31,40,56,.98), rgba(20,27,39,.98)); }
.export-btn { background: linear-gradient(180deg, #28d568, #1faa55); border-color: rgba(96,255,160,.34); box-shadow: 0 10px 32px rgba(34,197,94,.18); }
.preview-btn span, .export-btn span { font-size: 28px; line-height: 1; }
.preview-btn strong, .export-btn strong { font-size: 20px; }
button:disabled { opacity: .48; cursor: not-allowed; }
.privacy-note { text-align:center; margin: 10px 0 -4px; color: var(--muted); font-size: 13px; }

body.light {
  --bg:#f5f7fb; --panel:rgba(255,255,255,.9); --panel2:rgba(255,255,255,.95); --line:rgba(15,23,42,.12); --text:#0f172a; --muted:#64748b; --soft:#a0a8b6;
  background: linear-gradient(180deg, #f9fbff 0%, #e9eef7 100%);
}
body.light .app-shell { background: rgba(255,255,255,.76); }

@media (max-width: 980px) {
  .topbar, .bottom-bar { flex-wrap: wrap; }
  .record-row { gap: 28px; flex-wrap: wrap; }
  .record-btn { min-width: 260px; }
  .enhance-grid { grid-template-columns: repeat(2, 1fr); }
  .control-block:nth-child(2) { border-right: 0; padding-right: 0; }
  .device-box, .preview-btn, .export-btn { flex: 1; min-width: 240px; }
}
@media (max-width: 640px) {
  .app-shell { width: calc(100vw - 14px); padding: 12px; }
  .top-actions { width:100%; flex-wrap:wrap; }
  .preset-select { flex:1; }
  .typing-card { min-height: 230px; padding: 24px 16px; }
  .enhance-grid { grid-template-columns: 1fr; }
  .control-block { border-right: 0; padding-right: 0; border-bottom: 1px solid var(--line); padding-bottom: 18px; }
  .control-block:last-child { border-bottom:0; }
}

/* typing recorder refinements */
.topbar { padding: 14px 16px; border-radius: 16px; border: 1px solid var(--line); }
.record-btn.recording .rec-dot { animation: recPulse 1s ease-in-out infinite; }
@keyframes recPulse { 50% { transform: scale(.72); opacity: .72; } }
.preview-btn strong, .export-btn strong { min-height: 24px; }

.preview-btn.playing {
  border-color: rgba(53,232,125,.45);
  box-shadow: 0 10px 32px rgba(34,197,94,.14);
}

.preview-btn.playing span {
  color: var(--green2);
}
.wave-overview-wrap{
  height:40px;
  margin-top:8px;
  border-radius:8px;
  overflow:hidden;
  background:#07111a;
}

#waveOverviewCanvas{
  width:100%;
  height:40px;
  display:block;
}