:root {
  --bg-a: #080d17;
  --bg-b: #0b1322;
  --panel: #111927;
  --card: rgba(255, 255, 255, 0.055);
  --border: rgba(255, 255, 255, 0.1);
  --ink: #e8eefc;
  --muted: #9baed1;
  --accent: #7aa3ff;
  --danger: #ff6b6b;
  --court-line: #ffffff;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: linear-gradient(180deg, var(--bg-a), var(--bg-b));
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
.file-button {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font-weight: 750;
}

button,
select,
.file-button,
summary,
.token-button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.workspace {
  min-height: 45dvh;
  padding: 10px;
  overflow: auto;
}

.controls-panel {
  border-top: 2px solid rgba(122, 163, 255, 0.6);
  background: var(--panel);
  padding: 10px;
  display: grid;
  gap: 10px;
}

.brand-row,
.section-row,
.action-row,
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-row strong {
  color: var(--accent);
}

.icon-button {
  width: 36px;
  min-height: 36px;
  border-radius: 999px;
}

.title-input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  padding: 12px;
  font-weight: 850;
}

.control-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  padding: 12px;
}

.control-card h2,
.control-card summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.73rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 900;
}

.control-card summary {
  list-style: none;
}

.control-card summary::-webkit-details-marker {
  display: none;
}

.stack,
.token-grid,
.tool-grid,
.mini-actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.token-grid {
  grid-template-columns: repeat(5, minmax(38px, 1fr));
}

.tool-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mini-actions {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.mini-actions button {
  min-height: 34px;
  padding: 0 6px;
  font-size: 0.76rem;
}

.token-button {
  margin: auto;
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  font-weight: 950;
}

.token-button.offense {
  background: #edf5fa;
  color: #151a24;
}

.token-button.defense {
  background: #3a1515;
  border-color: rgba(255, 107, 107, 0.7);
  color: #ffd6d6;
}

.token-button.active,
.tool-button.active {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(122, 163, 255, 0.16);
}

.tool-button {
  display: grid;
  place-items: center;
  gap: 3px;
  min-height: 52px;
  color: var(--muted);
}

.tool-button.active {
  color: var(--accent);
  background: rgba(122, 163, 255, 0.16);
}

.primary-button {
  background: var(--accent);
  color: #0b1322;
}

.field-row span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.field-row input,
.field-row select {
  min-width: 116px;
}

.file-button {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0 12px;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.frames-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  max-width: 1300px;
  margin: 0 auto;
}

.frames-grid.two,
.frames-grid.four {
  grid-template-columns: 1fr;
}

.frame-card {
  border-radius: 10px;
  padding: 4px;
}

.frame-card.active {
  background: rgba(122, 163, 255, 0.14);
}

.frame-top {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.frame-top button {
  min-height: 28px;
  padding: 0 10px;
  color: var(--accent);
  background: rgba(122, 163, 255, 0.16);
}

.court-wrap {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 28px rgba(0, 0, 0, 0.42);
  touch-action: none;
}

.court-wrap.active {
  outline: 3px solid var(--accent);
}

.court-svg {
  display: block;
  width: 100%;
  aspect-ratio: 10 / 7;
  background: #c9984b;
}

.note-input {
  min-height: 46px;
  margin-top: 8px;
  resize: vertical;
  font-weight: 650;
}

.status {
  min-height: 1.2em;
  margin: 0;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 750;
}

.help-dialog {
  max-width: 420px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #111927;
  color: var(--ink);
}

.help-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.help-dialog form {
  display: grid;
  gap: 12px;
}

.help-dialog h2,
.help-dialog p {
  margin: 0;
}

.fullscreening .controls-panel {
  display: none;
}

.fullscreening .workspace {
  min-height: 100dvh;
  padding: 14px;
}

.fullscreening .frames-grid {
  max-width: min(1400px, 100%);
}

@media (min-width: 760px) {
  .frames-grid.two,
  .frames-grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .app-shell {
    flex-direction: row-reverse;
  }

  .workspace {
    flex: 1;
    height: 100dvh;
    padding: 18px;
  }

  .controls-panel {
    width: 310px;
    height: 100dvh;
    overflow: auto;
    border-top: 0;
    border-right: 1px solid var(--border);
  }
}

@media (max-width: 430px) {
  .mini-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tool-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
