:root {
  --court-charcoal: #202123;
  --court-charcoal-soft: #282a2d;
  --court-orange: #f25b2c;
  --line: rgba(255, 255, 255, 0.96);
  --home-token: #f7fbf8;
  --away-token: #ffe4cf;
  --accent: #40d2c1;
  --danger: #ef4444;
  --blue-pad: #174bb8;
  --ui-bg: #f3f1ea;
  --ui-card: #ffffff;
  --ui-soft: #ebe8df;
  --ui-text: #202124;
  --ui-muted: #6b665d;
  --ui-border: #d8d2c6;
  --team-orange: #f25b2c;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: Arial, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8f6f1 100%);
  color: var(--ui-text);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 4px 12px rgba(64, 52, 38, 0.06);
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

button.active,
button:active {
  background: var(--team-orange);
  border-color: var(--team-orange);
  color: #fff;
  transform: translateY(1px);
  box-shadow: 0 2px 7px rgba(242, 91, 44, 0.22);
}

button.danger {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.45);
}

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 255, 255, 0.9) 0 1px, transparent 430px),
    linear-gradient(120deg, #ece8de 0%, #f8f6ef 44%, #e7e1d5 100%);
}

.topbar {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(216, 210, 198, 0.9);
  box-shadow: 0 8px 28px rgba(68, 58, 47, 0.08);
  backdrop-filter: blur(14px);
}

.brand {
  display: grid;
  gap: 1px;
  min-width: 170px;
}

.brand strong {
  font-size: clamp(19px, 2.5vw, 30px);
  font-weight: 950;
  letter-spacing: -0.03em;
  text-shadow: none;
  white-space: nowrap;
}

.brand .byline {
  margin-left: 6px;
  color: var(--ui-muted);
  font-size: 0.48em;
  font-weight: 500;
  letter-spacing: 0;
  vertical-align: baseline;
}

.brand span {
  color: var(--ui-muted);
  font-size: 11px;
  font-weight: 900;
}

.brand span.saved-flash {
  color: var(--team-orange);
}

.timer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--ui-border);
  backdrop-filter: blur(8px);
}

.timer input {
  width: 40px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: #111;
  text-align: center;
  font-weight: 950;
}

.timer strong {
  min-width: 50px;
  text-align: center;
  font-size: 18px;
  font-weight: 950;
}

.timer button {
  min-width: 32px;
  min-height: 32px;
  padding: 0 8px;
}

.mode-actions {
  display: flex;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--ui-border);
  backdrop-filter: blur(8px);
}

.mode-actions button {
  min-width: 36px;
  min-height: 34px;
  padding: 0 10px;
}

#mode-toggle {
  background: rgba(242, 91, 44, 0.96);
  color: #fff;
  border-color: transparent;
  padding-inline: 12px;
}

.workspace {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(3, auto);
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  background: rgba(235, 232, 223, 0.9);
}

.mode-switch button {
  min-height: 28px;
  padding: 4px 9px;
  border: 0;
  background: transparent;
  font-size: 13px;
}

.mode-switch button.active,
.quick-mode.active {
  background: rgba(242, 91, 44, 0.96);
  color: #fff;
}

.board-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2px 44px 8px 10px;
}

