:root {
  --bg: #10171c;
  --panel: #19242b;
  --panel-2: #223039;
  --panel-3: #2a3942;
  --text: #f5f7f8;
  --muted: #91a2ad;
  --line: #31424c;
  --accent: #ffc62b;
  --accent-2: #ffda69;
  --danger: #ff5b68;
  --ok: #4bd59a;
  --shadow: 0 18px 50px rgba(0,0,0,.28);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 28px;
  height: 64px; padding: 0 28px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  background: rgba(15,23,28,.92); backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; letter-spacing: .06em; border: 0; background: transparent; color: var(--text); cursor: pointer; padding: 0; }
.brand-mark { width: 34px; height: 34px; border: 2px solid var(--accent); border-radius: 10px; display: grid; place-items: center; color: var(--accent); }
.nav { display: flex; align-items: center; gap: 8px; flex: 1; }
.nav button { border: 0; background: transparent; color: var(--muted); padding: 10px 13px; border-radius: 10px; font-weight: 700; }
.nav button:hover, .nav button.active { background: var(--panel); color: var(--text); }
.status-pill { color: var(--muted); font-size: 13px; }

.page { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 60px; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 26px; }
.hero h1 { margin: 0; font-size: clamp(30px, 5vw, 54px); line-height: 1; letter-spacing: -.04em; }
.hero p { margin: 10px 0 0; color: var(--muted); max-width: 680px; }

