/* Touch Tactics — pitchside clipboard */

:root {
  --chrome: #f3f5f0;
  --chrome-2: #e9ede4;
  --edge: #d4dacd;
  --ink: #16211b;
  --ink-soft: #4c5a51;

  --turf: #2f7a45;
  --turf-stripe: #2b7040;
  --turf-td: #276b3c;
  --turf-out: #245f37;
  --mark: rgba(255, 255, 255, 0.92);

  --attack: #ee5a1f;
  --attack-deep: #c74712;
  --defence: #1d4f8f;
  --ball: #ffd44d;
  --run: #ff7a33;

  --radius: 10px;
  --shadow: 0 10px 30px rgba(22, 33, 27, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  overflow: hidden;
  background: var(--chrome);
  color: var(--ink);
  font-family: Barlow, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2.5px solid var(--defence);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--edge);
  background: var(--chrome);
  min-height: 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  color: inherit;
  text-decoration: none;
}

.brand-ball { width: 21px; height: 21px; }

.brand-name {
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-style: italic;
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transform: translateY(-1px);
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-left: 4px;
  flex-shrink: 0;
}

.top-nav a {
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.top-nav a:hover { color: var(--ink); text-decoration: underline; }

.play-name {
  flex: 1;
  min-width: 60px;
  max-width: 340px;
  margin-left: auto;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: 500 15px Barlow, sans-serif;
  text-align: right;
  text-overflow: ellipsis;
}

.play-name:hover { border-color: var(--edge); }

.play-name:focus {
  outline: none;
  border-color: var(--defence);
  background: #fff;
  text-align: left;
}

.account-chip {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  border: 1.5px solid var(--edge);
  background: #fff;
  text-decoration: none;
}

.account-chip svg { width: 17px; height: 17px; }

.account-chip:hover { border-color: var(--ink-soft); color: var(--ink); }

.account-chip.signed-in {
  background: var(--defence);
  border-color: var(--defence);
}

.account-initial {
  font-family: "Barlow Condensed", sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
}

.account-row {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13.5px;
  color: var(--ink-soft);
}

.account-row strong {
  color: var(--ink);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.btn-mini {
  padding: 4px 9px;
  font-size: 12.5px;
  border: 1.5px solid var(--edge);
  border-radius: 7px;
  background: #fff;
  font-weight: 600;
  margin-left: auto;
}

.btn-mini:hover { border-color: var(--ink-soft); }

.hint a { color: var(--defence); font-weight: 600; }

.toast {
  position: fixed;
  top: 56px;
  left: 50%;
  translate: -50% 0;
  z-index: 40;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--chrome);
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

/* ---------- pitch ---------- */

.board {
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(47, 122, 69, 0.08), transparent 60%),
    var(--chrome-2);
}

.pitch-wrap {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#pitch {
  max-height: 100%;
  max-width: 100%;
  aspect-ratio: 65 / 88;
  border-radius: 12px;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#pitch text {
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-weight: 700;
  pointer-events: none;
}

.token { cursor: grab; }
.token.dragging { cursor: grabbing; }
/* With a mouse the ball's finger-sized hit circle shadows the player it's
   tucked against (ball paints on top); shrink it to just past the ball. */
@media (hover: hover) and (pointer: fine) {
  .token[data-id="ball"] .token-hit { r: 1.6; }
}
.token:focus { outline: none; }
.token:focus-visible .token-ring { stroke: #fff; stroke-width: 0.55; }
.token:focus-visible ellipse { stroke: #fff; stroke-width: 0.34; }

.line-hit { cursor: default; }
#pitch.tool-erase .line-hit { cursor: pointer; }
#pitch.tool-run, #pitch.tool-pass { cursor: crosshair; }
#pitch.tool-text { cursor: text; }

/* board notes (text tool) — font must match .text-entry (weight, no
   letter-spacing) so lines wrap identically in and out of edit mode */
#pitch .note {
  fill: #fff;
  paint-order: stroke;
  stroke: rgba(22, 33, 27, 0.8);
  stroke-width: 0.3;
  stroke-linejoin: round;
}
#pitch.tool-erase .note { pointer-events: auto; cursor: pointer; }
#pitch.tool-text .note { pointer-events: auto; cursor: grab; }

.text-entry {
  position: absolute;
  z-index: 20;
  transform: translate(-50%, -50%);
  /* width/padding/border/font are load-bearing: app.js NOTE_WRAP_PX (183)
     = 208 − 22 − 3, and noteLines() measures with this exact font so the
     note wraps the same once committed. Change them together. */
  width: 208px;
  padding: 6px 11px;
  border: 1.5px solid var(--ball);
  border-radius: 9px;
  background: rgba(22, 33, 27, 0.92);
  color: #fff;
  font: 700 16px/1.3 "Barlow Condensed", "Arial Narrow", sans-serif;
  text-align: center;
  box-shadow: var(--shadow);
  resize: none;
  overflow: hidden;
}
.text-entry::placeholder { color: rgba(255, 255, 255, 0.45); font-weight: 500; }
.text-entry:focus { outline: none; }
.text-entry[hidden] { display: none; }

/* ---------- toolbar ---------- */

.bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 18px;
  padding: 7px 10px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--edge);
  background: var(--chrome);
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bar-split {
  width: 1px;
  height: 26px;
  margin: 0 6px;
  background: var(--edge);
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 52px;
  padding: 5px 8px 4px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.1;
}

.tool svg { width: 21px; height: 21px; }

.tool:hover { background: var(--chrome-2); color: var(--ink); }

.tool.is-active {
  background: var(--ink);
  color: var(--chrome);
}

.tool:disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* edit sub-menu */

.edit-wrap { position: relative; display: flex; }

#editBtn { position: relative; }
#editBtn .ic { display: none; }
#editBtn[data-active=""] .ic-edit,
#editBtn[data-active="run"] .ic-run,
#editBtn[data-active="pass"] .ic-pass,
#editBtn[data-active="text"] .ic-text,
#editBtn[data-active="erase"] .ic-erase { display: block; }

#editBtn .caret {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 8px;
  height: 5px;
  opacity: 0.55;
  transition: rotate 0.15s;
}
#editBtn[aria-expanded="true"] .caret { rotate: 180deg; }

