:root {
  --bg: #07110f;
  --surface: #0d1b18;
  --surface-2: #12241f;
  --surface-3: #173028;
  --border: #254239;
  --text: #edf8f3;
  --muted: #8da9a0;
  --accent: #36e89b;
  --accent-2: #13b879;
  --accent-soft: rgba(54, 232, 155, 0.12);
  --danger: #ff6b78;
  --fold: #1c2926;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius: 14px;
}

html[data-theme="light"] {
  --bg: #eef4f1;
  --surface: #ffffff;
  --surface-2: #f5f9f7;
  --surface-3: #e6f0eb;
  --border: #ccdbd4;
  --text: #10221c;
  --muted: #60776f;
  --accent: #087a50;
  --accent-2: #0a9562;
  --accent-soft: rgba(8, 122, 80, 0.1);
  --fold: #e2e9e5;
  --shadow: 0 18px 45px rgba(22, 55, 43, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 65% -10%, rgba(54, 232, 155, 0.08), transparent 32rem),
    var(--bg);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
select,
input,
textarea {
  color: var(--text);
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}

.brand,
.top-actions,
.table-actions,
.section-heading,
.panel-heading,
.pagination,
.check-row {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border));
  border-radius: 12px;
  color: #05130e;
  background: linear-gradient(145deg, #8bffc9, var(--accent));
  box-shadow: 0 0 24px rgba(54, 232, 155, 0.18);
  font-size: 20px;
  font-weight: 900;
}

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

h1 {
  margin-bottom: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  letter-spacing: -0.025em;
}

h3 {
  margin-bottom: 0;
  font-size: 16px;
}

.eyebrow {
  margin-bottom: 2px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.muted {
  color: var(--muted);
}

.top-actions {
  gap: 10px;
}

.status-pill {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
}

.icon-button,
.table-actions button,
.pagination button,
.text-button {
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 18px;
}

.compact-toggle {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 750;
}

.compact-toggle.active {
  border-color: var(--accent-2);
  color: var(--accent);
  background: var(--accent-soft);
}

.app-shell {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.sidebar {
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 72px);
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 82%, var(--bg));
}

