:root {
  color-scheme: dark;
  --bg: #070b12;
  --surface: #101827;
  --surface-strong: #172236;
  --line: #2a3850;
  --text: #f5f7fb;
  --muted: #aab7c9;
  --accent: #66d9ff;
  --accent-strong: #00a8e8;
  --success: #38d996;
  --failure: #ff6b78;
  --warning: #ffc857;
  --danger: #ff5263;
  --focus: #fff3a3;
  --radius: 14px;
  --shadow: 0 18px 48px rgb(0 0 0 / 35%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.45; }
button, input, select { font: inherit; }
button, select, input { min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }
button, a, input, select, [tabindex]:focus { outline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); }
[hidden] { display: none !important; }
a { color: var(--accent); }

.skip-link { position: fixed; z-index: 1000; top: 8px; left: 8px; padding: 10px 14px; background: #fff; color: #000; transform: translateY(-160%); }
.skip-link:focus { transform: none; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.app-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px clamp(16px, 2.2vw, 36px); border-bottom: 1px solid var(--line); background: #0b1220; }
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-block h1 { font-size: clamp(18px, 2vw, 25px); margin: 0; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.brand-mark { width: 28px; height: 28px; border-radius: 9px; background: radial-gradient(circle at 50% 50%, #0b1220 0 22%, var(--accent) 24% 42%, #1f6feb 44% 100%); box-shadow: 0 0 24px rgb(102 217 255 / 28%); }
.header-statuses { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; }
.status-pill, .state-badge { display: inline-flex; align-items: center; min-height: 30px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: #0d1522; font-size: 13px; }
.state-badge { color: var(--text); border-color: #416180; }

.tab-bar { display: flex; gap: 4px; padding: 8px clamp(16px, 2.2vw, 36px); border-bottom: 1px solid var(--line); background: #0d1522; }
.tab-button { min-width: 100px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 700; }
.tab-button.is-active { color: var(--text); background: var(--surface-strong); box-shadow: inset 0 -2px var(--accent); }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(330px, 390px); min-height: calc(100vh - 125px); }
.stage-card { min-width: 0; display: grid; grid-template-rows: auto minmax(300px, 1fr) auto; background: #05080d; }
.stage-topline { min-height: 46px; display: flex; align-items: center; gap: 12px; padding: 8px 16px; color: var(--muted); border-bottom: 1px solid #1a2433; }
.stage-topline span:last-child { margin-left: auto; }
.canvas-wrap, .display-canvas-wrap { position: relative; min-height: 0; overflow: hidden; background: #090d12; }
.canvas-wrap canvas, .display-canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.empty-stage { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; color: var(--muted); text-align: center; padding: 24px; pointer-events: none; }
.empty-stage strong { color: var(--text); font-size: clamp(18px, 2.4vw, 30px); }
.timer-strip { display: grid; grid-template-columns: 1fr 1fr 1fr; border-top: 1px solid #1a2433; background: #080d15; }
.timer-strip > div { padding: 11px 16px; border-right: 1px solid #1a2433; }
.timer-strip > div:last-child { border-right: 0; }
.timer-strip span { display: block; color: var(--muted); font-size: 12px; }
.timer-strip strong { display: block; margin-top: 2px; font-variant-numeric: tabular-nums; font-size: clamp(18px, 2vw, 28px); }

.controller-panel { overflow-y: auto; max-height: calc(100vh - 125px); padding: 14px; border-left: 1px solid var(--line); background: #0b1220; }
.panel-section { padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel-section:last-child { margin-bottom: 0; }
.panel-section h3 { margin: 0 0 10px; font-size: 15px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.privacy-note, .small-note, .storage-explanation { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.folder-actions { display: flex; }
.folder-actions button { width: 100%; }
.drop-zone { min-height: 64px; display: grid; place-items: center; margin-top: 10px; padding: 10px; border: 2px dashed #40516c; border-radius: 10px; color: var(--muted); text-align: center; }
.drop-zone.is-dragging { border-color: var(--accent); color: var(--text); background: rgb(102 217 255 / 8%); }
.inline-message { min-height: 20px; margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.inline-message.is-error { color: #ffabb3; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; font-weight: 650; }
input, select { width: 100%; padding: 9px 11px; border: 1px solid #465876; border-radius: 9px; background: #09111d; color: var(--text); }
input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { min-height: 17px; color: #ffabb3; font-size: 12px; font-weight: 500; }

.primary-button, .secondary-button, .success-button, .failure-button, .warning-button, .danger-outline-button, .compact-button { border-radius: 9px; padding: 9px 13px; font-weight: 750; }
.primary-button { border: 1px solid #43c8f5; background: var(--accent-strong); color: #001018; }
.secondary-button, .compact-button { border: 1px solid #4a5d79; background: #17243a; color: var(--text); }
.compact-button { min-height: 36px; padding: 6px 11px; font-size: 13px; }
.success-button { border: 1px solid #58e7aa; background: #138659; color: #fff; }
.failure-button { border: 1px solid #ff8490; background: #a92f40; color: #fff; }
.warning-button { border: 1px solid #ffd778; background: #835b00; color: #fff7dc; }
.danger-outline-button { border: 1px solid var(--danger); background: transparent; color: #ff9ca7; }
.main-action { width: 100%; min-height: 58px; font-size: 20px; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 9px; }
.result-actions button { min-height: 52px; }
.utility-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; }
.utility-actions button:last-child { grid-column: 1 / -1; }
.stacked-actions { display: grid; gap: 8px; }
.wide-button { width: 100%; }
.score-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 10px; }
.score-grid > div { padding: 9px; border-radius: 9px; background: #0b1422; text-align: center; }
.score-grid dt { color: var(--muted); font-size: 12px; }
.score-grid dd { margin: 2px 0 0; font-size: 24px; font-weight: 800; }

.content-panel { max-width: 1500px; min-height: calc(100vh - 125px); margin: 0 auto; padding: clamp(20px, 3vw, 42px); }
.content-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.content-heading h2 { margin: 0; font-size: clamp(25px, 3vw, 38px); }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.link-button { display: inline-flex; align-items: center; text-decoration: none; }
.ranking-form { display: grid; grid-template-columns: minmax(180px, 2fr) minmax(150px, 1fr) minmax(180px, 1fr) auto; gap: 12px; align-items: start; margin: 24px 0 14px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.form-actions { display: flex; gap: 8px; align-items: flex-start; padding-top: 22px; }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.data-actions .danger-outline-button { margin-left: auto; }
.ranking-table-wrap, .leaderboard-table-wrap { overflow: auto; max-height: min(62vh, 760px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.ranking-table { width: 100%; border-collapse: collapse; }
.ranking-table th, .ranking-table td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; }
.ranking-table th { position: sticky; top: 0; z-index: 1; background: #182338; color: var(--muted); font-size: 13px; }
.ranking-table td { font-variant-numeric: tabular-nums; }
.ranking-table tr[data-rank="1"] { background: rgb(255 200 87 / 12%); }
.ranking-table tr[data-rank="2"] { background: rgb(189 205 223 / 10%); }
.ranking-table tr[data-rank="3"] { background: rgb(205 135 91 / 10%); }
.row-actions { display: flex; gap: 7px; }
.row-actions button { min-height: 36px; padding: 6px 9px; }
.empty-table { padding: 30px; margin: 0; color: var(--muted); text-align: center; }
.quick-guide { display: grid; gap: 11px; margin: 24px 0 34px; padding-left: 24px; }
.shortcut-grid { display: grid; grid-template-columns: max-content 1fr max-content 1fr; gap: 8px 14px; align-items: center; max-width: 900px; }
kbd { display: inline-block; min-width: 42px; padding: 5px 8px; border: 1px solid #5f718c; border-bottom-width: 3px; border-radius: 6px; background: #111c2c; color: var(--text); text-align: center; font-family: inherit; font-size: 12px; font-weight: 800; }

.modal-backdrop { position: fixed; z-index: 900; inset: 0; display: grid; place-items: center; padding: 20px; background: rgb(0 0 0 / 72%); }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 24px; border: 1px solid #536780; border-radius: 16px; background: #111b2a; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 12px; }
.modal p { color: var(--muted); white-space: pre-line; }
.modal-details { margin: 16px 0; padding: 14px; border-radius: 10px; background: #09121f; }
.modal-details dl { display: grid; grid-template-columns: 1fr auto; gap: 8px 18px; margin: 0; }
.modal-details dd { margin: 0; font-weight: 800; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.toast-region { position: fixed; z-index: 1000; right: 18px; bottom: 18px; max-width: min(420px, calc(100vw - 36px)); padding: 12px 16px; border: 1px solid transparent; border-radius: 10px; pointer-events: none; opacity: 0; transform: translateY(8px); transition: opacity .18s, transform .18s; }
.toast-region.is-visible { opacity: 1; transform: none; background: #18263b; border-color: #526783; box-shadow: var(--shadow); }
.toast-region.is-error { background: #3a151d; border-color: #a34250; }

.display-page { overflow: hidden; background: #05080d; }
.display-shell { height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.display-topline { min-height: 54px; display: flex; align-items: center; gap: 16px; padding: 9px 18px; background: #080d15; border-bottom: 1px solid #182235; }
.display-topline span:nth-child(2) { margin-left: auto; }
.display-canvas-wrap { min-height: 0; }
.display-timer { display: flex; align-items: baseline; justify-content: center; gap: 18px; padding: 13px; background: #080d15; border-top: 1px solid #182235; }
.display-timer span { color: var(--muted); }
.display-timer strong { font-size: clamp(30px, 5vw, 72px); font-variant-numeric: tabular-nums; }
.display-notice { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: 520px; padding: 16px 22px; border: 1px solid #50617a; border-radius: 12px; background: rgb(9 16 26 / 92%); text-align: center; }

.leaderboard-page { min-height: 100vh; background: radial-gradient(circle at 50% -20%, #20395c 0, #0a111d 48%, #060a11 100%); }
.leaderboard-shell { max-width: 1700px; margin: 0 auto; padding: clamp(22px, 4vw, 64px); }
.leaderboard-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.leaderboard-header h1 { margin: 0; font-size: clamp(36px, 6vw, 76px); }
.leaderboard-header-actions { display: flex; align-items: center; gap: 10px; }
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.podium-card { min-height: 120px; padding: 20px; border: 1px solid #586b84; border-radius: 16px; background: rgb(20 31 48 / 88%); }
.podium-card:first-child { border-color: #f0c765; box-shadow: 0 0 28px rgb(255 200 87 / 12%); }
.podium-rank { color: var(--warning); font-weight: 900; }
.podium-team { display: block; margin: 8px 0; font-size: clamp(20px, 2.3vw, 34px); overflow-wrap: anywhere; }
.podium-score { color: var(--muted); }
.leaderboard-table-wrap { max-height: calc(100vh - 340px); }
.leaderboard-table { font-size: clamp(16px, 1.7vw, 25px); }

.exit-audience-button { position: fixed; z-index: 100; top: 14px; right: 14px; min-height: 44px; border: 1px solid #536780; border-radius: 9px; background: rgb(9 16 26 / 90%); color: var(--text); }
body.audience-mode .app-header, body.audience-mode .tab-bar, body.audience-mode .controller-panel { display: none; }
body.audience-mode .game-layout { display: block; height: 100vh; }
body.audience-mode .stage-card { height: 100vh; grid-template-rows: auto minmax(0, 1fr) auto; }
body.audience-mode .stage-topline span:last-child { display: none; }
body.audience-mode .exit-audience-button { display: block !important; }

@media (max-width: 760px) {
  .game-layout { grid-template-columns: 1fr; }
  .stage-card { min-height: 68vh; }
  .controller-panel { max-height: none; border-left: 0; border-top: 1px solid var(--line); }
  .ranking-form { grid-template-columns: 1fr 1fr; }
  .form-actions { padding-top: 0; }
}

@media (max-height: 850px) and (min-width: 761px) {
  .controller-panel { padding: 8px; }
  .panel-section { padding: 10px; margin-bottom: 8px; }
  .panel-section h3 { margin-bottom: 6px; }
  .privacy-note, .small-note { margin-bottom: 7px; }
  .drop-zone { min-height: 46px; margin-top: 6px; }
  .field-grid { gap: 6px 8px; }
  .main-action { min-height: 52px; }
  .result-actions, .utility-actions { margin-top: 6px; gap: 6px; }
  .result-actions button { min-height: 48px; }
}

@media (max-width: 720px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-statuses { justify-content: flex-start; }
  .tab-bar { overflow-x: auto; }
  .stage-topline { font-size: 12px; }
  .timer-strip { grid-template-columns: 1fr 1fr; }
  .timer-strip > div:last-child { grid-column: 1 / -1; border-top: 1px solid #1a2433; }
  .field-grid, .ranking-form { grid-template-columns: 1fr; }
  .content-heading { align-items: flex-start; flex-direction: column; }
  .shortcut-grid { grid-template-columns: max-content 1fr; }
  .podium { grid-template-columns: 1fr; }
  .leaderboard-header { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

@media (forced-colors: active) {
  button, input, select, .panel-section, .ranking-table-wrap { border: 1px solid CanvasText; }
}
