:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #627080;
  --line: #d7dde4;
  --playing-card: #fffaf2;
  --playing-card-border: #d7c6b2;
  --accent: #246b54;
  --accent-strong: #174b3b;
  --danger: #a63838;
  --focus: #2b7cff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
}

button:disabled {
  opacity: 0.55;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.app-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

.app-header p {
  margin: 7px 0 0;
  color: var(--muted);
}

.run-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  min-height: 38px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}

.mode-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.mode-button {
  min-height: 38px;
  border: 0;
  padding: 0 16px;
  background: transparent;
  color: var(--ink);
}

.mode-button.selected {
  background: var(--accent);
  color: #fff;
}

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

.left-panel,
.results-panel {
  display: grid;
  gap: 16px;
  align-content: start;
  min-width: 0;
  max-width: 100%;
}

.slots-panel,
.card-bank-panel,
.results-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.section-title h2 {
  margin: 0;
  font-size: 16px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

.quick-entry-panel {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.quick-entry-panel .section-title {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.quick-entry-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-entry-actions .primary-button {
  min-height: 34px;
}

.quick-entry-panel label {
  min-width: 0;
}

.entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.card-entry {
  min-height: 46px;
  width: 100%;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.entry-preview {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: max-content;
}

.mini-card {
  display: grid;
  place-items: center;
  width: 32px;
  height: 34px;
  border: 1px dashed var(--playing-card-border);
  border-radius: 6px;
  background: rgba(240, 230, 216, 0.5);
  color: rgba(107, 102, 95, 0.8);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.card-entry.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(166, 56, 56, 0.12);
}

#entryStatus.entry-error {
  color: var(--danger);
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.slot-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  min-width: 0;
}

.hero-slots {
  grid-template-columns: repeat(4, minmax(74px, 1fr));
}

.board-slots {
  grid-template-columns: repeat(3, minmax(82px, 1fr));
}

.slot,
.card-button {
  min-height: 54px;
  min-width: 0;
  border: 2px solid var(--playing-card-border);
  border-radius: 12px;
  background: var(--playing-card);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
  box-shadow: 0 1px 0 rgba(28, 27, 25, 0.05);
}

.slot {
  display: grid;
  place-items: center;
  border-style: dashed;
  color: rgba(107, 102, 95, 0.8);
  background: rgba(240, 230, 216, 0.5);
}

.slot.filled {
  border-style: solid;
  color: #fff;
}

.slot:focus,
.card-button:focus,
button:focus,
input:focus,
select:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.suit-s {
  background: #1c1b19;
  border-color: #12110f;
  color: #fff;
}

.suit-h {
  background: #b03a2e;
  border-color: #8c2e25;
  color: #fff;
}

.suit-d {
  background: #2e5aac;
  border-color: #244583;
  color: #fff;
}

.suit-c {
  background: #2f7b3e;
  border-color: #255e31;
  color: #fff;
}

.card-bank {
  display: grid;
  grid-template-columns: repeat(13, minmax(38px, 1fr));
  gap: 6px;
}

.card-bank-panel details {
  min-width: 0;
}

.card-bank-panel summary {
  cursor: pointer;
  list-style: none;
}

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

.card-bank-panel summary::after {
  content: "Hide";
  color: var(--accent-strong);
  font-size: 13px;
}

.card-bank-panel details:not([open]) summary {
  margin-bottom: 0;
}

.card-bank-panel details:not([open]) summary::after {
  content: "Show";
}

.card-button {
  min-height: 42px;
  padding: 0;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease;
}

.card-button:not(:disabled):hover {
  box-shadow: 0 4px 12px rgba(28, 27, 25, 0.15);
  transform: translateY(-1px);
}

.card-button.used {
  opacity: 0.2;
  cursor: not-allowed;
}

.card-button.selected {
  border-color: #ffd166;
  box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.45);
}

.button-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.primary-button,
.secondary-button,
.text-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  max-width: 100%;
}

.primary-button {
  border: 1px solid var(--accent-strong);
  background: var(--accent);
  color: #fff;
}

.primary-button[aria-busy="true"] {
  opacity: 1;
  background: var(--accent-strong);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  padding: 0 6px;
}

.text-button:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  margin-left: auto;
  margin-right: auto;
  min-width: 0;
  max-width: 100%;
}

.running-state {
  grid-template-columns: 1fr;
}

.running-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
}

