:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #667085;
  --line: #d9dee7;
  --paper: #f5f2eb;
  --surface: #ffffff;
  --green: #216b55;
  --green-soft: #eaf3ef;
  --blue: #315d86;
  --blue-soft: #edf4fa;
  --gold: #93651f;
  --gold-soft: #fff7e6;
  --red: #ac3f45;
  --red-soft: #fff0f1;
  --shadow: 0 16px 42px rgba(35, 40, 47, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  min-height: 42px;
}

.app-shell {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar,
.section-heading,
.history-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

h1 {
  font-size: 2rem;
  line-height: 1.1;
}

h2 {
  font-size: 1.25rem;
}

.topbar p,
.field-help,
.empty-state,
.dialog-heading p {
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.scoreboard {
  margin: 22px 0 16px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.score-card,
.entry-panel,
.history-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.score-card {
  position: relative;
  min-width: 0;
  padding: 16px;
}

.player-marker {
  position: absolute;
  top: 13px;
  right: 13px;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  color: var(--muted);
  background: #f0f2f5;
  font-size: 0.76rem;
  font-weight: 800;
}

.score-name {
  max-width: calc(100% - 34px);
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.score-values {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.score-value {
  display: grid;
  gap: 2px;
}

.score-label,
.eyebrow {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.score-number {
  font-size: 1.7rem;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
  gap: 16px;
}

.entry-panel,
.history-panel {
  padding: 20px;
}

.value-badge,
.count-badge,
.result {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.value-badge {
  color: var(--green);
  background: var(--green-soft);
}

.count-badge {
  color: var(--blue);
  background: var(--blue-soft);
}

fieldset {
  margin: 20px 0 0;
  padding: 0;
  border: 0;
}

legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-weight: 850;
}

legend span {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: white;
  background: var(--ink);
  font-size: 0.75rem;
}

.field-help {
  margin: -3px 0 10px;
  font-size: 0.86rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: #434852;
  font-size: 0.84rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  border: 1px solid #cbd1da;
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink);
  background: white;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(49, 93, 134, 0.2);
  outline-offset: 1px;
  border-color: var(--blue);
}

input:disabled {
  color: #8d929b;
  background: #eef0f2;
}

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

.choice-chip,
.switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fafbfc;
  overflow-wrap: anywhere;
}

.ta-grafo-toggle {
  width: fit-content;
  max-width: 100%;
}

.outcome-control {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 10px;
  border-left: 3px solid var(--green);
  padding: 8px 12px;
  background: var(--green-soft);
}

.outcome-control > span {
  font-size: 0.8rem;
  font-weight: 850;
  text-transform: uppercase;
}

.outcome-control label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  margin: 0;
}

.outcome-control input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--green);
}

.choice-chip input,
.switch-label input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--green);
}

.defender-list {
  display: grid;
  gap: 8px;
}

.defender-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto 92px;
  align-items: end;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #fafbfc;
}

.defender-identity {
  align-self: center;
  display: grid;
  gap: 2px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.obligation {
  color: var(--muted);
  font-size: 0.78rem;
}

.tricks-layout {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(170px, 1fr);
  gap: 10px;
}

.trick-counter {
  display: grid;
  align-content: center;
  gap: 1px;
  border-radius: 7px;
  padding: 8px 12px;
}

.trick-counter.warning {
  color: var(--gold);
  background: var(--gold-soft);
}

.trick-counter.complete {
  color: var(--green);
  background: var(--green-soft);
}

.trick-counter span {
  font-size: 0.78rem;
}

.button {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 800;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  color: white;
  background: var(--green);
}

.secondary {
  color: var(--blue);
  border-color: #cadce9;
  background: var(--blue-soft);
}

.danger {
  color: var(--red);
  border-color: #ecc7ca;
  background: var(--red-soft);
}

.full-width {
  width: 100%;
  margin-top: 20px;
}

.notice {
  margin: 0 0 16px;
  border: 1px solid;
  border-radius: 7px;
  padding: 11px 13px;
  font-weight: 700;
}

.notice.success {
  color: var(--green);
  border-color: #b9d8cb;
  background: var(--green-soft);
}

.notice.warning {
  color: var(--gold);
  border-color: #ecd9ad;
  background: var(--gold-soft);
}

.notice.error {
  color: var(--red);
  border-color: #ecc7ca;
  background: var(--red-soft);
}

.hidden {
  display: none;
}

.history-list {
  display: grid;
  gap: 9px;
  max-height: 670px;
  margin: 18px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #fafbfc;
}

.result {
  color: var(--blue);
  background: var(--blue-soft);
  text-transform: capitalize;
}

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

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

.result-declined {
  color: var(--gold);
  background: var(--gold-soft);
}

.history-title {
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.history-notes {
  margin: 7px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

dialog {
  width: min(430px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(27, 31, 36, 0.48);
}

dialog form {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.dialog-heading {
  display: grid;
  gap: 4px;
}

.dialog-actions {
  margin-top: 6px;
}

.dialog-actions .button {
  flex: 1;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.busy {
  cursor: progress;
}

@media (max-width: 840px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .history-list {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1160px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .score-grid,
  .choice-row,
  .form-grid,
  .tricks-layout {
    grid-template-columns: 1fr;
  }

  .defender-row {
    grid-template-columns: 1fr 1fr;
  }

  .defender-identity {
    grid-column: 1 / -1;
  }

  .entry-panel,
  .history-panel {
    padding: 15px;
  }
}
