:root {
  color-scheme: dark;
  --canvas: #07090b;
  --surface: #101418;
  --surface-soft: #151a1f;
  --ink: #edf1f3;
  --muted: #929da6;
  --line: #2a3239;
  --line-strong: #46515a;
  --teal: #43c6cb;
  --teal-soft: #102d30;
  --cyan: #46d1d7;
  --red: #ff6672;
  --red-soft: #36191e;
  --green: #53d887;
  --green-soft: #153022;
  --amber: #ff9c37;
  --charcoal: #090c0f;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button,
summary,
.photo-picker,
.outcome-options label {
  cursor: pointer;
}

button:focus-visible,
summary:focus-visible,
input:focus-visible,
textarea:focus-visible,
.photo-picker:focus-within {
  outline: 3px solid rgba(40, 168, 178, 0.24);
  outline-offset: 2px;
}

.shell {
  width: min(1220px, calc(100% - 20px));
  margin: 0 auto;
  padding-bottom: 40px;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 11, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border: 1px solid var(--amber);
  border-radius: 6px;
  background: #15191d;
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 900;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  margin-bottom: 0;
  letter-spacing: 0;
  line-height: 1.1;
}

h1 {
  font-size: 1.08rem;
}

h2 {
  font-size: 1.18rem;
}

h3 {
  margin-top: 20px;
  font-size: 0.88rem;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sync-state {
  display: none;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.sync-state i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

.primary-button,
.save-button,
.ghost-button,
.photo-button {
  min-height: 40px;
  border: 1px solid var(--charcoal);
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button,
.save-button {
  border-color: var(--amber);
  background: var(--amber);
  color: #17110b;
}

.primary-button:hover,
.save-button:not(:disabled):hover {
  background: #ffad59;
}

.save-button:disabled {
  border-color: var(--line);
  background: #1a1f24;
  color: #68737c;
  cursor: not-allowed;
}

.matchup-band {
  overflow: hidden;
  padding: 18px;
  border-radius: 4px;
  border: 1px solid #343c43;
  background: #0b0e11;
  color: #ffffff;
}

.run-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 0.67rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.matchup-display {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 22px 0 18px;
}

.matchup-team {
  display: grid;
  min-width: 0;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.matchup-team > div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.matchup-team span,
.matchup-team small,
.matchup-center small,
.run-facts span {
  color: #aeb9c2;
  font-size: 0.67rem;
}

.matchup-team strong {
  font-size: 0.82rem;
  line-height: 1.2;
}

.matchup-team small {
  display: none;
}

.matchup-logo {
  width: 66px;
  height: 66px;
  object-fit: contain;
  border-radius: 50%;
  background: #f4f6f7;
  padding: 6px;
}

.matchup-center {
  display: grid;
  justify-items: center;
  gap: 3px;
}

.matchup-center > span {
  color: var(--cyan);
  font-size: 0.68rem;
  font-weight: 900;
}

.matchup-center strong {
  font-size: 1.45rem;
}

.run-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid #323b44;
}

.run-facts > div {
  display: grid;
  gap: 2px;
  padding: 12px 8px 0;
  border-left: 1px solid #323b44;
  text-align: center;
}

.run-facts > div:first-child {
  border-left: 0;
}

.run-facts strong {
  overflow: hidden;
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.surface {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: none;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-meta {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.matrix-header {
  display: none;
}

.ladder-matrix {
  display: grid;
  gap: 7px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.matrix-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 22px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.matrix-row.complete {
  border-left: 3px solid var(--green);
}

.matrix-row.current {
  border-color: var(--amber);
  border-left: 5px solid var(--amber);
  background: #382514;
  box-shadow: inset 0 0 0 1px rgba(255, 156, 55, 0.22);
}

.matrix-row.locked {
  opacity: 0.62;
}

.matrix-stage {
  grid-column: 1;
  grid-row: 1 / span 3;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.66rem;
  font-weight: 900;
}

.matrix-team {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.matrix-team:first-of-type {
  grid-column: 2;
  grid-row: 1;
}

.matrix-team.opponent {
  grid-column: 4;
  grid-row: 1;
}

.matrix-team strong {
  overflow: hidden;
  font-size: 0.74rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matrix-logo {
  width: 29px;
  height: 29px;
  flex: 0 0 29px;
  object-fit: contain;
  border-radius: 50%;
  background: #f4f6f7;
  padding: 3px;
}

.matrix-ratings {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(34px, 1.4fr);
  gap: 2px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.66rem;
}

.matrix-ratings:nth-of-type(2) {
  grid-column: 2;
  grid-row: 2;
}

.matrix-ratings:nth-of-type(4) {
  grid-column: 4;
  grid-row: 2;
}

.matrix-ratings span::before {
  content: attr(data-label) " ";
  color: var(--line-strong);
  font-size: 0.5rem;
}

.matrix-versus {
  grid-column: 3;
  grid-row: 1 / span 2;
  color: var(--muted);
  font-size: 0.57rem;
  font-weight: 900;
  text-align: center;
}

.matrix-status {
  display: flex;
  grid-column: 2 / 5;
  grid-row: 3;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
}

.matrix-status strong {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.matrix-row.complete .matrix-status strong {
  color: var(--green);
}

.matrix-row.current .matrix-status strong {
  color: var(--amber);
}

.matrix-status small {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.61rem;
}

.ladder-more {
  margin-top: 8px;
}

.ladder-more summary {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
}

.ladder-more[open] summary {
  margin-bottom: 7px;
}

.workspace {
  display: grid;
  min-width: 0;
  gap: 0;
}

.workspace > * {
  min-width: 0;
}

.entry-panel {
  scroll-margin-top: 82px;
}

.entry-form {
  display: grid;
  gap: 14px;
}

.entry-matchup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.entry-matchup > div {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.76rem;
  font-weight: 800;
}

.entry-matchup > div:last-child {
  flex-direction: row-reverse;
}

.entry-matchup > strong {
  color: var(--muted);
  font-size: 0.68rem;
}

.entry-team-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  border-radius: 50%;
  background: #f4f6f7;
  padding: 3px;
}

.capture-grid {
  display: grid;
  gap: 12px;
}

.photo-picker {
  position: relative;
  display: grid;
  min-height: 112px;
  place-content: center;
  gap: 3px;
  border: 1px dashed var(--teal);
  border-radius: 6px;
  background: var(--teal-soft);
  color: var(--ink);
  text-align: center;
}

.photo-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.photo-picker-action {
  color: var(--teal);
  font-size: 0.92rem;
  font-weight: 900;
}

.photo-picker small {
  color: var(--muted);
  font-size: 0.69rem;
}

.photo-preview {
  display: none;
  min-height: 112px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.photo-preview.has-photo {
  display: grid;
  place-items: center;
  margin-top: 8px;
}

.photo-preview img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
}

.result-controls {
  display: grid;
  align-content: start;
  gap: 9px;
}

.control-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.outcome-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.outcome-options label {
  position: relative;
}

.outcome-options input {
  position: absolute;
  opacity: 0;
}

.outcome-options span {
  display: grid;
  min-height: 48px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
}

.outcome-options input:checked + span {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--teal);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.outcome-options input[value="win"]:checked + span {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}

.outcome-options input[value="loss"]:checked + span {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red);
  box-shadow: inset 0 0 0 1px var(--red);
}

.result-controls [role="status"] {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.save-button {
  width: 100%;
}

.optional-details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.optional-details summary {
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
}

.optional-details summary span {
  color: var(--muted);
  font-weight: 700;
}

.optional-content {
  display: grid;
  gap: 14px;
  padding-top: 14px;
}

.score-row,
.stat-columns,
.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

legend {
  padding: 0 5px;
  font-size: 0.78rem;
  font-weight: 800;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 9px;
}

textarea {
  resize: vertical;
}

.trend-list {
  border-top: 1px solid var(--line);
}

.trend-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 62px;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border-bottom: 1px solid var(--line);
  font-size: 0.7rem;
}

.trend-row > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trend-row strong {
  font-size: 0.66rem;
}

.trend-row small {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: right;
}

.trend-row.improving strong {
  color: var(--green);
}

.trend-row.worsening strong {
  color: var(--red);
}

.trend-row.flat strong {
  color: var(--amber);
}

.trend-row.insufficient strong {
  color: var(--muted);
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 9px 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.61rem;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  font-size: 0.71rem;
}

.history-panel th:nth-child(n + 5):not(:last-child),
.history-panel td:nth-child(n + 5):not(:last-child) {
  display: none;
}

.history-panel {
  min-width: 0;
  overflow: hidden;
}

.history-matchup {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.history-matchup b {
  color: var(--muted);
  font-weight: 700;
}

.history-logo {
  width: 23px;
  height: 23px;
  object-fit: contain;
  border-radius: 50%;
  background: #f4f6f7;
  padding: 2px;
}

.ghost-button,
.photo-button {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.photo-button {
  min-height: 30px;
  padding: 0 9px;
  color: var(--teal);
  font-size: 0.68rem;
}

.result {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 4px;
  padding: 0 7px;
  font-size: 0.62rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result.win {
  background: var(--green-soft);
  color: var(--green);
}

.result.loss {
  background: var(--red-soft);
  color: var(--red);
}

.evidence-dialog {
  width: min(920px, calc(100% - 20px));
  max-height: calc(100vh - 20px);
  padding: 42px 10px 10px;
  border: 0;
  border-radius: 8px;
  background: #0c1014;
  color: #ffffff;
}

.evidence-dialog::backdrop {
  background: rgba(5, 8, 10, 0.84);
}

.evidence-dialog img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 84px);
  object-fit: contain;
}

.dialog-close {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: #ffffff;
  font-size: 1.7rem;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.logo-placeholder {
  display: block;
  border: 1px solid var(--line);
  border-radius: 50%;
}

@media (min-width: 700px) {
  .shell {
    width: min(1220px, calc(100% - 32px));
    padding-bottom: 56px;
  }

  .topbar {
    position: static;
    min-height: 78px;
    backdrop-filter: none;
  }

  .sync-state {
    display: flex;
  }

  .matchup-band {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr) 180px;
    align-items: center;
    gap: 20px;
    padding: 20px 24px;
  }

  .run-label {
    display: block;
  }

  .matchup-display {
    padding: 0;
  }

  .matchup-team {
    grid-template-columns: 74px minmax(0, 1fr);
    justify-items: start;
    text-align: left;
  }

  .matchup-team:last-child {
    grid-template-columns: minmax(0, 1fr) 74px;
    text-align: right;
  }

  .matchup-team:last-child > img {
    grid-column: 2;
    grid-row: 1;
  }

  .matchup-team:last-child > div {
    grid-column: 1;
    grid-row: 1;
  }

  .matchup-team small {
    display: block;
  }

  .matchup-logo {
    width: 74px;
    height: 74px;
  }

  .run-facts {
    grid-template-columns: 1fr;
    border-top: 0;
    border-left: 1px solid #323b44;
  }

  .run-facts > div {
    grid-template-columns: 58px 1fr;
    padding: 6px 0 6px 14px;
    border-left: 0;
    text-align: left;
  }

  .surface {
    padding: 18px;
  }

  .matrix-header,
  .matrix-row {
    display: grid;
    grid-template-columns: 48px minmax(0, 1.15fr) minmax(118px, 154px) 28px minmax(0, 1.15fr) minmax(118px, 154px) 95px;
    gap: 8px;
  }

  .matrix-header {
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 6px 6px 0 0;
    background: var(--charcoal);
    color: #ffffff;
    font-size: 0.62rem;
    font-weight: 900;
    text-transform: uppercase;
  }

  .matrix-header-rating {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(34px, 1.4fr);
    gap: 2px;
  }

  .matrix-header-rating b {
    font-weight: 900;
  }

  .ladder-matrix {
    gap: 0;
    border: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 6px 6px;
  }

  .matrix-row {
    min-height: 52px;
    padding: 7px 10px;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
  }

  .matrix-row:first-child {
    border-top: 0;
  }

  .matrix-row.current {
    border-top: 1px solid var(--amber);
    border-bottom: 1px solid var(--amber);
    border-left: 5px solid var(--amber);
    padding-left: 6px;
  }

  .matrix-stage,
  .matrix-team:first-of-type,
  .matrix-team.opponent,
  .matrix-ratings:nth-of-type(2),
  .matrix-ratings:nth-of-type(4),
  .matrix-versus,
  .matrix-status {
    grid-row: 1;
  }

  .matrix-stage {
    grid-column: 1;
  }

  .matrix-team:first-of-type {
    grid-column: 2;
  }

  .matrix-ratings:nth-of-type(2) {
    grid-column: 3;
  }

  .matrix-versus {
    grid-column: 4;
  }

  .matrix-team.opponent {
    grid-column: 5;
  }

  .matrix-ratings:nth-of-type(4) {
    grid-column: 6;
  }

  .matrix-status {
    display: grid;
    grid-column: 7;
    justify-content: start;
    padding-top: 0;
    border-top: 0;
  }

  .matrix-logo {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .matrix-team strong {
    font-size: 0.76rem;
  }

  .matrix-ratings span::before {
    display: none;
  }

  .capture-grid,
  .score-row,
  .stat-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .history-panel th:nth-child(n),
  .history-panel td:nth-child(n) {
    display: table-cell;
  }
}

@media (min-width: 1040px) {
  .workspace {
    grid-template-columns: minmax(0, 1.42fr) minmax(320px, 0.78fr);
    gap: 12px;
  }

  .workspace > .surface {
    min-width: 0;
  }

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