.running-card strong,
.running-card small {
  display: block;
}

.running-card small {
  margin-top: 4px;
  color: var(--muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 4px solid #d7e6df;
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
  min-height: 82px;
  min-width: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.metric strong {
  display: block;
  font-size: 22px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.metric small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  min-width: 0;
}

.hidden {
  display: none !important;
}

.filters label {
  min-width: min(180px, 100%);
  flex: 1 1 180px;
}

.combo-panel {
  margin-bottom: 14px;
}

.combo-panel summary {
  cursor: pointer;
  list-style: none;
}

.combo-panel summary::-webkit-details-marker {
  display: none;
}

.combo-panel summary::after {
  content: "Show";
  color: var(--accent-strong);
  font-size: 13px;
}

.combo-panel[open] summary::after {
  content: "Hide";
}

.combo-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: 360px;
  min-width: 0;
  max-width: 100%;
}

.combo-component {
  display: grid;
  gap: 3px;
}

.combo-holding {
  display: grid;
  gap: 4px;
}

.combo-component span,
.combo-component small,
.combo-holding small {
  color: var(--muted);
}

.risk-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: 470px;
  min-width: 0;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

.combo-table table {
  min-width: 0;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #eef2f5;
  z-index: 1;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 120px;
  color: var(--muted);
}

.history-panel {
  margin-top: 16px;
}

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

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcfd;
  flex-wrap: wrap;
}

.history-item button {
  min-height: 32px;
}

.raw-json {
  margin-top: 16px;
}

.raw-json summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.raw-json summary::marker {
  content: "";
}

.raw-json summary::-webkit-details-marker {
  display: none;
}

.raw-json pre {
  max-height: 360px;
  overflow: auto;
  background: #111820;
  color: #e7edf4;
  padding: 12px;
  border-radius: 8px;
  font-size: 12px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1200px) {
  .app-header,
  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  .results-panel,
  .slots-panel,
  .card-bank-panel {
    width: 100%;
    max-width: calc(100vw - 40px);
    overflow-x: hidden;
  }

  .run-controls {
    justify-content: start;
  }

  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 680px;
  }
}

@media (max-width: 980px) {
  .quick-entry-panel {
    grid-template-columns: 1fr;
  }

  .quick-entry-actions {
    width: 100%;
    justify-content: space-between;
  }

  .entry-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .entry-preview {
    justify-content: start;
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .app-header h1 {
    font-size: 23px;
  }

  .run-controls,
  .run-controls label,
  .mode-toggle,
  .mode-button,
  .button-row,
  .quick-entry-actions,
  .quick-entry-actions .primary-button,
  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .mode-button,
  .primary-button,
  .secondary-button {
    flex: 1 1 0;
  }

  .slot {
    min-height: 46px;
  }

  .card-bank {
    grid-template-columns: repeat(7, minmax(38px, 1fr));
  }

  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    max-width: min(520px, calc(100vw - 48px));
    overflow: hidden;
  }

  .metric {
    min-height: 76px;
    padding: 10px;
  }

  .metric span {
    margin-bottom: 6px;
    font-size: 11px;
    line-height: 1.2;
  }

  .metric strong {
    font-size: 19px;
  }

  .metric small {
    font-size: 11px;
  }

  .combo-table {
    border: 0;
    border-radius: 0;
    max-height: none;
    overflow: visible;
  }

  .combo-table table,
  .combo-table thead,
  .combo-table tbody,
  .combo-table tr,
  .combo-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .combo-table table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .combo-table thead {
    display: none;
  }

  .combo-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(96px, auto);
    align-items: start;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
    margin-bottom: 10px;
    padding: 10px;
  }

  .combo-table td {
    border-bottom: 0;
    padding: 6px 0;
    overflow-wrap: anywhere;
  }

  .combo-table td:first-child {
    padding-top: 0;
    font-size: 15px;
  }

  .combo-table td:nth-child(2)::before {
    display: none;
  }

  .combo-table td:nth-child(2) {
    text-align: right;
  }

  .combo-table td:nth-child(2) .combo-component {
    justify-items: end;
  }

  .combo-holding strong {
    font-size: 17px;
    line-height: 1.2;
  }

  .combo-holding small {
    font-size: 12px;
  }

  .combo-component strong {
    font-size: 17px;
    line-height: 1.2;
  }

  .combo-component small {
    font-size: 12px;
  }
}
