:root {
  --bg: #ebe7de;
  --block: #f8f6f1;
  --tile: #e2ddd2;
  --ink: #141414;
  --ink-soft: #6a665e;
  --felt: #1d4d3a;
  --felt-light: #d6e3da;
  --chip: #d4452a;
  --chip-dark: #b5371f;
  --chip-light: #f4d9d1;
  --run: #2b4c8c;
  --run-light: #d9e1f0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page { max-width: 960px; margin: 0 auto; padding: 28px 20px 56px; }
.page-wide { max-width: min(1760px, 98vw); }
.page-narrow { max-width: 400px; min-height: 100vh; display: flex; align-items: center; }

/* Header block */
.hero-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
  padding: 22px 24px;
  background: var(--felt);
  color: #ffffff;
}
.hero h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.hero p { margin: 4px 0 0; color: var(--felt-light); }
.user-bar { display: flex; align-items: center; gap: 4px; }
.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
}
.hero-row .button-secondary { background: #ffffff; color: var(--felt); }
.hero-row .button-secondary:hover:not(:disabled) { background: var(--felt-light); color: var(--felt); }

/* Blocks */
.card {
  background: var(--block);
  padding: 24px;
  margin-bottom: 4px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

/* Forms */
.label { display: block; margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--ink); }

input[type="file"],
input[type="password"],
input[type="text"] {
  width: 100%;
  border: 0;
  border-radius: 0;
  background: var(--tile);
  color: var(--ink);
  font: inherit;
  padding: 11px 12px;
}
input[type="text"]:focus,
input[type="password"]:focus { outline: none; background: #ffffff; box-shadow: inset 0 -2px 0 var(--felt); }
input:focus-visible, button:focus-visible, .links a:focus-visible { outline: 2px solid var(--felt); outline-offset: 2px; }

input[type="file"]::file-selector-button {
  margin: 0 12px 0 0;
  padding: 7px 12px;
  border: 0;
  background: var(--ink);
  color: #ffffff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--felt); }

.hint { margin-top: 6px; color: var(--ink-soft); font-size: 12px; }

/* Buttons */
button {
  margin-top: 16px;
  border: 0;
  border-radius: 0;
  padding: 11px 20px;
  background: var(--chip);
  color: #ffffff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 100ms ease;
}
button:hover:not(:disabled) { background: var(--chip-dark); }
button:disabled { opacity: 0.45; cursor: default; }

.form-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 16px; }
.form-actions button { margin-top: 0; }

.button-secondary { margin-top: 0; background: var(--tile); color: var(--ink); }
.button-secondary:hover:not(:disabled) { background: #d5cfc2; }

.button-danger { margin-top: 0; background: var(--tile); color: var(--chip); }
.button-danger:hover:not(:disabled) { background: var(--chip-light); color: var(--chip-dark); }

.mistakes-cta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 14px; }
.button-export { margin-top: 0; background: var(--felt); }
.button-export:hover:not(:disabled) { background: #153a2b; }
.export-status { flex: 1 1 320px; min-height: 18px; color: var(--ink-soft); font-size: 13px; }

/* Status */
.status { margin-top: 16px; padding: 10px 14px; background: var(--tile); color: var(--ink-soft); font-size: 13px; font-weight: 500; }
.status.running { background: var(--run-light); color: var(--run); }
.status.ok { background: var(--felt-light); color: var(--felt); }
.status.error { background: var(--chip-light); color: var(--chip-dark); }

/* Login */
.form-stack { display: grid; gap: 16px; }
.page-narrow .card { width: 100%; padding: 0; background: transparent; }
.login-title {
  margin: 0;
  padding: 22px 24px;
  background: var(--felt);
  color: #ffffff;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.login-title::before { content: "\2660\00a0"; color: var(--chip-light); }
.login-subtitle { margin: 4px 0 0; padding: 14px 24px 0; background: var(--block); color: var(--ink-soft); }
.page-narrow .form-stack { padding: 18px 24px 24px; background: var(--block); }
.page-narrow .form-stack button { width: 100%; margin-top: 4px; }
.page-narrow .status { margin-top: 4px; }

/* Metrics */
.run-meta { margin-top: 8px; color: var(--ink-soft); font-size: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; min-height: 18px; }
#result-content { color: var(--ink-soft); }
.result-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 4px; }
.metric { background: var(--tile); padding: 14px 16px; }
.metric-label { color: var(--ink-soft); font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.metric-value { color: var(--ink); font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.metric-negative { color: var(--chip); }

.links { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.links a { color: var(--felt); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 10px 12px; text-align: left; white-space: nowrap; border: 0; }
.table th { background: var(--ink); color: #ffffff; font-size: 12px; font-weight: 700; }
.table td { color: var(--ink); }
.table tbody tr:nth-child(even) { background: #efebe3; }
.table tbody tr:hover { background: var(--felt-light); }
.table-errors th, .table-errors td { white-space: normal; overflow-wrap: normal; word-break: normal; }
.filters-empty { color: var(--ink-soft) !important; text-align: center !important; font-style: italic; }

.th-sort-btn {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #ffffff;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
}
.th-sort-btn:hover:not(:disabled) { background: transparent; color: var(--chip-light); }
.th-sort-btn.active { color: #ffffff; text-decoration: underline; text-underline-offset: 4px; }
.sort-icon { display: inline-flex; min-width: 12px; font-size: 11px; font-weight: 700; }

.mistakes-table th, .mistakes-table td { vertical-align: top; }
.cards-inline { display: flex; flex-wrap: nowrap; gap: 3px; min-width: max-content; }

.action-pill {
  display: inline-block;
  min-width: 52px;
  text-align: center;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: lowercase;
  background: var(--tile);
  color: var(--ink);
}
.action-hero { background: var(--chip); color: #ffffff; }
.action-solver { background: var(--felt); color: #ffffff; }

.ev-loss-cell { color: var(--chip) !important; font-weight: 700; }

.row-remove-btn {
  margin: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}
.row-remove-btn:hover:not(:disabled) { background: var(--chip); color: #ffffff; }

.mistake-meta-cell { min-width: 240px; white-space: normal !important; color: var(--ink-soft) !important; }
.mistake-meta-cell .meta-line { font-size: 11px; line-height: 1.3; margin: 0 0 2px; }
.cards-empty { color: var(--ink-soft); font-size: 12px; }

/* Playing cards */
.card-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 46px;
  background: #ffffff;
  font-weight: 700;
  opacity: 0;
  transform: translateY(6px);
  animation: card-deal-in 240ms ease-out forwards;
  animation-delay: var(--deal-delay, 0ms);
}
.card-chip-mini { width: 24px; height: 32px; }
.card-chip-mini .card-rank { font-size: 14px; }
.card-chip-invalid { color: var(--ink-soft); font-weight: 500; width: auto; min-width: 34px; padding: 0 7px; }
.card-rank { font-size: 19px; line-height: 1; }
.card-chip.suit-h .card-rank { color: #c8341f; }
.card-chip.suit-s .card-rank { color: var(--ink); }
.card-chip.suit-c .card-rank { color: #1d6b45; }
.card-chip.suit-d .card-rank { color: #2453a6; }

@keyframes card-deal-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
