  :root {
    color-scheme: dark;
    --bg: #100c18;
    --surface: #1a1425;
    --surface-raised: #241c32;
    --ink: #f8f4ff;
    --muted: #b4a9c2;
    --line: #4b3a5f;
    --accent: #d77bff;
    --accent-ink: #210d2c;
    --blue: #56c8ff;
    --orange: #ff943e;
    --green: #76d19b;
    --danger: #ff716f;
    --shadow: 0 18px 50px #08050c66;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }
  body[data-theme="black"] {
    --bg: #090b0e; --surface: #12161b; --surface-raised: #1a2027; --ink: #f4f7fa; --muted: #a4afb9;
    --line: #36414c; --accent: #58c7ff; --accent-ink: #051722; --blue: #58c7ff; --orange: #ff9a4e;
  }
  body[data-theme="white"] {
    color-scheme: light;
    --bg: #f4f5f7; --surface: #ffffff; --surface-raised: #edf0f4; --ink: #1b2028; --muted: #5d6874;
    --line: #d5dae1; --accent: #7137a1; --accent-ink: #ffffff; --blue: #138ec2; --orange: #df7020;
    --green: #258b59; --danger: #c93239; --shadow: 0 14px 40px #2030401c;
  }
  * { box-sizing: border-box; }
  body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); }
  button, input, select { font: inherit; }
  button { cursor: pointer; }
  [hidden] { display: none !important; }
  .app-shell { min-height: 100vh; }
  .topbar {
    position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 12px max(18px, calc((100vw - 1080px) / 2)); border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(16px);
  }
  .brand { display: flex; align-items: center; gap: 10px; text-align: left; color: var(--ink); }
  .brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 900; font-size: 22px; }
  .brand strong, .brand small { display: block; letter-spacing: .1em; }
  .brand strong { font-size: 13px; }
  .brand small { margin-top: 3px; color: var(--muted); font-size: 9px; }
  .topbar-actions { display: flex; align-items: center; gap: 8px; }
  .theme-switch select { max-width: 118px; padding: 9px 26px 9px 10px; }
  .main-content { width: min(100% - 32px, 940px); margin: 0 auto; padding: 30px 0 72px; }
  .screen { animation: enter .22s ease-out; }
  @keyframes enter { from { opacity: .5; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
  .hero { padding: 34px 0 40px; }
  .eyebrow { margin: 0 0 9px; color: var(--blue); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
  h1, h2, h3, p { margin-top: 0; }
  h1 { margin-bottom: 14px; font-size: clamp(34px, 8vw, 60px); line-height: 1.02; letter-spacing: -.055em; }
  h1 span { color: var(--accent); }
  .hero-copy { max-width: 480px; color: var(--muted); line-height: 1.65; }
  .section-heading { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin: 4px 0 18px; }
  h2 { margin-bottom: 0; font-size: 25px; letter-spacing: -.03em; }
  .count-pill, .tag { padding: 6px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 11px; white-space: nowrap; }
  .tournament-list { display: grid; gap: 12px; }
  .tournament-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; padding: 17px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
  .tournament-card h3 { margin: 0 0 7px; font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
  .tournament-meta { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; }
  .tournament-actions { display: flex; align-items: center; gap: 7px; }
  .status { display: inline-flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; }
  .status::before { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); content: ""; }
  .status-open::before { background: var(--green); box-shadow: 0 0 10px var(--green); }
  .status-finished::before { background: var(--orange); }
  .status-draft::before { background: var(--muted); }
  .stars { color: #ffc857; letter-spacing: 1px; white-space: nowrap; }
  .button, .icon-button, .button-plain {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px;
    font-weight: 750; transition: transform .15s, background .15s, opacity .15s;
  }
  .button:hover, .icon-button:hover { transform: translateY(-1px); }
  .button:disabled, .icon-button:disabled { cursor: not-allowed; opacity: .52; transform: none; }
  .button { min-height: 44px; padding: 0 16px; background: var(--accent); color: var(--accent-ink); }
  .button-small { min-height: 38px; padding: 0 12px; font-size: 12px; }
  .button-outline { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
  .button-danger { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); color: var(--danger); }
  .button-plain { padding: 0; background: transparent; }
  .icon-button { width: 42px; height: 42px; border: 1px solid var(--line); background: var(--surface-raised); color: var(--ink); font-size: 18px; }
  .icon-button.active { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 22%, var(--surface)); color: var(--blue); }
  .empty-state, .loading { padding: 28px 18px; border: 1px dashed var(--line); border-radius: 16px; color: var(--muted); text-align: center; }
  .screen-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 22px; }
  .screen-header h1 { margin: 2px 0 5px; font-size: clamp(25px, 6vw, 38px); overflow-wrap: anywhere; }
  .back-button { flex: 0 0 42px; }
  .header-copy { min-width: 0; flex: 1; }
  .score-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 18px; }
  .score-card { padding: 15px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); }
  .score-card-top { display: flex; justify-content: space-between; align-items: start; gap: 10px; margin-bottom: 13px; }
  .score-card h3 { margin: 0 0 4px; font-size: 16px; }
  .target { color: var(--muted); font-size: 12px; }
  .score-cumul { min-width: 70px; text-align: right; }
  .score-cumul strong { display: block; color: var(--blue); font-size: 24px; line-height: 1.1; }
  .score-cumul span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
  .score-buttons { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
  .score-option { min-height: 47px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-raised); color: var(--ink); font-size: 16px; font-weight: 800; }
  .score-option.selected { border-color: var(--blue); background: var(--blue); color: #06141c; }
  .score-guidance { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 11px; line-height: 1.35; white-space: nowrap; }
  .score-guidance > div { display: flex; gap: 3px; min-width: 0; }
  .score-guidance strong { color: var(--ink); font-size: 12px; }
  .score-save-state { min-height: 17px; margin-top: 8px; color: var(--muted); font-size: 11px; }
  .player-select-row { display: flex; gap: 9px; margin: 0 0 12px; }
  .player-select-row select { flex: 1; min-width: 0; }
  .notice { padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--orange) 45%, var(--line)); border-radius: 12px; background: color-mix(in srgb, var(--orange) 10%, var(--surface)); color: var(--ink); font-size: 12px; line-height: 1.5; }
  .overview-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
  .overview-table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 12px; }
  .overview-table th, .overview-table td { min-width: 70px; padding: 10px 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
  .overview-table th { position: sticky; top: 0; background: var(--surface-raised); }
  .overview-table .sort-header { width: 100%; padding: 0; border: 0; background: transparent; color: inherit; font-weight: 800; white-space: nowrap; }
  .overview-table .sort-header:hover, .overview-table .sort-header:focus-visible { color: var(--blue); }
  .overview-table th:first-child, .overview-table td:first-child { position: sticky; left: 0; z-index: 1; min-width: 110px; max-width: 150px; background: var(--surface); text-align: left; overflow-wrap: anywhere; }
  .overview-table th:first-child { z-index: 2; background: var(--surface-raised); }
  .overview-table .cumul-cell { color: var(--blue); font-weight: 800; }
  .admin-nav { display: flex; gap: 7px; overflow-x: auto; margin: 0 0 22px; padding-bottom: 5px; }
  .admin-nav button { flex: 0 0 auto; }
  .admin-panel { padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
  .admin-panel + .admin-panel { margin-top: 14px; }
  .form-grid { display: grid; gap: 14px; }
  .field { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
  input, select { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; outline: 0; background: var(--surface-raised); color: var(--ink); }
  input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 20%, transparent); }
  input:disabled, select:disabled { opacity: .65; }
  .field-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: end; }
  .cabinet-edit-row { display: grid; grid-template-columns: minmax(0, 1fr) 92px auto auto; gap: 8px; align-items: end; }
  .cabinet-order-actions { display: flex; gap: 4px; }
  .cabinet-order-actions .icon-button { width: 36px; min-height: 44px; }
  .cabinet-edit-row .field { min-width: 0; }
  .cabinet-list-row, .period-row { display: grid; grid-template-columns: minmax(0, 1fr) 95px 118px auto auto; gap: 9px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .cabinet-list-row input { min-width: 0; }
  .period-row { grid-template-columns: minmax(0, 1fr) 90px auto; }
  .period-order-actions { gap: 5px; }
  .save-cabinet-row.needs-save { outline: 2px solid var(--blue); }
  .cabinet-list-row:last-child, .period-row:last-child { border-bottom: 0; }
  .admin-tournament-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 13px 0; border-bottom: 1px solid var(--line); }
  .admin-tournament-row:last-child { border-bottom: 0; }
  .admin-tournament-row h3 { margin: 0 0 5px; font-size: 15px; }
  .admin-row-actions { display: flex; align-items: center; gap: 6px; }
  .small { min-height: 36px; padding: 0 10px; font-size: 12px; }
  .row-actions, .panel-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-top: 14px; }
  .drag-handle { color: var(--muted); cursor: grab; touch-action: none; }
  .toast { position: fixed; z-index: 10; right: 16px; bottom: 18px; left: 16px; max-width: 500px; margin: auto; padding: 12px 16px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(12px); transition: .2s; }
  .toast.show { opacity: 1; transform: translateY(0); }
  .toast.error { border-color: var(--danger); }
  .player-modal-backdrop {
    position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 12px;
    background: rgb(5 3 10 / 72%); backdrop-filter: blur(4px);
  }
  .player-modal {
    width: min(100%, 440px); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 20px;
    border: 1px solid var(--line); border-radius: 20px; background: var(--surface); color: var(--ink);
    box-shadow: var(--shadow);
  }
  .player-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
  .player-modal-header h2 { font-size: 23px; }
  .player-modal-close { flex: 0 0 44px; width: 44px; height: 44px; font-size: 23px; }
  .confirm-dialog-message { margin: 0; color: var(--ink); font-size: 14px; }
  .player-modal .field { gap: 8px; color: var(--ink); font-size: 14px; }
  .player-modal input { min-height: 50px; font-size: 16px; }
  .player-modal-help { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
  .player-modal-error { margin: 10px 0 0; color: var(--danger); font-size: 13px; line-height: 1.45; }
  .player-modal-status { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--muted); font-size: 12px; }
  .player-modal-spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: player-modal-spin .7s linear infinite; }
  @keyframes player-modal-spin { to { transform: rotate(360deg); } }
  .player-modal-actions { display: grid; gap: 9px; margin-top: 20px; }
  .player-modal-actions .button { width: 100%; min-height: 50px; }
  @media (min-width: 480px) {
    .player-modal { padding: 24px; }
    .player-modal-actions { display: flex; justify-content: flex-end; }
    .player-modal-actions .button { width: auto; min-width: 112px; }
  }
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
  @media (min-width: 660px) {
    .main-content { padding-top: 44px; }
    .tournament-card { padding: 21px 23px; }
    .form-grid.two-column { grid-template-columns: 1fr 1fr; }
    .score-entry-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
    .score-card { margin: 0; }
    .admin-panel { padding: 24px; }
  }
  @media (max-width: 440px) {
    .topbar { padding-right: 12px; padding-left: 12px; }
    .main-content { width: min(100% - 24px, 940px); padding-top: 20px; }
    .brand small { display: none; }
    .theme-switch select { max-width: 99px; padding-right: 19px; font-size: 11px; }
    .tournament-card { padding: 14px; }
    .tournament-actions { flex-direction: column; }
    .cabinet-list-row { grid-template-columns: minmax(0, 1fr) 75px 1fr auto; }
    .cabinet-edit-row { grid-template-columns: minmax(0, 1fr) 64px auto auto; }
    .cabinet-order-actions .icon-button { width: 32px; }
    .cabinet-list-row .status-select { grid-column: 1; grid-row: 2; }
    .cabinet-list-row .save-cabinet-row { grid-column: 2; grid-row: 2; }
    .cabinet-list-row .delete-row { grid-column: 3; grid-row: 2; }
    .period-row { grid-template-columns: minmax(0, 1fr) 68px auto; }
    .admin-tournament-row { grid-template-columns: minmax(0, 1fr); }
  }