.board {
  position: relative;
  width: min(100%, calc((100vh - 68px) * 0.625));
  height: auto;
  aspect-ratio: 1000 / 1600;
  max-width: 820px;
  max-height: calc(100vh - 68px);
  overflow: hidden;
  border-radius: 4px;
  background: var(--court-charcoal);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

@supports (height: 100dvh) {
  .board {
    width: min(100%, calc((100dvh - 68px) * 0.625));
    max-height: calc(100dvh - 68px);
  }
}

.court-svg,
.draw-canvas,
.laser-layer,
.object-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.court-svg {
  z-index: 1;
}

.draw-canvas {
  z-index: 3;
  pointer-events: none;
}

.laser-layer {
  z-index: 5;
  pointer-events: none;
}

.object-layer {
  z-index: 4;
  pointer-events: none;
}

.free-zone,
.court-charcoal {
  fill: var(--court-charcoal);
}

.court-orange {
  fill: var(--court-orange);
}

.court-outline {
  fill: none;
  stroke: var(--line);
  stroke-width: 8;
}

.court-line {
  stroke: var(--line);
  stroke-width: 7;
  stroke-linecap: square;
}

.outside-mark {
  stroke: var(--line);
  stroke-width: 8;
  stroke-linecap: square;
}

.net-band {
  fill: #141516;
  stroke: rgba(255, 255, 255, 0.94);
  stroke-width: 2;
}

.net-mesh {
  fill: url(#net-mesh);
  stroke: rgba(255, 255, 255, 0.64);
  stroke-width: 1;
}

.net-line {
  stroke: rgba(255, 255, 255, 0.86);
  stroke-width: 2;
}

.net-post {
  stroke: rgba(255, 255, 255, 0.72);
  stroke-width: 3;
  stroke-linecap: round;
}

.object-token {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: var(--token-size, 46px);
  height: var(--token-size, 46px);
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  border: 3px solid rgba(10, 80, 82, 0.9);
  background: var(--home-token);
  color: #061d1e;
  font-size: var(--token-font, 13px);
  font-weight: 950;
  line-height: 1;
  letter-spacing: -0.12em;
  white-space: nowrap;
  overflow: visible;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.object-token::before {
  content: "";
  position: absolute;
  inset: var(--token-hit, -10px);
  border-radius: 50%;
}

.token-size-small {
  --token-size: 38px;
  --token-font: 11px;
  --token-hit: -15px;
  --token-border: 3px;
}

.token-size-base {
  --token-size: 46px;
  --token-font: 13px;
  --token-hit: -10px;
  --token-border: 3px;
}

.token-size-large {
  --token-size: 54px;
  --token-font: 15px;
  --token-hit: -8px;
  --token-border: 3px;
}

.object-token.away {
  background: var(--away-token);
  border-color: rgba(132, 63, 30, 0.9);
}

.object-token.selected {
  outline: 4px solid rgba(64, 210, 193, 0.58);
  outline-offset: 2px;
}

.object-token.dragging {
  cursor: grabbing;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.42);
}

.ball-token {
  font-size: 0;
  border: 1px solid rgba(255, 255, 255, 0.86);
  background: center / cover no-repeat url("./mikasa-ball.png");
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.32);
}

.ball-token::before {
  inset: -13px;
}

.panel-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  z-index: 27;
  min-width: 58px;
  min-height: 120px;
  padding: 12px 11px;
  transform: translateY(-50%);
  background: rgba(242, 91, 44, 0.96);
  color: #fff;
  border-color: transparent;
  border-radius: 999px;
  box-shadow: 0 12px 28px rgba(242, 91, 44, 0.24);
  touch-action: none;
}

.panel-toggle:active {
  transform: translateY(-50%) scale(0.98);
}

.panel-toggle::before {
  content: "";
  position: absolute;
  inset: -16px -12px;
  border-radius: 999px;
}

.tool-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 24;
  width: min(372px, 82vw);
  padding: 14px;
  background: rgba(255, 255, 255, 0.97);
  border-left: 1px solid var(--ui-border);
  color: var(--ui-text);
  transform: translateX(100%);
  transition: transform 0.18s cubic-bezier(.2, .8, .2, 1);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.tool-panel.open {
  transform: translateX(0);
}

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  border: 1px solid var(--ui-border);
  border-radius: 18px;
  background: rgba(235, 232, 223, 0.82);
  box-shadow: inset 0 1px 2px rgba(84, 71, 53, 0.06);
}

.panel-tabs::after {
  content: "";
  grid-column: 1 / -1;
  height: 1px;
  margin: 8px 2px 0;
  background: linear-gradient(90deg, transparent, rgba(145, 133, 115, 0.45), transparent);
}

.panel-tabs .tab {
  min-height: 38px;
  padding: 7px 8px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  box-shadow: none;
  color: #4b4d50;
  font-size: 14px;
}

.panel-tabs .tab.active {
  background: rgba(242, 91, 44, 0.14);
  color: #bd3b18;
  box-shadow: 0 3px 10px rgba(242, 91, 44, 0.12), inset 0 0 0 1px rgba(242, 91, 44, 0.18);
}

.panel-page {
  display: none;
}

.panel-page.active {
  display: grid;
  gap: 13px;
}

.panel-actions,
.tool-grid,
.color-row,
.preset-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.panel-actions button,
.tool-grid button,
.preset-row button,
.roster-player {
  min-height: 44px;
  border-radius: 14px;
}

.player-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
}

.player-actions button {
  width: 100%;
  min-height: 48px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 10px;
  border: 1px solid rgba(216, 210, 198, 0.85);
  border-radius: 18px;
  background: rgba(250, 248, 243, 0.74);
}

.tool-grid .draw-mode[data-tool="eraser"] {
  grid-column: 1 / -1;
  justify-self: center;
  min-width: min(180px, 72%);
}

.tool-grid .draw-mode[data-tool="ballTrajectory"],
.tool-grid .draw-mode[data-tool="laser"] {
  background: rgba(34, 211, 238, 0.1);
  border-color: rgba(34, 211, 238, 0.34);
}

.tool-grid .draw-mode[data-tool="laser"] {
  background: rgba(244, 63, 94, 0.1);
  border-color: rgba(244, 63, 94, 0.34);
}

.tool-grid .draw-mode.active,
.training-toolbar .draw-mode.active {
  background: var(--team-orange);
  border-color: var(--team-orange);
  color: #fff;
}

.color-chip {
  min-width: 46px;
}

.color-row {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-inline: auto;
}

.color-row .color-chip {
  width: 48px;
  min-width: 48px;
  height: 42px;
  padding: 0;
  font-size: 0;
}

