:root {
  color-scheme: dark;
  --bg: #07110d;
  --panel: rgba(14, 29, 22, .94);
  --panel-2: #11271d;
  --line: rgba(207, 240, 219, .13);
  --text: #eef8f1;
  --muted: #91aa9a;
  --accent: #c8ff58;
  --accent-ink: #122008;
  --danger: #ff746c;
  --home: #e8ff52;
  --away: #ff596d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; width: 100%; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif; }
body { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button, .button-label { color: var(--text); background: #163126; border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; cursor: pointer; transition: .16s ease; }
button:hover, .button-label:hover { border-color: rgba(200, 255, 88, .55); background: #1b3b2d; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { width: 100%; color: var(--text); background: #091b13; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
textarea { resize: vertical; }
.primary-button { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 800; }
.primary-button:hover { background: #dbff8f; }
.ghost-button { background: transparent; }
.compact { padding: 8px 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); }
.section-label { margin: 0; color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .16em; }

.auth-gate { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #183c2a 0, #07110d 52%); }
.auth-card { width: min(430px, calc(100% - 36px)); padding: 44px; text-align: center; background: rgba(8, 23, 16, .88); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 30px 90px #0008; }
.brand-mark { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 22px; color: var(--accent-ink); background: var(--accent); border-radius: 15px; font-weight: 950; letter-spacing: -.08em; }
.brand-mark.small { width: 34px; height: 34px; margin: 0; border-radius: 10px; font-size: 14px; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 850; letter-spacing: .18em; }
.auth-card h1 { margin: 10px 0; font-size: clamp(27px, 6vw, 39px); letter-spacing: -.04em; }
.auth-card p:not(.eyebrow) { color: var(--muted); line-height: 1.7; }
.auth-card button { width: 100%; margin-top: 12px; }

.app-shell { height: 100dvh; min-width: 980px; overflow: hidden; }
.topbar { height: 62px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: #091711; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; }
.brand > div:last-child { display: flex; flex-direction: column; }
.brand strong { font-size: 14px; }
.brand span:not(.brand-mark) { color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.top-actions { display: flex; align-items: center; gap: 7px; }
.top-actions button, .button-label { padding: 8px 10px; font-size: 12px; }
.button-label input { display: none; }
.save-status { margin-right: 5px; color: var(--muted); font-size: 11px; }
.danger-text { color: #ff9c95; }

.workspace { height: calc(100dvh - 62px); min-height: 0; display: grid; grid-template-columns: 250px minmax(500px, 1fr) 220px; gap: 10px; padding: 10px; }
.left-panel, .right-panel { overflow: auto; border-radius: 14px; padding: 16px; }
.left-panel section + section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.match-inputs, .formation-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 7px; margin-top: 11px; }
.match-inputs input { text-align: center; font-weight: 800; }
.match-inputs span { color: var(--muted); font-size: 11px; }
.fotmob-box { display: grid; gap: 7px; margin-top: 12px; }
.fotmob-box small { color: var(--muted); font-size: 10px; line-height: 1.5; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading > span { color: var(--muted); font-size: 10px; }
.icon-button { padding: 4px 8px; }
.formation-row { grid-template-columns: 1fr 1fr; }
.team-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.team-tabs button { font-size: 11px; }
.team-tabs button.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 850; }
.roster-list { display: grid; gap: 5px; }
.roster-caption { margin: 10px 0 6px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .1em; }
.bench-caption { margin-top: 15px; }
.roster-player { display: grid; grid-template-columns: 27px minmax(0, 1fr) 36px; align-items: center; gap: 8px; width: 100%; padding: 7px; text-align: left; background: transparent; }
.roster-player .number { display: grid; place-items: center; width: 25px; height: 25px; color: var(--accent-ink); background: var(--player-color); border-radius: 50%; font-size: 10px; font-weight: 900; }
.roster-player .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.roster-player .position { color: var(--muted); font-size: 10px; text-align: right; }
.roster-player.sub-target { border-color: var(--accent); background: rgba(200, 255, 88, .08); }
.bench-player { grid-template-columns: 27px minmax(0, 1fr) auto; }
.bench-player .sub-button { padding: 5px 7px; color: var(--accent); background: transparent; font-size: 9px; }
.bench-empty { padding: 10px 2px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.substitution-hint { margin: 8px 0; padding: 8px; color: var(--accent); background: rgba(200, 255, 88, .08); border: 1px solid rgba(200, 255, 88, .35); border-radius: 8px; font-size: 10px; line-height: 1.5; }

.board-column { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px; }
.board-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: 7px; border-radius: 13px; }
.tool-buttons, .history-buttons { display: flex; gap: 5px; }
.tool-buttons button { display: flex; align-items: center; gap: 6px; min-width: 52px; justify-content: center; font-size: 14px; }
.tool-buttons button span { font-size: 10px; }
.tool-buttons button.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 850; }
.history-buttons button { font-size: 11px; }
#playerTextToggle.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 850; }
.board-frame { position: relative; min-width: 0; min-height: 0; overflow: hidden; display: grid; place-items: center; background: #10281c; border: 1px solid var(--line); border-radius: 15px; }
#board { display: block; width: 100%; height: 100%; max-width: 100%; max-height: 100%; object-fit: contain; background: #315f2b; box-shadow: 0 22px 70px #0007; touch-action: none; user-select: none; }
.scene-bar { display: flex; align-items: center; gap: 8px; min-height: 58px; padding: 7px 10px; border-radius: 13px; }
.scene-title { min-width: 120px; }
.scene-title small { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; }
.scene-list { flex: 1; display: flex; gap: 7px; overflow-x: auto; }
.scene-button { min-width: 105px; padding: 9px 11px; text-align: left; font-size: 10px; }
.scene-button.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.scene-button strong { display: block; margin-bottom: 3px; font-size: 11px; }
.add-scene { white-space: nowrap; }

.right-panel { padding: 17px; }
.inspector-empty { min-height: 230px; display: grid; place-content: center; color: var(--muted); text-align: center; font-size: 11px; line-height: 1.7; }
.inspector-empty > span { color: #4d6c59; font-size: 32px; }
#inspectorForm { display: grid; gap: 13px; margin-top: 18px; }
#inspectorForm label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 700; }
.split-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.danger-button { color: #ffd1cd; background: #4e211f; border-color: #873b36; margin-top: 5px; }
.shortcuts { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }
.shortcuts dl { display: grid; gap: 8px; }
.shortcuts dl div { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 10px; }
.shortcuts dt { min-width: 44px; padding: 4px 7px; color: var(--text); background: #091b13; border: 1px solid var(--line); border-radius: 5px; text-align: center; }
.shortcuts dd { margin: 0; }

dialog { color: var(--text); background: #10241b; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 25px 80px #0009; }
dialog::backdrop { background: #0009; }
dialog form { width: min(350px, 70vw); }
dialog h2 { margin-top: 0; font-size: 17px; }
dialog form > div { display: flex; justify-content: flex-end; gap: 7px; margin-top: 14px; }

.pitch-line { fill: none; stroke: rgba(240,255,245,.72); stroke-width: 3; vector-effect: non-scaling-stroke; }
.player-node { cursor: grab; }
.player-node:active { cursor: grabbing; }
.player-node.selected .player-disc { stroke: var(--accent); stroke-width: 6; }
.player-disc { stroke: rgba(0,0,0,.58); stroke-width: 4; filter: url(#shadow); }
.player-number { fill: #10150f; font-size: 16px; font-weight: 950; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.player-label { fill: white; stroke: #07110d; stroke-width: 4; paint-order: stroke; font-size: 13px; font-weight: 800; text-anchor: middle; pointer-events: none; }
.player-position { fill: #dce8df; stroke: #07110d; stroke-width: 3; paint-order: stroke; font-size: 10px; font-weight: 750; text-anchor: middle; pointer-events: none; }
.drawing { cursor: pointer; }
.drawing.selected { filter: drop-shadow(0 0 5px var(--accent)); }
.drawing-line { fill: none; stroke-linecap: round; stroke-width: 7; }
.drawing-zone { stroke-width: 4; stroke-dasharray: 10 7; }
.drawing-text { font-size: 28px; font-weight: 850; paint-order: stroke; stroke: #07110d; stroke-width: 6; }
.ball { cursor: grab; filter: url(#shadow); }
#board.hide-player-text .player-label,
#board.hide-player-text .player-position { display: none; }

body.web-optimized #board { box-shadow: none; }
body.web-optimized .player-disc,
body.web-optimized .ball { filter: none; }
body.web-optimized .drawing.selected { filter: none; }

@media (max-width: 1400px), ((hover: none) and (pointer: coarse)) {
  .player-disc { r: 42px; stroke-width: 6; }
  .player-number { font-size: 28px; }
  .player-label { font-size: 20px; stroke-width: 6; }
  .player-position { font-size: 15px; stroke-width: 4; }
  .drawing-text { font-size: 44px; stroke-width: 8; }
}

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 220px minmax(480px, 1fr) 190px; }
  .tool-buttons button span { display: none; }
  .tool-buttons button { min-width: 38px; }
}

@media (max-width: 1024px) {
  :root { --mobile-dock-height: 190px; }

  body { overflow: hidden; }
  .app-shell { min-width: 0; height: 100dvh; }

  .topbar {
    position: fixed;
    z-index: 40;
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    min-height: 58px;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  .brand { min-width: 0; }
  .brand > div:last-child { display: none; }
  .save-status { display: none; }
  .top-actions {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .top-actions::-webkit-scrollbar { display: none; }
  .top-actions button,
  .button-label {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 10px;
    white-space: nowrap;
  }

  .workspace {
    position: relative;
    height: 100dvh;
    min-height: 0;
    display: block;
    padding: 8px 8px var(--mobile-dock-height);
    overflow: hidden;
  }

  .board-column {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
  }

  .board-frame {
    grid-row: 1;
    align-self: stretch;
    border-radius: 10px;
  }

  #board {
    width: 100%;
    height: 100%;
    box-shadow: none;
  }

  .player-disc { r: 44px; stroke-width: 6; }
  .player-number { font-size: 29px; }
  .player-label { font-size: 21px; stroke-width: 6; }
  .player-position { font-size: 16px; stroke-width: 4; }
  .drawing-text { font-size: 48px; stroke-width: 8; }

  .board-toolbar,
  .scene-bar {
    position: fixed;
    z-index: 45;
    left: 8px;
    right: 8px;
    border-radius: 10px;
    backdrop-filter: blur(12px);
  }

  .board-toolbar {
    bottom: calc(66px + env(safe-area-inset-bottom));
    min-height: 52px;
    justify-content: flex-start;
    gap: 8px;
    overflow-x: auto;
  }

  .tool-buttons,
  .history-buttons {
    flex: 0 0 auto;
  }

  .tool-buttons button {
    min-width: 42px;
    min-height: 38px;
  }

  .history-buttons button {
    min-height: 38px;
    white-space: nowrap;
  }

  .scene-bar {
    bottom: calc(121px + env(safe-area-inset-bottom));
    min-height: 56px;
    overflow: hidden;
  }

  .scene-title { min-width: auto; }
  .scene-title small { display: none; }
  .scene-list { min-width: 0; }
  .scene-button { min-width: 86px; }

  .left-panel,
  .right-panel {
    position: absolute;
    z-index: 25;
    top: 8px;
    bottom: calc(var(--mobile-dock-height) + 8px);
    width: clamp(138px, 23vw, 220px);
    max-height: none;
    padding: 10px;
    border-radius: 10px;
    background: rgba(14, 29, 22, .88);
    backdrop-filter: blur(10px);
  }

  .left-panel {
    left: 8px;
    transform-origin: left center;
  }

  .right-panel {
    right: 8px;
    transform-origin: right center;
  }

  .left-panel section + section {
    margin-top: 14px;
    padding-top: 12px;
  }

  .match-inputs,
  .formation-row {
    gap: 5px;
    margin-top: 8px;
  }

  .fotmob-box { display: none; }
  .team-tabs { gap: 4px; }
  .roster-player {
    grid-template-columns: 25px minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
  }
  .roster-player .position { display: none; }
  .bench-player .sub-button { display: none; }
  .inspector-empty { min-height: 120px; }
  .shortcuts { display: none; }
  #inspectorForm { gap: 10px; margin-top: 12px; }
  .split-fields { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  :root { --mobile-dock-height: 205px; }

  .workspace { padding: 6px 6px var(--mobile-dock-height); }
  .board-toolbar,
  .scene-bar {
    left: 6px;
    right: 6px;
  }

  .topbar {
    min-height: 64px;
    align-items: flex-start;
  }

  .brand-mark.small {
    width: 30px;
    height: 30px;
    border-radius: 8px;
  }

  .top-actions button,
  .button-label {
    min-height: 34px;
    padding: 7px 9px;
    font-size: 11px;
  }

  .board-toolbar {
    bottom: calc(70px + env(safe-area-inset-bottom));
    min-height: 50px;
    padding: 5px;
  }

  .player-disc { r: 48px; stroke-width: 7; }
  .player-number { font-size: 30px; }
  .player-label { font-size: 22px; stroke-width: 7; }
  .player-position { font-size: 16px; stroke-width: 5; }
  .drawing-text { font-size: 52px; stroke-width: 9; }

  .scene-bar {
    bottom: calc(123px + env(safe-area-inset-bottom));
    min-height: 70px;
    padding: 6px;
  }

  .scene-title { display: none; }
  .add-scene { padding-left: 9px; padding-right: 9px; }

  .left-panel,
  .right-panel {
    top: 6px;
    bottom: calc(var(--mobile-dock-height) + 6px);
    width: min(132px, 34vw);
    padding: 8px;
  }

  .left-panel { left: 6px; }
  .right-panel { right: 6px; }

  .section-label { font-size: 9px; letter-spacing: .1em; }
  input,
  select,
  textarea {
    padding: 7px 8px;
    font-size: 11px;
  }

  .match-inputs {
    grid-template-columns: 1fr;
  }

  .match-inputs span { display: none; }
  .formation-row { grid-template-columns: 1fr; }
  .section-heading > span,
  .roster-caption,
  .bench-caption,
  .bench-list { display: none; }
  .roster-list { gap: 4px; }
  .roster-player .number {
    width: 22px;
    height: 22px;
    font-size: 9px;
  }
  .roster-player .name { font-size: 10px; }

  .right-panel {
    width: min(118px, 30vw);
  }

  .inspector-empty {
    min-height: 80px;
    font-size: 10px;
  }

  .inspector-empty > span { display: none; }
  #inspectorForm label { font-size: 9px; }
  textarea[name="note"] { display: none; }
  .danger-button { padding-left: 7px; padding-right: 7px; font-size: 10px; }
}

@media (max-width: 1024px) {
  .left-panel,
  .right-panel {
    width: min(220px, 72vw);
    transition: transform .18s ease;
  }

  .left-panel {
    transform: translateX(calc(-100% + 38px));
    box-shadow: 12px 0 35px rgba(0, 0, 0, .28);
  }

  .right-panel {
    transform: translateX(calc(100% - 38px));
    box-shadow: -12px 0 35px rgba(0, 0, 0, .28);
  }

  .left-panel:hover,
  .left-panel:focus-within,
  .right-panel:hover,
  .right-panel:focus-within {
    transform: translateX(0);
  }

  .left-panel::after,
  .right-panel::after {
    position: sticky;
    bottom: 0;
    display: grid;
    place-items: center;
    height: 30px;
    margin: 10px -4px -4px;
    color: var(--accent);
    background: rgba(9, 27, 19, .9);
    border: 1px solid rgba(200, 255, 88, .32);
    border-radius: 8px;
    font-size: 10px;
    font-weight: 850;
    letter-spacing: .08em;
  }

  .left-panel::after { content: "MATCH"; }
  .right-panel::after { content: "EDIT"; }
}

@media (max-height: 820px) {
  .topbar { height: 52px; }
  .workspace { height: calc(100dvh - 52px); padding: 7px; gap: 7px; }
  .board-toolbar { min-height: 44px; padding: 4px; }
  .board-toolbar button { padding-top: 6px; padding-bottom: 6px; }
  .scene-bar { min-height: 48px; padding: 5px 8px; }
  .scene-title small { display: none; }
  .scene-button { padding: 6px 8px; }
  .left-panel, .right-panel { padding: 12px; }
}

@media (max-width: 1024px) and (max-height: 820px) {
  .topbar {
    height: auto;
    min-height: 56px;
  }

  .workspace {
    height: 100dvh;
    padding: 8px 8px var(--mobile-dock-height);
    gap: 0;
  }

  .board-toolbar { min-height: 50px; }
  .scene-bar { min-height: 54px; }
  .left-panel,
  .right-panel { padding: 10px; }
}
