:root {
  --bg: #121418;
  --bg-elevated: #1a1d24;
  --bg-panel: #22262e;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8eaef;
  --text-muted: #9aa3b2;
  --accent: #5c9fd6;
  --accent-dim: rgba(92, 159, 214, 0.2);
  --success: #4caf7a;
  --danger: #e05555;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --panel-width: 380px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  margin: 0;
  height: 100%;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
  overflow-y: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  flex-shrink: 0;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg) 100%);
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.app-subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 52ch;
}

.app-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-width) 1fr;
  gap: 0;
  align-items: stretch;
  overflow: hidden;
}

.control-panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 0.65rem 0.85rem 1.25rem;
  min-height: 0;
  overflow-y: auto;
  box-shadow: inset -1px 0 0 var(--border);
}

.stage {
  padding: 1rem 1.25rem 1.25rem;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

.canvas-shell {
  display: inline-block;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  background: #0d0f12;
  line-height: 0;
}

.canvas-shell canvas {
  display: block;
  vertical-align: top;
}

.ctrl-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.ctrl-section--embed {
  margin-top: 1rem;
  margin-bottom: 0;
}

.ctrl-section__title {
  list-style: none;
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ctrl-section__title::-webkit-details-marker {
  display: none;
}

.ctrl-section__title::after {
  content: "";
  margin-left: auto;
  width: 0.45em;
  height: 0.45em;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  opacity: 0.7;
}

details[open] > .ctrl-section__title::after {
  transform: rotate(45deg);
}

.ctrl-section__title:hover {
  color: var(--text);
  background: var(--accent-dim);
}

.ctrl-section__body {
  padding: 0.65rem 0.75rem 0.85rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field--inline {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
}

.field--inline .field__label {
  min-width: 5.5rem;
  margin-bottom: 0;
}

.field--compact {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.field__label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.field__value {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.field__input {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.875rem;
}

.field__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field__input--num {
  width: 3.5rem;
  text-align: center;
}

.range {
  width: 100%;
  accent-color: var(--accent);
  height: 0.35rem;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
}

.check input {
  margin-top: 0.2rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.check span {
  line-height: 1.35;
}

.phase-badge {
  margin: 0;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 183, 77, 0.12);
  border: 1px solid rgba(255, 183, 77, 0.35);
  color: #ffb74d;
  font-size: 0.8125rem;
  font-weight: 600;
}

.btn {
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--success);
  color: #fff;
}

.btn--primary:hover {
  filter: brightness(1.08);
}

.btn--secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}

.btn--secondary:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: #252a33;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn--ghost:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn--danger {
  background: rgba(224, 85, 85, 0.18);
  color: #ff9a9a;
  border-color: rgba(224, 85, 85, 0.45);
}

.btn--danger:hover {
  background: rgba(224, 85, 85, 0.28);
}

.btn--block {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  margin-top: 0.85rem;
  padding: 0.65rem 1rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.stats-bar__item {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.stats-bar__k {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-bar__v {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stats-bar__muted {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8rem;
}

.stats-bar__victory {
  margin: 0;
  flex: 1 1 100%;
  color: #7dffb3;
  font-weight: 600;
}

.hint {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.hint--small {
  font-size: 0.78rem;
  line-height: 1.4;
}

.tournament-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
}

.tournament-list {
  text-align: left;
  max-height: 120px;
  overflow: auto;
  margin: 0;
  padding: 0.35rem 0 0.35rem 1.25rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.tournament-results {
  margin-top: 0.5rem;
  font-size: 0.875rem;
}
