:root {
  --bg: #141413;
  --panel: #1f1e1c;
  --line: #2c2b28;
  --text: #ecebe6;
  --muted: #8f8d86;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.14);
  --danger: #e0685a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login form {
  width: min(320px, 100%);
  display: grid;
  gap: 12px;
}

.login h1 { margin: 0 0 8px; font-size: 22px; font-weight: 600; }

.login input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}

.login input:focus { border-color: var(--accent); }

.login button, .main {
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  color: #1a1612;
  font-weight: 600;
}

.error { color: var(--danger); margin: 0; font-size: 14px; }

main {
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

header {
  padding: 14px 16px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.direction {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}

.seg {
  background: none;
  border: 0;
  border-radius: 7px;
  padding: 7px 12px;
  color: var(--muted);
  white-space: nowrap;
}

.seg.on { background: var(--accent-soft); color: var(--accent); }

.target-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.target-row select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}

.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-kind="live"] .dot { background: var(--accent); }
.status[data-kind="wait"] .dot { background: #c9a35b; }
.status[data-kind="error"] .dot { background: var(--danger); }
.status[data-kind="error"] { color: var(--danger); }

.lines {
  list-style: none;
  margin: 0;
  padding: 8px 16px 16px;
  overflow-y: auto;
  min-height: 0;
}

.lines li {
  position: relative;
  padding: 14px 44px 14px 0;
  border-bottom: 1px solid var(--line);
}

.lines li:not(.done) .dst::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}

.dst { margin: 0; font-size: 21px; line-height: 1.35; }
.src { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.play {
  position: absolute;
  top: 14px;
  right: 0;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
}

.play svg { width: 16px; height: 16px; fill: var(--muted); }
.lines li.playing .play { border-color: var(--accent); }
.lines li.playing .play svg { fill: var(--accent); }

.empty {
  grid-row: 2;
  align-self: center;
  justify-self: center;
  margin: 0;
  padding: 0 32px;
  color: var(--muted);
  text-align: center;
}

#lines:not(:empty) + .empty { display: none; }
.lines, .empty { grid-row: 2; grid-column: 1; }

footer {
  border-top: 1px solid var(--line);
  padding: 12px 16px 16px;
  display: grid;
  gap: 12px;
}

.options {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 14px;
}

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span {
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: var(--line);
  position: relative;
  transition: background 0.15s;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + span { background: var(--accent-soft); }
.switch input:checked + span::after { transform: translateX(14px); background: var(--accent); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.link {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 0;
}

.controls { display: grid; gap: 10px; }

.main {
  position: relative;
  overflow: hidden;
  padding: 14px;
  font-size: 17px;
}

.main.running {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}

.main .level {
  position: absolute;
  inset: 0;
  background: var(--accent-soft);
  transform-origin: left;
  transform: scaleX(var(--lvl, 0));
  transition: transform 0.1s linear;
  pointer-events: none;
}

.main span:last-child { position: relative; }

.hold {
  height: 120px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 18px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hold.down {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1612;
}

@media (max-width: 520px) {
  .status { margin-left: 0; width: 100%; }
  .dst { font-size: 19px; }
}
