* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #101012;
  --panel: #1a1a1e;
  --panel-2: #26262b;
  --text: #e9e7e7;
  --muted: #9b9ba3;
  --accent: #d92a24;
  --accent-2: #ff6f68;
}

html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

[hidden] { display: none !important; }

/* ---------- Home screen ---------- */
.home {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 0 24px;
}

/* margin:auto centres the content when it fits and lets the page
   scroll naturally when it doesn't */
.home-inner {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  padding: 18px 0 40px;
  width: 100%;
}

.home .lang-select {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 5;
}

.lang-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #3c3c42;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  cursor: pointer;
}

.home-logo {
  width: 180px;
  height: auto;
  margin-bottom: -8px;
}

.home h1 {
  font-size: 40px;
  letter-spacing: 1px;
  text-align: center;
}

.play-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 500px;
}

.play-list:empty { display: none; }

.play-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 12px 8px;
  background: var(--panel);
  border: 1px solid #3c3c42;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
}

.play-card:hover { border-color: var(--accent); background: var(--panel-2); }

.play-card .card-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-del { margin-left: auto; }

.card-grip {
  color: #55555c;
  cursor: grab;
  touch-action: none;
  padding: 6px 4px;
  display: flex;
  flex: none;
}

.card-grip svg { width: 13px; height: 17px; }

.card-grip:hover { color: var(--muted); }

.card-del {
  background: none;
  border: none;
  color: #e05252;
  cursor: pointer;
  padding: 6px;
  border-radius: 7px;
  display: flex;
  flex: none;
}

.card-del svg { width: 15px; height: 15px; }

.card-del:hover { background: #e0525226; }

.play-card.dragging-card {
  opacity: 0.93;
  z-index: 10;
  position: relative;
  box-shadow: 0 10px 28px #000b;
  border-color: var(--accent);
  cursor: grabbing;
}

.play-card .meta {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.create-new {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 18px 46px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1.5px;
  cursor: pointer;
  box-shadow: 0 8px 26px #d92a2445;
}

.create-new:hover { background: #ee3b34; }

.backup-row {
  display: flex;
  gap: 10px;
}

.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: #000a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--panel);
  border: 1px solid #3c3c42;
  border-radius: 14px;
  padding: 24px;
  width: min(420px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 70px #000c;
}

.modal h2 { font-size: 19px; }

.modal p { color: var(--muted); font-size: 14px; line-height: 1.5; }

.modal input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #3c3c42;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
}

.modal input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.modal .field select,
.modal .field input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #3c3c42;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 15px;
  outline: none;
}

.modal .field input:focus,
.modal .field select:focus { border-color: var(--accent); }

#exportTiming {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.export-status {
  color: var(--accent-2) !important;
  font-variant-numeric: tabular-nums;
}

.btn.btn-danger-solid {
  background: #d05050;
  border-color: #d05050;
  color: #fff;
  font-weight: 600;
}

.btn.btn-danger-solid:hover { background: #e06060; border-color: #e06060; }

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 96px 10px 16px; /* right space reserved for the language select */
  background: var(--panel);
  flex-wrap: wrap;
}

/* pinned to the screen's top-right corner, level with the title row */
#langEditor {
  position: absolute;
  top: 9px;
  right: 14px;
}

.name-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.play-name {
  appearance: none;
  -webkit-appearance: none;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.3px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 4px 6px;
  max-width: 22vw;
  outline: none;
  cursor: text;
}

.play-name:focus {
  background: var(--panel-2);
  box-shadow: 0 0 0 1px var(--accent);
}

.pencil-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.pencil-btn:hover { color: var(--text); }

select, .btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #3c3c42;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 14px;
  cursor: pointer;
}

