:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --ink-muted: #555;
  --border: #d8d4cc;

  /* Family gold (#ffcc00) used for primary actions, focus rings, header
     underline, active nav state. Dark text on gold for contrast. */
  --accent: #ffcc00;
  --accent-deep: #d4a900;
  --accent-ink: #1a1a1a;
  --accent-soft: #fff7d6;

  --green: #2a8f3a;
  --yellow: #c08a00;
  --red: #c0392b;
  --radius: 6px;
  --pad: 1rem;

  /* Family typography: Oswald for display/headings/buttons, Roboto for body. */
  --font-display: 'Oswald', sans-serif;
  --font-body: 'Roboto', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

/* ─── App header (felt strip — only place felt appears) ─── */

header.app-header {
  position: relative;
  background-color: #5e1a1a;
  background-image: url('../../images/red-felt.jpg');
  background-size: cover;
  background-position: center;
  border-bottom: 3px solid var(--accent);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
header.app-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.25);
  pointer-events: none;
}
header.app-header > * { position: relative; z-index: 1; }

header.app-header .site-logo {
  display: inline-flex;
  align-items: center;
}
header.app-header .site-logo img {
  height: 60px;
  width: auto;
  display: block;
}

nav.app-nav {
  margin-left: auto;
}
nav.app-nav a {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  margin-right: 1.25rem;
}
nav.app-nav a:hover { color: #fff; }
nav.app-nav a.active {
  color: #fff;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 2px;
}

main.app-main {
  max-width: 70rem;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ─── Backup banner ─── */

.backup-banner {
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent);
  color: #6e5800;
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
}
.backup-banner[hidden] { display: none; }
.backup-banner .banner-message { flex: 1; }
.backup-banner .banner-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.backup-banner .banner-dismiss {
  background: transparent;
  border-color: transparent;
  color: #6e5800;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.2rem 0.5rem;
}
.backup-banner .banner-dismiss:hover { background: rgba(0,0,0,0.05); }

.placeholder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--ink-muted);
}
.placeholder code { font-family: var(--font-mono); font-size: 0.85rem; }

/* ─── Buttons (Oswald, all-caps) ─── */

.btn {
  display: inline-block;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: #f0ede5; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.btn-small { padding: 0.3rem 0.65rem; font-size: 0.75rem; letter-spacing: 0.8px; }

.btn-danger { color: var(--red); }
.btn-danger:hover { background: #fbeae7; }

.btn-icon {
  padding: 0;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 1rem;
  line-height: 1;
  border-radius: 50%;
  letter-spacing: 0;
  font-family: var(--font-body);
}

/* ─── Screen page titles ─── */

.inventory .screen-header h2,
.planner .screen-header h2,
.settings .screen-header h2,
.set-detail .screen-header h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin: 0 0 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

/* ─── Inventory screen ─── */

.inventory .screen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  border-bottom: 0;
}
.inventory .screen-header h2 {
  border-bottom: 0;
  padding-bottom: 0;
  margin: 0;
}
.inventory .screen-header + * { margin-top: 0; }

.inventory .empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  color: var(--ink-muted);
}

.inventory .totals {
  margin-top: 1rem;
  text-align: right;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

/* ─── Set cards ─── */

.set-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}

.set-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.set-card-header h3 {
  margin: 0 0 0.1rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.set-card-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.set-card-meta {
  margin: 0.1rem 0 0.5rem;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.set-card-denoms {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink);
  line-height: 1.6;
  word-break: break-word;
}

/* ─── Edit form ─── */

.set-form {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.set-form h3 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.set-form h4 {
  margin: 1rem 0 0.5rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.form-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.75rem;
  border: 0;
  padding: 0;
}
.form-row legend {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 0;
  margin-right: 0.6rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}
.field span {
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
}
.field input, .field textarea {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: #fff;
}
.field input:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.field-grow { flex: 1; }

.radio, .checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  margin-right: 1rem;
  cursor: pointer;
}
.radio input, .checkbox input { margin: 0; }
label.checkbox { margin: 0.5rem 0; }

/* ─── Denom table ─── */

.denom-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}
.denom-table th {
  text-align: left;
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--ink-muted);
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--border);
}
.denom-table td {
  padding: 0.25rem 0.4rem;
  vertical-align: middle;
}
.denom-table input[type="text"] {
  width: 100%;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.85rem;
}
.denom-table input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.denom-table .cell-center { text-align: center; }

.denom-table th:nth-child(1), .denom-table td:nth-child(1) { width: 32%; }
.denom-table th:nth-child(2), .denom-table td:nth-child(2) { width: 30%; }
.denom-table th:nth-child(3), .denom-table td:nth-child(3) { width: 28%; }
.denom-table th:nth-child(4), .denom-table td:nth-child(4) { width: 10%; }

.form-actions {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.6rem;
}

@media (max-width: 640px) {
  .form-row { flex-direction: column; gap: 0.5rem; }
  .set-card-header { flex-direction: column; }
  .set-card-actions { align-self: flex-end; }
  .denom-table { font-size: 0.78rem; }
}

/* ─── Planner screen ─── */