.color-row .color-chip::before {
  margin: 0;
}

.color-chip::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--chip);
  border: 1px solid rgba(0, 0, 0, 0.28);
  vertical-align: -4px;
}

.range-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 28px;
  align-items: center;
  gap: 8px;
  font-weight: 900;
}

.setting-block {
  display: grid;
  gap: 8px;
  padding: 11px;
  border: 1px solid rgba(216, 210, 198, 0.85);
  border-radius: 18px;
  background: rgba(250, 248, 243, 0.74);
}

.setting-block h3 {
  margin: 0;
  color: var(--team-orange);
  font-size: 13px;
  letter-spacing: 0.06em;
}

.token-size-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.token-size-row button {
  min-height: 42px;
  padding: 7px 8px;
}

.roster-list {
  display: grid;
  gap: 14px;
}

.position-group {
  display: grid;
  gap: 7px;
}

.position-group h3 {
  margin: 0;
  color: var(--team-orange);
  font-size: 14px;
  letter-spacing: 0.08em;
}

.roster-player {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 24px;
  align-items: center;
  min-height: 42px;
  padding: 7px 9px;
  border-radius: 12px;
  background: var(--ui-soft);
  border: 1px solid var(--ui-border);
  text-align: left;
}

.roster-player.inserted {
  background: rgba(242, 91, 44, 0.12);
  border-color: rgba(242, 91, 44, 0.72);
}

.roster-player .number {
  color: var(--ui-muted);
}

.roster-player .check {
  color: var(--team-orange);
  font-size: 18px;
  text-align: right;
}

.training-toolbar {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  z-index: 35;
  display: none;
  gap: 7px;
  transform: translateX(-50%);
  padding: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid var(--ui-border);
  backdrop-filter: blur(14px);
}

.training-toolbar button {
  min-height: 34px;
  padding: 6px 10px;
}

.laser-dot {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: #ff1f5b;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 13px rgba(255, 31, 91, 0.72);
  animation: laserFade 1.2s ease-out forwards;
}

.show-ui {
  position: absolute;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  z-index: 36;
  display: none;
  background: rgba(242, 91, 44, 0.96);
  color: #fff;
}

.training-mode .topbar,
.whiteboard-mode .topbar {
  min-height: 40px;
  padding: calc(env(safe-area-inset-top) + 4px) 16px 3px;
  grid-template-columns: minmax(0, 1fr) auto;
  opacity: 0.96;
}

.training-mode .brand > span,
.whiteboard-mode .brand > span,
.training-mode .mode-actions,
.whiteboard-mode .mode-actions,
.training-mode .panel-toggle,
.whiteboard-mode .panel-toggle,
.whiteboard-mode .tool-panel {
  display: none;
}

.training-mode .timer,
.whiteboard-mode .timer {
  grid-column: 2;
}

.training-mode .board-wrap,
.whiteboard-mode .board-wrap {
  padding: 0 4px 42px;
}

.training-mode .board,
.whiteboard-mode .board {
  width: min(100%, calc((100vh - 44px) * 0.625));
  height: auto;
  aspect-ratio: 1000 / 1600;
  max-width: 900px;
  max-height: calc(100vh - 44px);
}

@supports (height: 100dvh) {
  .training-mode .board,
  .whiteboard-mode .board {
    width: min(100%, calc((100dvh - 44px) * 0.625));
    max-height: calc(100dvh - 44px);
  }
}

.training-mode .training-toolbar,
.whiteboard-mode .training-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100vw - 20px);
}

.whiteboard-mode .board {
  background: #fff;
  box-shadow: 0 22px 70px rgba(60, 48, 35, 0.18);
}

.whiteboard-mode .court-svg {
  display: none;
}

.ui-hidden .topbar,
.ui-hidden .training-toolbar {
  opacity: 0;
  pointer-events: none;
}

.timer.finished strong {
  animation: timerPulse 0.32s ease-in-out 6;
  color: #ffd166;
}

.icon-button {
  min-width: 42px;
  font-size: 24px;
  line-height: 1;
}

@keyframes timerPulse {
  0%, 100% { transform: scale(1); text-shadow: none; }
  50% { transform: scale(1.18); text-shadow: 0 0 18px rgba(255, 209, 102, 0.9); }
}

@keyframes laserFade {
  0% { opacity: 0.98; transform: translate(-50%, -50%) scale(1); }
  55% { opacity: 0.76; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.42); }
}

.ui-hidden .show-ui {
  display: block;
}

.drawing-hidden .draw-canvas {
  opacity: 0;
}

.object-locked .object-token {
  cursor: default;
}

@media (orientation: portrait) {
  .board-wrap {
    padding-left: 8px;
    padding-right: 48px;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .timer,
  .mode-actions {
    justify-content: center;
  }

  .board {
    width: min(100%, calc((100vh - 180px) * 0.625));
    height: auto;
    max-height: calc(100vh - 180px);
    aspect-ratio: 1000 / 1600;
  }
}