select:hover, .btn:hover { border-color: #5a5a63; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: #ee3b34; border-color: #ee3b34; }

.btn-danger:hover { border-color: #d05050; color: #ff8a8a; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn svg { width: 15px; height: 15px; flex: none; }

.btn.active {
  background: #ffd166;
  border-color: #ffd166;
  color: #1e232b;
  font-weight: 600;
}

/* ---------- Step chips ---------- */
.step-chips {
  position: relative; /* offsetParent for the chips' scroll math */
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  max-width: 100%;
  padding: 9px 9px 3px 2px;
  scrollbar-width: thin;
  scrollbar-color: #3c3c42 transparent;
  cursor: grab;
  touch-action: none;
}

.step-chips.dragging { cursor: grabbing; }

/* scrolled-away chips fade in from the left edge */
.step-chips.faded-left {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 42px);
  mask-image: linear-gradient(to right, transparent 0, #000 42px);
}

/* centered row of step actions above the steps carousel */
.step-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 6px 0 2px;
  background: var(--panel);
}

/* chips shrink to fit and stay centered; overflow turns into the carousel */
.steps-row {
  display: flex;
  justify-content: center;
  background: var(--panel);
  border-bottom: 1px solid #0009;
  padding: 0 10px 5px;
}

.step-actions .step-chip {
  padding: 6px 28px;
  font-size: 15px;
}

/* delete-play lives in its own section, separated from the player */
.delete-row {
  display: flex;
  justify-content: center;
  padding: 11px 0 13px;
  background: var(--bg);
  border-top: 1px solid #34343b;
}

.step-chips::-webkit-scrollbar { height: 5px; width: 5px; }
.step-chips::-webkit-scrollbar-track { background: transparent; }
.step-chips::-webkit-scrollbar-thumb { background: #3c3c42; border-radius: 3px; }

.step-chip {
  position: relative;
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #3c3c42;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
}

.step-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.step-chip.step-add {
  background: #2ea44f;
  border-color: #2ea44f;
  color: #fff;
  font-weight: 700;
}

.step-chip.step-add:hover:not(:disabled) { background: #36b95a; border-color: #36b95a; }

.step-chip.step-add:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.step-chip.step-reset {
  background: #d05050;
  border-color: #d05050;
  color: #fff;
  font-weight: 700;
}

.step-chip.step-reset:hover { background: #e06060; border-color: #e06060; }

.chip-del {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #d84343;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px #000a;
  border: 1.5px solid var(--panel);
}

.chip-del svg { width: 11px; height: 11px; }

.chip-del:hover { background: #ef5a5a; transform: scale(1.12); }

/* ---------- Stage ---------- */
.stage-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  padding: 12px;
  container-type: size;
}

/* Fit the container in both directions while keeping the exact court
   aspect ratio — token positions are percentages of this box, so the
   ratio must never distort. */
.stage {
  position: relative;
  width: min(100cqw, calc(100cqh * 57 / 62));
  aspect-ratio: 57 / 62;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 40px #000a;
  touch-action: none;
  transform-origin: center center;
}

.stage-wrap { overflow: hidden; }

/* ---------- Zoom control ---------- */
.zoom-ctrl {
  position: absolute;
  right: 14px;
  bottom: 12px;
  display: flex;
  gap: 2px;
  background: var(--panel);
  border: 1px solid #3c3c42;
  border-radius: 9px;
  padding: 3px;
  z-index: 30;
}

.zoom-ctrl button {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  min-width: 30px;
}

.zoom-ctrl button:hover { background: var(--panel-2); }

#zoomLabel { font-size: 12px; color: var(--muted); min-width: 46px; }

.stage svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#arrowsSvg { pointer-events: none; }

#tokens {
  position: absolute;
  inset: 0;
}

/* ---------- Tokens ---------- */
.token {
  position: absolute;
  width: 5.8%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: clamp(10px, 2.2vmin, 20px);
  color: #fff;
  cursor: grab;
  user-select: none;
  touch-action: none;
  box-shadow: 0 2px 6px #0008, inset 0 -2px 4px #0004;
}

.token.dragging { cursor: grabbing; box-shadow: 0 6px 14px #000b; z-index: 10; }

.token.offense {
  background: radial-gradient(circle at 35% 30%, #4d8fe0, #2b5ea8);
  border: 2px solid #cfe2ff;
}

.token.ball {
  width: 3.2%;
  background: radial-gradient(circle at 35% 30%, #ff9c50, #d35f14);
  border: 2px solid #7a3c0c;
}

.token.ball::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    linear-gradient(#7a3c0c, #7a3c0c) center/100% 6% no-repeat,
    linear-gradient(#7a3c0c, #7a3c0c) center/6% 100% no-repeat;
  opacity: 0.7;
}

.playing .token { cursor: default; }

/* ---------- Player bar ---------- */
.player-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--panel);
  border-top: 1px solid #0009;
}

.pbtn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}

.pbtn:hover { background: var(--panel-2); }

.pbtn-main {
  font-size: 22px;
  background: var(--accent);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pbtn-main:hover { background: #ee3b34; }

.timeline-wrap {
  flex: 1;
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
}

.timeline-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.timeline-tick {
  position: absolute;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5a5a63;
  transform: translate(-50%, -50%);
}

.timeline-tick.passed { background: var(--accent-2); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #3c3c42;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px #0008;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px #0008;
}

.step-indicator {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.speed-select { padding: 5px 8px; font-size: 13px; }

/* ---------- Toolbar (floating over everything, drag anywhere) ---------- */
.toolbar {
  position: fixed;
  display: flex;
  gap: 4px;
  padding: 6px;
  background: #fdfdfd;
  border-radius: 12px;
  box-shadow: 0 4px 18px #0007;
  z-index: 60;
}

.tool {
  position: relative;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #3d4148;
  cursor: pointer;
  padding: 0;
}

.tool svg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
}

.tool:hover:not(:disabled) { background: #ececf1; }

.tool:disabled {
  color: #c4c8ce;
  cursor: not-allowed;
}

.tool-sep {
  width: 1px;
  align-self: stretch;
  margin: 5px 3px;
  background: #e3e5e9;
}

.tool-grip {
  width: 16px;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c6cad0;
  cursor: grab;
  touch-action: none;
}

.tool-grip svg { width: 14px; height: 18px; }

.tool-grip:hover { color: #8a919c; }

.toolbar { touch-action: none; }

.tool:disabled .knum { color: #d5d8dd; }

.tool.active {
  background: #fbdedc;
  color: #b8221c;
}

.tool .knum {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 9px;
  color: #9aa0aa;
}

.tool.active .knum { color: #b8221c; }

/* Tool cursors */
body[data-tool="arrow"] .token,
body[data-tool="screen"] .token { cursor: crosshair; }
body[data-tool="eraser"] .token { cursor: pointer; }
body[data-tool="eraser"] .arrow-path,
body[data-tool="eraser"] .screen-cap {
  pointer-events: stroke;
  cursor: pointer;
}

/* ---------- Arrows & screens ---------- */
.arrow-path {
  stroke: rgba(255,255,255,0.9);
  stroke-width: 0.45;
  fill: none;
  stroke-linecap: round;
}

.arrow-path.ball-path {
  stroke-dasharray: 1.2 1;
}

.arrow-path.screen { stroke: #ffd166; }

.screen-cap {
  stroke: #ff5252;
  stroke-width: 0.55;
  stroke-linecap: round;
}

.arrow-path.ghost, .screen-cap.ghost { opacity: 0.45; }
.arrow-path.preview, .screen-cap.preview { opacity: 0.7; }

/* ---------- Handles ---------- */
#handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.handle {
  position: absolute;
  width: 13px;
  height: 13px;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2.5px solid #2d2d31;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  z-index: 15;
}

.handle.mid { border-radius: 50%; }
.handle.end { border-radius: 3px; }

.handle.rot {
  border-radius: 50%;
  border-color: #ff5252;
  cursor: grab;
}

.handle.rot:hover { background: #ffd7d7; }

.handle:hover { background: #f0d3d1; }

.playing .toolbar { opacity: 0.35; pointer-events: none; }

@media (max-width: 1100px) {
  .chip-word { display: none; }
  .step-chip { padding: 6px 10px; }
}

@media (max-width: 900px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  .play-name { max-width: 34vw; }
}

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  .topbar { padding: 6px 76px 6px 8px; gap: 6px; }
  #langEditor { top: 6px; right: 8px; }
  .topbar .btn { padding: 5px 8px; font-size: 12px; border-radius: 7px; }
  .play-name { font-size: 15px; padding: 3px 4px; max-width: 40vw; }
  .lang-select { padding: 4px 6px; font-size: 12px; }
  /* steps as a swipeable carousel — single row, no visible scrollbar */
  .step-chips {
    max-width: 100%;
    padding-top: 8px;
    gap: 5px;
    scrollbar-width: none;
  }
  .step-chips::-webkit-scrollbar { display: none; }
  .step-chip { padding: 5px 9px; font-size: 12px; }

  .stage-wrap { padding: 8px; }
  .toolbar { padding: 4px; gap: 2px; border-radius: 10px; }
  .tool { width: 32px; height: 32px; }
  .tool svg { width: 17px; height: 17px; }
  .tool .knum { display: none; }
  .tool-sep { margin: 4px 2px; }

  /* narrow screens: only prev / play / next — no progress bar */
  .player-bar { padding: 8px 10px; gap: 30px; justify-content: center; }
  .timeline-wrap, .step-indicator, .speed-select { display: none; }
  .pbtn { font-size: 18px; padding: 6px 8px; }
  .pbtn-main { width: 46px; height: 46px; font-size: 20px; }

  .home { gap: 22px; }
  .home h1 { font-size: 30px; }
  .create-new { padding: 14px 32px; font-size: 16px; letter-spacing: 1px; }
  .backup-row { flex-wrap: wrap; justify-content: center; }
  .play-card { padding: 13px 16px; font-size: 15px; }
  .modal { padding: 18px; gap: 12px; }
}