.planner-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.85rem;
}
.planner-form .field { flex: 0 1 auto; min-width: 7rem; }
.planner-form .field-narrow { min-width: 5rem; max-width: 7rem; }
.planner-form select, .planner-form input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: #fff;
}
.planner-form select:focus, .planner-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.planner-form .planner-ncv {
  margin: 0 0 0.25rem;
  align-self: flex-end;
  padding-bottom: 0.5rem;
}
.planner-form .planner-ncv.disabled { opacity: 0.5; cursor: not-allowed; }
.planner-form .btn { margin-bottom: 0; align-self: flex-end; }

.stale-notice {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
  color: #6e5800;
}

.results-summary {
  margin-bottom: 0.75rem;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
  gap: 0.75rem;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  border-left: 4px solid var(--border);
}
.result-card.status-green { border-left-color: var(--green); }
.result-card.status-yellow { border-left-color: var(--yellow); }
.result-card.status-red { border-left-color: var(--red); }
.result-card.status-ineligible, .result-card.status-ncv-pending { opacity: 0.85; }

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.result-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.badge {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--border);
  color: var(--ink);
}
.badge-green { background: var(--green); color: #fff; }
.badge-yellow { background: var(--yellow); color: #fff; }
.badge-red { background: var(--red); color: #fff; }
.badge-ineligible { background: #aaa; color: #fff; }

.kind-tag {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  background: #b08bd6;
  color: #fff;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 0.3rem;
  text-transform: uppercase;
}

.role-tag {
  font-family: var(--font-display);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
  background: #e9e5db;
  color: var(--ink-muted);
}
.role-tag.role-workhorse { background: #dde8d9; color: #3a6a3a; }
.role-tag.role-secondary { background: #e3dcef; color: #5a4480; }

.ncv-note {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-style: italic;
}

.result-reason {
  margin: 0.25rem 0 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.result-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.5rem;
}
.result-body h4 {
  margin: 0 0 0.3rem;
  font-family: var(--font-display);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-muted);
  font-weight: 500;
}
.result-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-family: var(--font-mono);
}
.result-body th, .result-body td {
  text-align: right;
  padding: 0.15rem 0.4rem;
  border-bottom: 1px solid #f0eee8;
}
.result-body th:first-child, .result-body td:first-child { text-align: left; }
.result-body thead th {
  font-weight: 500;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
}
.result-body tfoot td {
  font-weight: 600;
  border-top: 1px solid var(--border);
  border-bottom: 0;
}
.cushion-yellow { color: var(--yellow); font-weight: 600; }
.cushion-red { color: var(--red); font-weight: 600; }

@media (max-width: 700px) {
  .result-body { grid-template-columns: 1fr; }
}

/* ─── Settings screen ─── */

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}
.settings-section h3 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.75rem 0;
  border-top: 1px solid #f0eee8;
}
.setting-row:first-of-type { border-top: 0; padding-top: 0; }

.setting-label { flex: 1; }
.setting-label strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.15rem;
  font-weight: 600;
}
.setting-label p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.settings-section .btn { flex-shrink: 0; }
.settings-section label.btn { cursor: pointer; display: inline-block; }

.setting-meta {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--ink-muted);
}
.setting-meta p { margin: 0.2rem 0; }
.setting-meta.meta-warn p:last-child {
  color: var(--yellow);
  font-weight: 500;
}

@media (max-width: 600px) {
  .setting-row { flex-direction: column; align-items: stretch; }
  .setting-row .btn, .setting-row label.btn { align-self: flex-start; }
}

/* ─── Set Detail screen ─── */

.set-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted transparent;
}
.set-link:hover { border-bottom-color: var(--accent-deep); color: var(--accent-deep); }

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.back-link:hover { color: var(--accent-deep); }

.set-detail .screen-header { margin-bottom: 1rem; }
.set-detail .screen-header .meta {
  margin: 0.25rem 0 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.detail-plan-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.detail-plan-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.detail-plan-header .meta {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.status-line {
  font-size: 0.9rem;
  margin: 0.5rem 0 0.75rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  background: #f0eee8;
  border-left: 4px solid var(--border);
}
.status-line.status-green { background: #e7f6ea; border-left-color: var(--green); color: #1a5e2a; }
.status-line.status-yellow { background: #fbf2dc; border-left-color: var(--yellow); color: #6a4f00; }
.status-line.status-red { background: #fbeae7; border-left-color: var(--red); color: #8a1f12; }

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-family: var(--font-mono);
}
.breakdown-table th {
  text-align: right;
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink-muted);
  font-weight: 500;
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 1.2px;
}
.breakdown-table th:first-child { text-align: left; }
.breakdown-table td {
  padding: 0.3rem 0.6rem;
  text-align: right;
  border-bottom: 1px solid #f0eee8;
}
.breakdown-table td:first-child { text-align: left; }
.breakdown-table tfoot td {
  font-weight: 600;
  border-top: 1px solid var(--border);
  border-bottom: 0;
}

.notes-block {
  margin: 1rem 0 0;
  padding: 0.5rem 0.75rem;
  background: #fafaf5;
  border-left: 3px solid var(--border);
  font-size: 0.85rem;
  color: var(--ink-muted);
}

/* Zebra striping for the detail-view data tables. Pale sage-green stripe
   pulls from the felt-header palette without competing with status colors. */
.set-detail .breakdown-table tbody tr:nth-child(even),
.set-detail .result-body tbody tr:nth-child(even) {
  background: #e2ecda;
}