.search-section,
.filter-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.search-section label,
.filter-field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.search-box:focus-within {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  background: var(--surface);
  font-size: 11px;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-heading h2 {
  font-size: 13px;
  letter-spacing: 0.02em;
}

.text-button {
  padding: 4px 8px;
  border-radius: 7px;
  color: var(--accent);
  font-size: 11px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.filter-field select {
  width: 100%;
  height: 34px;
  padding: 0 26px 0 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: 0;
  background: var(--surface-2);
  text-overflow: ellipsis;
  font-size: 12px;
}

.filter-field select:focus {
  border-color: var(--accent-2);
}

details {
  margin-top: 10px;
}

details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.advanced-grid {
  margin-top: 10px;
}

.check-row {
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.check-row input {
  accent-color: var(--accent);
}

.results-section {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 14px 10px 10px;
}

.results-section > .section-heading {
  padding: 0 8px;
}

.table-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.table-list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  width: 100%;
  margin-bottom: 4px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  text-align: left;
  background: transparent;
}

.table-list-item:hover {
  background: var(--surface-2);
}

.table-list-item.active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
}

.table-list-item strong,
.table-list-item small {
  display: block;
}

.table-list-item strong {
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.table-list-item small {
  color: var(--muted);
  font-size: 10px;
}

.list-star {
  color: #f3c84b;
}

.pagination {
  justify-content: center;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

.pagination button {
  width: 30px;
  height: 28px;
  border-radius: 7px;
}

.pagination button:disabled {
  cursor: default;
  opacity: 0.35;
}

.workspace {
  position: relative;
  min-width: 0;
  padding: 24px;
}

.loading-overlay {
  position: fixed;
  z-index: 20;
  inset: 72px 0 0 330px;
  display: grid;
  place-content: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(5px);
}

.loading-overlay[hidden] {
  display: none;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 10px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.table-header {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.table-header h2 {
  margin-top: 7px;
  font-size: clamp(20px, 2vw, 28px);
}

.table-header > div:first-child {
  min-width: 0;
}

#table-subtitle {
  margin: 5px 0 0;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.breadcrumb-chip {
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 10px;
}

.table-actions {
  flex-shrink: 0;
  gap: 8px;
}

.table-actions button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 12px;
}

.table-actions button:hover,
.icon-button:hover,
.pagination button:hover:not(:disabled) {
  border-color: var(--accent-2);
}

#favorite-button.active {
  border-color: #c59c25;
  color: #f3c84b;
}

.study-layout {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
}

.range-panel {
  position: sticky;
  top: 96px;
  padding: 18px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-heading.compact {
  margin-bottom: 10px;
}

.stats {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 10px;
}

.matrix-scroll {
  overflow: auto;
  padding: 2px;
}

.range-grid {
  display: grid;
  grid-template-columns: repeat(13, minmax(42px, 1fr));
  gap: 4px;
  min-width: 594px;
}

.range-cell {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  min-width: 0;
  place-items: center;
  padding: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  border-radius: 6px;
  color: #15221e;
  background: var(--fold);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.035);
  font-size: clamp(9px, 0.9vw, 12px);
  font-weight: 850;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.35), 0 0 5px rgba(255, 255, 255, 0.35);
  transition: transform 100ms ease, border-color 100ms ease, filter 100ms ease;
}

.range-cell:hover,
.range-cell.selected {
  z-index: 2;
  border-color: var(--accent);
  filter: saturate(1.1) brightness(1.06);
  transform: scale(1.08);
}

.range-cell.empty {
  color: var(--muted);
  text-shadow: none;
}

.range-cell::after {
  position: absolute;
  right: 3px;
  bottom: 2px;
  color: rgba(0, 0, 0, 0.5);
  content: attr(data-mix);
  font-size: 7px;
  font-weight: 800;
}

.matrix-help {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.details-column {
  display: grid;
  gap: 14px;
}

.details-column .panel {
  padding: 15px;
  box-shadow: none;
}

.hand-details.empty-state,
.empty-state {
  color: var(--muted);
}

.hand-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.hand-title strong {
  font-size: 26px;
}

.action-row {
  margin-bottom: 10px;
}

.action-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 11px;
}

.action-name {
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
}

.action-name span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 50%;
}

.bar-track {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-3);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.legend {
  display: grid;
  gap: 8px;
}

.legend-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.legend-swatch {
  width: 12px;
  height: 28px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 4px;
}

.legend-item strong,
.legend-item small {
  display: block;
}

.legend-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.legend-item small {
  color: var(--muted);
  font-size: 9px;
}

.legend-percentage {
  font-size: 11px;
  font-weight: 800;
}

.linked-ranges {
  display: grid;
  gap: 7px;
}

.range-link {
  width: 100%;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: left;
  background: var(--surface-2);
}

.range-link:hover:not(:disabled) {
  border-color: var(--accent-2);
}

.range-link strong,
.range-link small {
  display: block;
}

.range-link strong {
  margin-bottom: 2px;
  font-size: 11px;
}

.range-link small {
  color: var(--muted);
  font-size: 9px;
}

.range-link:disabled {
  cursor: default;
  opacity: 0.55;
}

.toast {
  position: fixed;
  z-index: 60;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-3);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.quick-switcher {
  display: none;
}

.quick-header,
.quick-group-title,
.quick-step-buttons,
.compact-hand-heading,
.compact-action-row {
  display: flex;
  align-items: center;
}

.quick-header,
.quick-group-title,
.compact-hand-heading,
.compact-action-row {
  justify-content: space-between;
}

.quick-header {
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.quick-step-buttons {
  gap: 5px;
}

.quick-step-buttons button {
  width: 32px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
}

.compact-hand-details {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.compact-hand-heading strong {
  font-size: 22px;
}

.compact-hand-heading span {
  color: var(--muted);
  font-size: 10px;
}

.compact-action-row {
  gap: 6px;
  margin-top: 4px;
  font-size: 9px;
}

.compact-action-name {
  display: flex;
  gap: 5px;
  align-items: center;
  min-width: 0;
}

.compact-action-name span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-group {
  padding-top: 8px;
}

.quick-group-title {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.quick-hint {
  color: color-mix(in srgb, var(--muted) 65%, transparent);
  font-size: 8px;
  letter-spacing: 0;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.quick-chip {
  min-height: 27px;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 9px;
  font-weight: 750;
  line-height: 1.1;
}

.quick-chip:hover {
  border-color: var(--accent-2);
  color: var(--text);
}

.quick-chip.active {
  border-color: var(--accent);
  color: #06140f;
  background: var(--accent);
}

.quick-chip .shortcut-number {
  margin-right: 3px;
  opacity: 0.65;
  font-size: 7px;
}

.stack-chips {
  max-height: 74px;
  overflow-y: auto;
  padding-right: 2px;
}

.quick-recent-group {
  min-height: 0;
}

.quick-recents {
  display: grid;
  gap: 3px;
}

.quick-recent {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px;
  width: 100%;
  padding: 5px 7px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  text-align: left;
  background: var(--surface-2);
  font-size: 8px;
}

.quick-recent span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-recent.active {
  border-color: var(--accent-2);
  color: var(--text);
}

.quick-clear {
  padding: 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  font-size: 8px;
  text-transform: none;
}

.quick-help {
  margin: auto 0 0;
  padding-top: 7px;
  color: var(--muted);
  font-size: 8px;
  text-align: center;
}

body.compact-mode {
  overflow: hidden;
}

body.compact-mode .topbar {
  height: 48px;
  padding: 0 9px;
}

body.compact-mode .brand {
  gap: 7px;
}

body.compact-mode .brand-mark {
  width: 31px;
  height: 31px;
  border-radius: 8px;
  font-size: 15px;
}

body.compact-mode .brand .eyebrow,
body.compact-mode .status-pill {
  display: none;
}

body.compact-mode .brand h1 {
  font-size: 14px;
}

body.compact-mode .compact-toggle,
body.compact-mode .icon-button {
  min-height: 31px;
  height: 31px;
}

body.compact-mode .app-shell {
  display: block;
  min-height: calc(100vh - 48px);
}

body.compact-mode .sidebar {
  display: none;
}

body.compact-mode .workspace {
  height: calc(100vh - 48px);
  min-height: 360px;
  padding: 7px;
  overflow: hidden;
}

body.compact-mode .loading-overlay {
  inset: 48px 0 0;
}

body.compact-mode .table-header {
  align-items: center;
  min-height: 37px;
  margin-bottom: 5px;
}

body.compact-mode .table-header h2 {
  margin-top: 0;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.compact-mode .breadcrumbs,
body.compact-mode #table-subtitle,
body.compact-mode #export-button,
body.compact-mode #print-button {
  display: none;
}

body.compact-mode .table-actions {
  gap: 4px;
}

body.compact-mode .table-actions button {
  min-height: 29px;
  padding: 0 7px;
  font-size: 9px;
}

body.compact-mode .study-layout {
  display: grid;
  grid-template-columns: minmax(330px, 56%) minmax(220px, 44%);
  gap: 6px;
  height: calc(100% - 42px);
}

body.compact-mode .quick-switcher {
  display: flex;
  grid-column: 2;
  grid-row: 1;
  flex-direction: column;
  min-height: 0;
  padding: 8px;
  overflow-y: auto;
  border-radius: 9px;
  box-shadow: none;
}

body.compact-mode .range-panel {
  position: static;
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 7px;
  border-radius: 9px;
  box-shadow: none;
}

body.compact-mode .range-panel .panel-heading {
  min-height: 25px;
  margin-bottom: 4px;
}

body.compact-mode .range-panel .eyebrow,
body.compact-mode .matrix-help {
  display: none;
}

body.compact-mode .range-panel h3 {
  max-width: 220px;
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.compact-mode .stats {
  gap: 3px;
}

body.compact-mode .stat {
  padding: 3px 5px;
  font-size: 7px;
}

body.compact-mode .matrix-scroll {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

body.compact-mode .range-grid {
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 2px;
  width: min(100%, calc(100vh - 128px));
  min-width: 0;
  margin: 0 auto;
}

body.compact-mode .range-cell {
  border-radius: 3px;
  font-size: clamp(7px, 1.25vw, 10px);
}

body.compact-mode .range-cell::after {
  right: 1px;
  bottom: 0;
  font-size: 5px;
}

body.compact-mode .details-column {
  display: none;
}

@media (max-width: 570px) {
  body.compact-mode .study-layout {
    grid-template-columns: minmax(280px, 58%) minmax(190px, 42%);
  }

  body.compact-mode .quick-switcher {
    padding: 6px;
  }

  body.compact-mode .quick-chip {
    min-height: 24px;
    padding: 2px 5px;
    font-size: 8px;
  }
}

@media (max-width: 1180px) {
  .study-layout {
    grid-template-columns: 1fr;
  }

  .range-panel {
    position: static;
  }

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

@media (max-width: 840px) {
  .topbar {
    position: static;
    padding: 0 14px;
  }

  .status-pill {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .results-section {
    max-height: 390px;
  }

  .table-list {
    min-height: 220px;
  }

  .workspace {
    padding: 16px;
  }

  .loading-overlay {
    inset: 0;
  }

  .table-header {
    display: block;
  }

  .table-actions {
    margin-top: 14px;
  }

  .details-column {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .top-actions {
    gap: 4px;
  }

  .workspace {
    padding: 10px;
  }

  .range-panel {
    padding: 12px;
  }

  .table-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .table-actions button {
    padding: 0 8px;
  }
}

@media print {
  :root {
    --bg: #fff;
    --surface: #fff;
    --surface-2: #f7f7f7;
    --border: #bbb;
    --text: #111;
    --muted: #555;
  }

  .topbar,
  .sidebar,
  .table-actions,
  .links-panel,
  .toast {
    display: none !important;
  }

  .app-shell,
  .study-layout {
    display: block;
  }

  .workspace {
    padding: 0;
  }

  .range-panel {
    position: static;
    box-shadow: none;
  }

  .details-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 12px;
  }
}