.submenu {
  position: absolute;
  bottom: calc(100% + 11px);
  left: 50%;
  translate: -50% 0;
  z-index: 45;
  display: flex;
  gap: 2px;
  padding: 5px;
  background: var(--chrome);
  border: 1px solid var(--edge);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.submenu[hidden] { display: none; }

.submenu::after {
  content: "";
  position: absolute;
  bottom: -5.5px;
  left: 50%;
  width: 9px;
  height: 9px;
  translate: -50% 0;
  rotate: 45deg;
  background: var(--chrome);
  border-right: 1px solid var(--edge);
  border-bottom: 1px solid var(--edge);
}

.tool-play.playing { background: var(--attack); color: #fff; }
.tool-play .ic-stop { display: none; }
.tool-play.playing .ic-stop { display: block; }
.tool-play.playing .ic-play { display: none; }

/* phase chips */

.chips { display: flex; gap: 4px; }

.chip {
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  border-radius: 9px;
  border: 1.5px solid var(--edge);
  background: #fff;
  color: var(--ink-soft);
  font-family: "Barlow Condensed", sans-serif;
  font-size: 17px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chip[aria-selected="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--chrome);
}

.chip-add { color: var(--ink-soft); background: transparent; border-style: dashed; }
.chip-add svg { width: 15px; height: 15px; }
.chip-add:hover { color: var(--ink); border-color: var(--ink-soft); }

/* ---------- panel ---------- */

.panel-scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(22, 33, 27, 0.35);
}

.panel {
  position: fixed;
  z-index: 51;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(360px, 94vw);
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  border-left: 1px solid var(--edge);
  box-shadow: -18px 0 40px rgba(22, 33, 27, 0.18);
}

.panel[hidden], .panel-scrim[hidden] { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}

.panel-head h2 {
  margin: 0;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 26px;
  font-weight: 700;
}

.panel-x {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
}
.panel-x svg { width: 19px; height: 19px; }
.panel-x:hover { background: var(--chrome-2); color: var(--ink); }

.panel-body {
  overflow-y: auto;
  padding: 0 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-sec h3 {
  margin: 0 0 8px;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-soft);
}

.btn {
  padding: 9px 13px;
  border: 1.5px solid var(--edge);
  border-radius: var(--radius);
  background: #fff;
  font-weight: 600;
  font-size: 14px;
}

.btn:hover { border-color: var(--ink-soft); }

.btn-primary {
  background: var(--attack);
  border-color: var(--attack);
  color: #fff;
}
.btn-primary:hover { background: var(--attack-deep); border-color: var(--attack-deep); }

.panel-sec > .btn { width: 100%; margin-bottom: 8px; }

a.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--ink);
}

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

.hint, .panel-foot {
  margin: 10px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.panel-foot {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--edge);
}

/* ---------- view-only (shared links) ---------- */

.view-note {
  gap: 7px;
  padding: 4px 6px 4px 13px;
  border: 1.5px dashed var(--edge);
  border-radius: 999px;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

.view-note svg { width: 17px; height: 17px; flex-shrink: 0; }
.view-note .btn-mini { margin-left: 3px; }

body:not(.view-only) .view-note { display: none; }

body.view-only .tools,
body.view-only .chip-add,
body.view-only #shareOpenBtn,
body.view-only .top-nav,
body.view-only #accountChip { display: none !important; }

body.view-only .token { cursor: default; }
body.view-only .play-name { pointer-events: none; }

/* ---------- small screens ---------- */

@media (max-width: 560px) {
  .brand-name { font-size: 19px; }
  .top { gap: 9px; }
  .top-nav { gap: 9px; }
  .top-nav a { font-size: 12.5px; }
  .play-name { padding-inline: 6px; }
  .bar { gap: 2px 10px; }
  .tool { min-width: 46px; padding-inline: 5px; }
  .board { padding: 8px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