.btn { border: 1px solid transparent; border-radius: 12px; padding: 11px 16px; font-weight: 800; transition: .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #151b1f; box-shadow: 0 8px 24px rgba(255,198,43,.14); }
.btn-secondary { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-danger { background: rgba(255,91,104,.12); color: #ff8d97; border-color: rgba(255,91,104,.25); }
.btn:disabled { cursor: not-allowed; opacity: .45; transform: none; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card { background: linear-gradient(180deg, rgba(255,255,255,.025), transparent), var(--panel); border: 1px solid rgba(255,255,255,.055); border-radius: var(--radius); box-shadow: var(--shadow); }
.tournament-card { padding: 20px; min-height: 190px; display: flex; flex-direction: column; }
.tournament-card h3 { margin: 8px 0; font-size: 22px; }
.tournament-card .meta { color: var(--muted); font-size: 14px; }
.tournament-card .progress { margin-top: auto; }
.card-actions { display: flex; gap: 8px; margin-top: 16px; }

.progress { height: 8px; background: #0e1519; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: inherit; }

.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 52px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 20px; margin-bottom: 7px; }

.section-title { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 26px 0 12px; }
.section-title h2 { margin: 0; font-size: 21px; }
.panel { padding: 18px; background: var(--panel); border: 1px solid rgba(255,255,255,.055); border-radius: var(--radius); }

.import-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.import-card { padding: 17px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.import-card h3 { margin: 0 0 7px; }
.import-card p { color: var(--muted); font-size: 13px; min-height: 38px; }
.field { display: grid; gap: 7px; margin: 11px 0; }
.field label { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.input { width: 100%; padding: 11px 12px; border-radius: 11px; border: 1px solid var(--line); background: #111a20; color: var(--text); outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,198,43,.08); }
.checkbox-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.toolbar .search { flex: 1 1 280px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; background: var(--panel-3); color: var(--muted); font-size: 12px; font-weight: 800; }
.badge.ok { color: var(--ok); background: rgba(75,213,154,.1); }
.badge.warn { color: var(--accent-2); background: rgba(255,198,43,.08); }

.track-list { display: grid; gap: 8px; }
.track-row { display: grid; grid-template-columns: 52px minmax(0, 1.7fr) minmax(0, 1fr) 110px 150px; gap: 12px; align-items: center; padding: 10px; border: 1px solid transparent; border-radius: 13px; background: var(--panel); }
.track-row:hover { border-color: var(--line); }
.cover { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: radial-gradient(circle at 30% 20%, #516774, #18242b 55%, #0e1418); display: grid; place-items: center; font-size: 22px; overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.track-main { min-width: 0; }
.track-title { font-weight: 850; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-artist, .muted { color: var(--muted); font-size: 13px; }
.track-source { color: var(--muted); font-size: 12px; }
.inline-actions { display: flex; justify-content: end; gap: 7px; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }
.icon-btn:hover { border-color: var(--accent); }

.drawer-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.58); display: grid; justify-items: end; }
.drawer { width: min(520px, 100%); height: 100%; overflow: auto; background: #131d23; border-left: 1px solid var(--line); padding: 24px; box-shadow: -30px 0 80px rgba(0,0,0,.4); }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.drawer h2 { margin: 0; }
.editor-cover { width: 180px; height: 180px; margin: 25px auto; border-radius: 24px; overflow: hidden; background: radial-gradient(circle at 30% 20%, #5c7380, #1b2930 55%, #0d1418); display: grid; place-items: center; font-size: 62px; box-shadow: var(--shadow); }
.editor-cover img { width: 100%; height: 100%; object-fit: cover; }
.start-tools { display: grid; grid-template-columns: 1fr 120px; gap: 10px; }

.audio-mini { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; margin-top: 14px; }
.audio-mini button { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: #151b1f; font-weight: 900; }
.audio-mini input[type=range] { width: 100%; accent-color: var(--accent); }
.time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }

.select-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; max-height: 55vh; overflow: auto; padding-right: 4px; }
.select-track { display: grid; grid-template-columns: 22px 44px 1fr; gap: 10px; align-items: center; padding: 9px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.select-track .cover { width: 44px; height: 44px; }
.select-track input { accent-color: var(--accent); width: 17px; height: 17px; }

.play-page { width: 100%; min-height: calc(100vh - 64px); padding: 0; }
.play-head { height: 54px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 18px; background: #18232a; border-bottom: 1px solid var(--line); }
.play-head .left { justify-self: start; }
.play-head .right { justify-self: end; display: flex; gap: 8px; }
.round-label { color: var(--muted); font-size: 13px; text-align: center; }
.round-label strong { color: var(--text); }
.duel { display: grid; grid-template-columns: 1fr 1fr; min-height: calc(100vh - 118px); }
.duel-side { position: relative; display: flex; flex-direction: column; min-width: 0; overflow: hidden; border-right: 1px solid rgba(255,255,255,.08); background: #121b20; }
.duel-side:last-child { border-right: 0; }
.duel-bg { position: absolute; inset: 0; background-position: center; background-size: cover; filter: blur(50px) saturate(.8); opacity: .18; transform: scale(1.15); }
.duel-content { position: relative; z-index: 2; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; text-align: center; }
.duel-cover { width: min(340px, 55%); aspect-ratio: 1; border-radius: 26px; overflow: hidden; background: radial-gradient(circle at 30% 20%, #5b717d, #1b2931 55%, #0d1519); display: grid; place-items: center; font-size: 90px; box-shadow: 0 28px 90px rgba(0,0,0,.42); }
.duel-cover img { width: 100%; height: 100%; object-fit: cover; }
.duel-content h2 { margin: 24px 0 5px; font-size: clamp(20px, 2.4vw, 34px); max-width: 90%; }
.duel-artist { color: var(--muted); font-size: clamp(14px, 1.2vw, 18px); }
.duel-player { width: min(520px, 90%); margin: 24px auto 0; display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 12px; }
.duel-player .play { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--accent); color: #152027; font-weight: 900; }
.duel-player input[type=range] { width: 100%; accent-color: var(--accent); }
.choose { position: relative; z-index: 3; width: 100%; border: 0; border-top: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 20px; font-size: 17px; font-weight: 900; letter-spacing: .02em; }
.choose:hover { background: var(--accent); color: #10171c; }
.shortcut { color: var(--muted); font-size: 11px; margin-left: 8px; }

.result { text-align: center; padding-top: 20px; }
.champion { margin: 22px auto 34px; width: min(520px, 100%); padding: 28px; background: linear-gradient(145deg, rgba(255,198,43,.14), transparent 55%), var(--panel); border: 1px solid rgba(255,198,43,.35); border-radius: 28px; box-shadow: var(--shadow); }
.champion .editor-cover { width: 220px; height: 220px; margin: 0 auto 20px; }
.champion h2 { font-size: 34px; margin: 0; }
.placements { width: min(760px, 100%); margin: 0 auto; display: grid; gap: 10px; text-align: left; }
.place-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 14px 16px; border-radius: 13px; background: var(--panel); }
.place-row strong { color: var(--accent); }

.modal-wrap { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,.65); }
.modal { width: min(460px, 100%); background: #151f25; border: 1px solid var(--line); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); }
.modal h3 { margin-top: 0; }
.modal p { color: var(--muted); }
.modal-actions { display: flex; justify-content: end; gap: 8px; margin-top: 20px; }

#toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 300; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 420px; background: #1d2a32; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { border-color: rgba(255,91,104,.4); color: #ffafb6; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.loading { min-height: 45vh; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .grid, .import-grid { grid-template-columns: 1fr 1fr; }
  .track-row { grid-template-columns: 50px 1fr 110px; }
  .track-row .track-source, .track-row .album-col { display: none; }
  .duel { grid-template-columns: 1fr; }
  .duel-side { min-height: calc(50vh - 59px); border-right: 0; border-bottom: 1px solid var(--line); }
  .duel-content { padding: 18px; }
  .duel-cover { width: 150px; }
  .duel-content h2 { margin-top: 12px; }
  .duel-player { margin-top: 13px; }
  .choose { padding: 14px; }
  .play-page { min-height: calc(100vh - 64px); }
}

@media (max-width: 640px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .brand span:last-child { display: none; }
  .nav { gap: 2px; }
  .nav button { padding: 9px 8px; font-size: 13px; }
  .status-pill { display: none; }
  .page { width: min(100% - 22px, 1180px); padding-top: 22px; }
  .hero { align-items: start; flex-direction: column; }
  .grid, .import-grid, .select-grid { grid-template-columns: 1fr; }
  .track-row { grid-template-columns: 46px 1fr 86px; padding: 8px; }
  .track-row .cover { width: 46px; height: 46px; }
  .play-head { grid-template-columns: 1fr auto; height: auto; min-height: 54px; padding: 8px 10px; }
  .play-head .round-label { display: none; }
  .play-head .right .desktop-only { display: none; }
  .duel-cover { width: 122px; border-radius: 18px; }
  .duel-content h2 { font-size: 19px; }
  .duel-player { grid-template-columns: 42px 1fr; }
  .duel-player .time { grid-column: 2; }
}
