:root {
  color-scheme: dark;
  --bg: #101117;
  --panel: #191b25;
  --field: #12141d;
  --edge: #323545;
  --ink: #f6f5fb;
  --muted: #b7bbce;
  --accent: #dcfa79;
  --violet: #afa1ff;
  --radius: 18px;
  --bar-gutter: clamp(12px, 3vw, 36px);
  font: 16px/1.55 system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 4px; }
.shell { width: min(1280px, calc(100% - 64px)); margin-inline: auto; }
.site-header { background: #14151e; border-bottom: 1px solid var(--edge); }
.header-inner { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.header-inner { min-height: 74px; padding-inline: var(--bar-gutter); }
.brand { display: inline-flex; align-items: center; gap: .42rem; font-weight: 800; white-space: nowrap; }
.brand > span:last-child { color: var(--muted); font-weight: 500; }
.brand-mark { display: block; flex: none; margin-right: .25rem; }
nav { display: flex; flex-wrap: wrap; gap: 4px; }
nav a { color: var(--muted); padding: .55rem .8rem; border-radius: 8px; font-size: .9rem; font-weight: 650; }
nav a:hover, nav a[aria-current] { background: #262839; color: var(--ink); }
nav a[aria-current] { color: var(--accent); }
.workspace { padding-block: clamp(30px, 6vw, 78px); }
h1 { font-size: clamp(2rem, 5vw, 4.3rem); line-height: 1; letter-spacing: -.065em; }
h2 { font-size: 1.25rem; letter-spacing: -.025em; }
h3 { font-size: 1rem; }
p { color: var(--muted); }
.hero p { margin-top: 14px; }
.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  align-items: center;
  gap: 24px;
  padding: clamp(28px, 6vw, 84px);
  border: 1px solid var(--edge);
  border-radius: 24px;
  overflow: hidden;
  background: radial-gradient(ellipse at 85% 65%, #383054, transparent 67%), var(--panel);
}
.hero h1 { font-size: clamp(3.5rem, 9vw, 8.4rem); line-height: .91; }
.hero p { font-size: 1.1rem; max-width: 28rem; margin-top: 24px; }
.accent { color: var(--accent); }
.hero-art { position: relative; width: min(100%, 310px); aspect-ratio: 1; justify-self: center; }
.hero-art i { position: absolute; inset: 15%; border-radius: 28%; transform: rotate(45deg); }
.hero-art i:nth-child(1) { border: 1px solid #8175ac; transform: rotate(28deg) scale(1.23); }
.hero-art i:nth-child(2) { background: #a897f3; box-shadow: 18px 18px #5d4a9b; }
.hero-art i:nth-child(3) { inset: 34%; background: var(--accent); box-shadow: inset 0 -10px #a3bf53; }
.tool-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.tool-card, .panel { background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius); padding: clamp(16px, 2vw, 28px); }
.tool-card { display: flex; flex-direction: column; gap: 10px; transition: border-color .15s; }
.tool-card:hover { border-color: var(--violet); }
.card-action { display: flex; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 14px; font-size: .92rem; font-weight: 700; color: var(--accent); }
.tool-icon { display: grid; place-items: center; position: relative; width: 44px; height: 44px; margin-bottom: 6px; border-radius: 12px; background: #322b4c; color: var(--violet); }
.board-icon::before { content: ''; width: 20px; height: 20px; border: 2px solid; border-radius: 3px; background: linear-gradient(currentColor,currentColor) center / 2px 100% no-repeat, linear-gradient(currentColor,currentColor) center / 100% 2px no-repeat; }
.bracket-icon { font-size: 1.75rem; }
.time-icon::before { content: ''; width: 22px; height: 22px; border: 2px solid; border-radius: 50%; }
.time-icon::after { content: ''; position: absolute; left: 21px; top: 15px; width: 6px; height: 8px; border-left: 2px solid; border-bottom: 2px solid; }
button { border: 1px solid var(--edge); border-radius: 9px; background: #232635; color: var(--ink); padding: .52rem .85rem; cursor: pointer; font-weight: 650; }
button:hover:enabled { border-color: var(--violet); background: #30334a; }
button:disabled { opacity: .48; cursor: default; }
button.primary { background: var(--accent); color: #1b2407; border-color: var(--accent); }
button.primary:hover:enabled { color: #1b2407; background: #ecffab; border-color: #ecffab; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
label { display: grid; gap: 6px; font-size: .88rem; color: var(--muted); font-weight: 650; }
input, select, textarea { width: 100%; min-width: 0; padding: .55rem .65rem; border: 1px solid var(--edge); border-radius: 8px; background: var(--field); color: var(--ink); }
.board-workspace { display: grid; grid-template-columns: minmax(270px, 350px) minmax(0, 1fr); gap: 16px; align-items: start; }
.controls { display: grid; gap: 12px; }
.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
textarea { resize: vertical; font: .9rem/1.35 ui-monospace, monospace; overflow: auto; }
details { border-top: 1px solid var(--edge); padding-top: 10px; font-size: .86rem; }
summary { cursor: pointer; font-weight: 650; }
.symbol-key { display: grid; grid-template-columns: max-content 1fr; gap: 6px 10px; margin-bottom: 0; color: var(--muted); }
.symbol-key dd { margin: 0; }
code, kbd { color: var(--violet); }
.drawing-surface { min-height: 200px; margin-top: 14px; padding: clamp(8px, 2vw, 24px); display: grid; place-items: center; border-radius: 12px; background: var(--field); }
.drawing-surface svg { display: block; width: 100%; max-height: 65vh; }
.svgline { fill: #161923; }
.irocube { stroke: #191b25; stroke-width: 4px; }
.timer-page { display: flex; flex-direction: column; min-height: 100dvh; }
.timer-page:fullscreen { background: var(--bg); overflow: auto; }
.timer-page:fullscreen .site-header,
.timer-page:fullscreen .timer-subnav,
.timer-page:fullscreen .timer-actions { display: none; }
#fullscreen-timer, #fullscreen-tournament { margin-inline-start: auto; }
.timer-page .workspace { display: flex; flex-direction: column; flex: 1; width: 100%; padding: 0; }
.tool-workspace { padding-block: clamp(12px, 2vw, 24px); }
.tool-subnav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem .85rem;
  padding: .4rem var(--bar-gutter);
  border-bottom: 1px solid var(--edge);
  background: var(--panel);
}
.tool-subnav h1 { font-size: 1.08rem; letter-spacing: -.02em; }
.timer-modes { display: flex; gap: 4px; }
.timer-modes button, .timer-limit { font-size: .86rem; }
.tool-subnav button { padding: .3rem .6rem; font-size: .86rem; }
.tool-subnav .button-row { gap: 4px; }
.timer-modes button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.timer-limit { display: flex; align-items: center; }
.timer-limit input { width: 6rem; padding: .3rem .4rem; }
.timer-panel { display: flex; flex-direction: column; flex: 1; gap: 8px; padding: 8px clamp(8px, 2vw, 24px); }
.clock {
  display: grid;
  grid-template-rows: auto minmax(3.5rem, 1fr) auto;
  flex: 1;
  min-height: 7rem;
  padding: 6px 8px;
  text-align: center;
  background: radial-gradient(ellipse at 50% 80%, #292840, transparent 75%), var(--field);
  border: 1px solid var(--edge);
  border-radius: 14px;
}
.clock span { color: var(--muted); font-size: .85rem; }
.clock-face { container-type: size; display: grid; place-items: center; min-width: 0; }
#clock-reading {
  color: var(--accent);
  font-family: ui-monospace, monospace;
  font-size: min(calc(158cqw / var(--clock-digits, 5)), 104cqh);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: .95;
}
.timer-actions { justify-content: center; align-items: center; }
.timer-actions button { min-width: 88px; padding-block: .35rem; }
.shortcut { font-size: .85rem; }
@media (max-height: 500px) and (orientation: landscape) {
  .timer-page .header-inner { flex-direction: row; align-items: center; min-height: 46px; padding-block: 4px; }
  .timer-page nav a { padding-block: .3rem; }
}
kbd { display: inline-block; padding: 0 .35rem; border: 1px solid var(--edge); border-radius: 4px; margin-right: .2rem; }
.empty-state { text-align: center; padding-block: 70px; }
.empty-state p { margin-top: 8px; }
.tournament-workspace { width: 100%; padding-inline: var(--bar-gutter); }
.bracket-panel { padding: clamp(12px, 1.5vw, 24px); }
.bracket-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.bracket-panel:fullscreen { overflow: auto; border-radius: 0; }
.bracket-scroll { overflow: auto; margin-top: 18px; padding: 5px; }
#bracket { display: flex; gap: 14px; min-height: 180px; }
.round-column { display: flex; flex-direction: column; gap: 12px; flex: 1 0 172px; min-width: 0; }
.round-column h3 { color: var(--muted); }
.matches, .winner-track { position: relative; height: var(--bracket-height, 0px); }
.matches > .match, .winner-track > .match { position: absolute; inset-inline: 0; }
.match { border: 1px solid var(--edge); border-radius: 12px; background: var(--field); padding: 7px; }
.entrant { display: flex; align-items: center; gap: 8px; padding: 5px; min-height: 44px; }
.entrant-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: .9rem; }
.entrant input { width: 54px; padding: .3rem; }
.advancing .entrant-name, .champion strong { color: var(--accent); }
.champion .match { padding: 12px; border-color: #61773a; }
.avatar { width: 27px; height: 27px; border-radius: 7px; object-fit: cover; flex: none; }
.avatar-fallback { display: grid; place-items: center; background: #302b48; color: var(--violet); font-weight: 700; font-size: .7rem; }
.muted, .tie { color: var(--muted); font-size: .8rem; }
.tie { padding: 4px 6px; }
dialog { width: min(650px, calc(100% - 28px)); max-height: 85vh; padding: 24px; color: var(--ink); background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius); }
dialog::backdrop { background: #090911c9; }
dialog form, #contestants { display: grid; gap: 12px; }
.contestant-heading { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.contestant-field { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; }
.contestant-field input[type=file] { font-size: .8rem; }
.dialog-actions { justify-content: flex-end; margin-top: 8px; }
#setup-error, #tournament-status, #board-status { color: #ffb6bd; }
#tournament-status { margin-bottom: 14px; }

@media (max-width: 740px) {
  .shell { width: calc(100% - 32px); }
  .header-inner { align-items: flex-start; flex-direction: column; gap: 8px; padding-block: 12px; }
  nav a { padding: .45rem .58rem; }
  .tool-grid, .board-workspace { grid-template-columns: 1fr; }
}
@media (max-width: 460px) {
  .hero { grid-template-columns: 1fr; }
  .hero-art { display: none; }
  .contestant-field { grid-template-columns: minmax(0, 1fr) auto; }
  .contestant-field input[type=text], .contestant-field input:not([type]) { grid-column: 1 / -1; }
}
