/* WikiBattle — light theme modelled on wikiracer.io (Tailwind + Ant Design look) */
:root {
  --bg: #edf2f7;
  --card: #ffffff;
  --text: rgba(0, 0, 0, .85);
  --muted: #718096;
  --line: #cbd5e0;
  --line-light: #e2e8f0;
  --primary: #1890ff;
  --primary-hover: #40a9ff;
  --primary-active: #096dd9;
  --blue-50: #e6f7ff;
  --blue-100: #ebf8ff;
  --blue-border: #91d5ff;
  --red: #f56565;
  --red-dark: #e53e3e;
  --green: #38a169;
  --green-bg: #f0fff4;
  --yellow-bg: #fffbe6;
  --yellow-border: #ffe58f;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -1px rgba(0, 0, 0, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
h2 { margin: 0; font-size: 20px; font-weight: 700; }
a { color: var(--primary); text-decoration: none; }

#app { min-height: 100%; display: flex; flex-direction: column; }

/* Header */
.site-header { position: relative; display: flex; justify-content: center; align-items: center; padding: 24px 24px 20px; }
.logo { display: inline-flex; align-items: center; gap: 8px; color: var(--primary); font-size: 24px; font-weight: 400; }
.logo svg { width: 30px; height: 30px; }
.music-btn { position: absolute; right: 24px; top: 26px; }

/* Layout containers */
.screen { display: none; width: 100%; margin: 0 auto; padding: 0 24px 24px; }
.container-sm { max-width: 560px; }
.container-md { max-width: 896px; }
.container-race { max-width: 1440px; }
#app[data-screen="home"] #screen-home,
#app[data-screen="lobby"] #screen-lobby,
#app[data-screen="vote"] #screen-vote,
#app[data-screen="countdown"] #screen-countdown,
#app[data-screen="race"] #screen-race,
#app[data-screen="results"] #screen-results { display: block; }

.card { background: var(--card); box-shadow: var(--shadow); padding: 24px; margin-bottom: 24px; }
.card-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.card-title.small { font-size: 16px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.card-title.center, .center { text-align: center; }
.upper { text-transform: uppercase; letter-spacing: .02em; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.muted { color: var(--muted); margin: 12px 0 0; }
.muted.center { text-align: center; }
.mb { margin-bottom: 12px; }
.pill { font-size: 12px; font-weight: 500; background: var(--blue-50); color: var(--primary); border: 1px solid var(--blue-border); padding: 0 8px; line-height: 20px; border-radius: 2px; }

/* Ant-like controls */
.btn {
  appearance: none; height: 32px; padding: 4px 15px; border-radius: 2px; border: 1px solid #d9d9d9; background: #fff;
  color: var(--text); cursor: pointer; font-size: 14px; line-height: 1.5; white-space: nowrap; transition: all .2s;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .015);
}
.btn:hover:not(:disabled) { color: var(--primary-hover); border-color: var(--primary-hover); }
.btn:disabled { color: rgba(0, 0, 0, .25); background: #f5f5f5; border-color: #d9d9d9; cursor: not-allowed; box-shadow: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, .045); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-primary:active:not(:disabled) { background: var(--primary-active); border-color: var(--primary-active); }
.btn-danger { color: var(--red-dark); border-color: var(--red-dark); }
.btn-danger:hover:not(:disabled) { color: #fff; background: var(--red-dark); border-color: var(--red-dark); }
.btn-sm { height: 26px; padding: 0 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row.center { justify-content: center; margin-top: 16px; }

.input {
  width: 100%; height: 32px; padding: 4px 11px; border: 1px solid #d9d9d9; border-radius: 2px; background: #fff; outline: none; transition: all .2s;
}
.input:focus { border-color: var(--primary-hover); box-shadow: 0 0 0 2px rgba(24, 144, 255, .2); }
.input[readonly] { color: rgba(0, 0, 0, .65); background: #fafafa; }
.select { width: auto; min-width: 120px; }
.input-group { display: flex; }
.input-group .input { flex: 1; border-radius: 2px 0 0 2px; min-width: 0; }
.input-group .btn { border-radius: 0 2px 2px 0; margin-left: -1px; }
.label { display: block; font-size: 14px; margin-bottom: 6px; }
.form-row { margin-bottom: 20px; }
.form-row.inline { display: flex; align-items: center; gap: 12px; }
.form-row.inline .label { margin: 0; }
.form-error { color: var(--red-dark); margin: 12px 0 0; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: 4px 0; }
.plain-list .off { color: rgba(0, 0, 0, .35); }
.plain-list .you { color: var(--primary); }

/* Home */
.home-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; text-align: center; }
.home-col .card-title { margin-bottom: 12px; }
.home-col .input-group { max-width: 260px; margin: 0 auto; }
.how-to ol { margin: 0; padding-left: 20px; color: rgba(0, 0, 0, .65); }
.how-to li { margin: 4px 0; }

/* Timer (Ant progress circle) */
.timer { position: relative; width: 100px; height: 100px; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 6; stroke-linecap: round; }
.timer .trail { stroke: #f5f5f5; }
.timer .bar { stroke: var(--primary); stroke-dasharray: 282.74; stroke-dashoffset: 0; transition: stroke-dashoffset .3s linear, stroke .3s; }
.timer.low .bar { stroke: var(--red); }
.timer-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; }

/* Route block (begin ↓ end) */
.route-block { text-align: center; padding: 8px 0; }
.route-block .begin { font-size: 20px; font-weight: 700; }
.route-block .arrow { color: var(--red); font-size: 20px; line-height: 1.2; }
.route-block .end { font-size: 20px; }
.route-block.compact .begin, .route-block.compact .end { font-size: 16px; }
.route-block.compact .arrow { font-size: 16px; }
.round-label { font-weight: 700; font-size: 20px; text-align: center; text-transform: uppercase; }
.countdown-number { font-size: 96px; font-weight: 700; color: var(--primary); line-height: 1.1; animation: pulse .9s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(1.15); opacity: .5; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

/* Vote */
.vote-head { display: flex; align-items: center; gap: 20px; margin-bottom: 20px; }
.vote-title { flex: 1; text-align: center; }
.vote-title .round-label { font-size: 16px; color: var(--muted); }
.vote-title h2 { font-size: 22px; }
.vote-title .muted { margin-top: 4px; }
.options { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.option {
  display: grid; grid-template-columns: 72px 1fr auto; gap: 14px; align-items: center; width: 100%; text-align: left; padding: 12px;
  background: #fff; border: 0; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; cursor: pointer; transition: background .15s, transform .4s, opacity .4s;
}
.option:last-child { border-bottom: 0; }
.option:hover:not(:disabled) { background: var(--blue-100); }
.option.mine { background: var(--blue-100); border-left-color: var(--primary); }
.option:disabled { cursor: default; }
.option .thumb { width: 72px; height: 56px; object-fit: cover; background: #edf2f7; display: block; }
.option .thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 22px; font-weight: 700; }
.option .title { font-weight: 700; font-size: 16px; }
.option .extract { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.option .votes { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; min-width: 60px; }
.option .avatars { display: flex; gap: 3px; }
.avatar { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; flex: none; }
.vote-bar { height: 6px; width: 100px; background: #f0f0f0; border-radius: 3px; overflow: hidden; }
.vote-bar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .9s cubic-bezier(.2, .8, .2, 1); }
.vote-count { font-size: 12px; color: var(--muted); }

/* Reveal animation */
.options.revealing .option.loser { animation: loser .6s ease forwards; }
.options.revealing .option.winner { animation: winner .7s cubic-bezier(.2, .9, .3, 1.3) .35s both; background: var(--blue-50); border-left-color: var(--primary); position: relative; z-index: 1; }
.options.revealing .option.winner .title { color: var(--primary); }
@keyframes loser { to { opacity: .3; transform: scale(.97); filter: grayscale(1); } }
@keyframes winner { 0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(24, 144, 255, 0); } 60% { transform: scale(1.03); box-shadow: 0 8px 24px rgba(24, 144, 255, .25); } 100% { transform: scale(1.02); box-shadow: 0 6px 18px rgba(24, 144, 255, .2); } }
.stamp-wrap { display: flex; justify-content: center; margin-top: 20px; }
.stamp {
  display: inline-block; padding: 6px 18px; border: 3px solid var(--primary); color: var(--primary); font-weight: 800; font-size: 22px; letter-spacing: .04em; text-transform: uppercase;
  border-radius: 4px; transform: rotate(-3deg); animation: stamp .5s cubic-bezier(.2, .9, .3, 1.4) .9s both;
}
.stamp.end { border-color: var(--red-dark); color: var(--red-dark); }
@keyframes stamp { 0% { transform: scale(2.2) rotate(-12deg); opacity: 0; } 70% { transform: scale(.95) rotate(-2deg); opacity: 1; } 100% { transform: scale(1) rotate(-3deg); opacity: 1; } }

/* Race */
.race-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.race-main { padding: 0; display: flex; flex-direction: column; height: calc(100vh - 100px); min-height: 420px; margin-bottom: 0; }
.frame-wrap { position: relative; flex: 1; min-height: 0; background: #fff; }
#wiki-frame { width: 100%; height: 100%; border: 0; display: block; }
.race-main.spectating #wiki-frame { pointer-events: none; }
.frame-loading { position: absolute; inset: 0; background: rgba(255, 255, 255, .6); display: grid; place-items: center; pointer-events: none; }
.spinner { width: 32px; height: 32px; border: 3px solid #e2e8f0; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: 8px 15px; border: 1px solid; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.alert-info { background: var(--blue-50); border-color: var(--blue-border); }
.alert-warn { background: var(--yellow-bg); border-color: var(--yellow-border); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: blink 1.2s infinite; flex: none; }
@keyframes blink { 50% { opacity: .3; } }
.race-side .card { margin-bottom: 16px; padding: 16px; }
.race-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.race-head .timer { width: 84px; height: 84px; }
.race-head .timer-text { font-size: 18px; }
.race-head .route-block { flex: 1; padding: 0; min-width: 0; }
.race-head .route-block div { overflow-wrap: anywhere; }
.path-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; border-top: 1px solid var(--line-light); }
.path-list li { padding: 5px 0 5px 22px; border-bottom: 1px solid var(--line-light); position: relative; color: rgba(0, 0, 0, .65); font-size: 13px; overflow-wrap: anywhere; }
.path-list li::before { content: ''; position: absolute; left: 6px; top: 12px; width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.path-list li:last-child { color: var(--text); font-weight: 600; }
.path-list li:last-child::before { background: var(--primary); }
.path-list li.hit { color: var(--green); }
.path-list li.hit::before { background: var(--green); }
.player-rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-light); }
.player-rows li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line-light); }
.player-rows .name { font-weight: 600; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.player-rows .page { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-rows .page.done { color: var(--green); }
.player-rows .page.out { color: rgba(0, 0, 0, .35); }
.player-rows .clicks { font-size: 12px; color: var(--muted); text-align: right; }
.player-rows .watch { grid-column: 3; }
.player-rows li.watching { background: var(--blue-100); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.player-rows .off { opacity: .5; }
.tag { font-size: 11px; font-weight: 500; color: var(--muted); }

/* Results */
.results-head h2 { font-size: 26px; margin: 4px 0 8px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 700; padding: 6px 8px; border-bottom: 1px solid var(--line-light); font-size: 13px; }
.table td { padding: 8px; border-bottom: 1px solid var(--line-light); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.winner td { color: var(--primary); font-weight: 600; }
.table tr.you td:nth-child(2)::after { content: ' (you)'; color: var(--muted); font-weight: 400; font-size: 12px; }
.paths-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.paths-grid h4 { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; gap: 8px; }

/* Toast + connection */
.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%) translateY(-10px); background: #fff; box-shadow: 0 3px 6px -4px rgba(0,0,0,.12), 0 6px 16px rgba(0,0,0,.08), 0 9px 28px 8px rgba(0,0,0,.05);
  padding: 10px 16px; border-radius: 2px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.conn-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 60; background: var(--red-dark); color: #fff; text-align: center; padding: 6px; font-weight: 600; }

@media (max-width: 900px) {
  .race-layout { grid-template-columns: 1fr; }
  .race-main { height: 70vh; }
  .two-cols, .home-cols { grid-template-columns: 1fr; }
  .music-btn { position: static; margin-left: auto; }
  .site-header { justify-content: space-between; }
}
