/* ============================================================
   BIGFoot VS Yeti — Card Tracker
   WCAG 2.2 Level AA — screen-reader-primary
   ============================================================ */

/* ── Custom Properties ──────────────────────────────────────── */
:root {
  --color-bg:        #f0f2f5;
  --color-surface:   #ffffff;
  --color-border:    #b0b8c4;
  --color-text:      #1a1a1a;   /* 16:1+ on white */
  --color-muted:     #4a4a4a;   /* 9.7:1 on white */
  --color-focus:     #005fcc;

  /* Expedition — blue */
  --exp-bg:          #d6eaf8;
  --exp-border:      #1a5276;
  --exp-accent:      #1a5276;   /* 7:1 on --exp-bg */

  /* Proof — green */
  --proof-bg:        #d5f0e0;
  --proof-border:    #145a32;
  --proof-accent:    #145a32;   /* 8:1 on --proof-bg */

  /* Phenomenon — purple */
  --phen-bg:         #ebe0f5;
  --phen-border:     #4a235a;
  --phen-accent:     #4a235a;   /* 11:1 on --phen-bg */

  --radius:          6px;
  --gap:             1rem;
}

/* ── Reset ───────────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; margin: 0; padding: 0; }
ul { list-style: none; }

/* ── Screen-reader-only utility ─────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Base ────────────────────────────────────────────────────── */
body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
}

/* ── Global focus ────────────────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ── Header ──────────────────────────────────────────────────── */
header {
  background: #1a2a3a;
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: 1400px;
  margin: 0 auto;
}
header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

/* ── Status message ──────────────────────────────────────────── */
.status-message {
  background: #fff8dc;
  border: 2px solid #b8900a;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  margin: var(--gap) var(--gap) 0;
  min-height: 2.75rem;
  font-size: 0.9rem;
  color: #4a3500;   /* 12:1 on #fff8dc */
  display: flex;
  align-items: center;
}
.status-message:empty {
  visibility: hidden;
}

/* ── Three-panel layout ──────────────────────────────────────── */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--gap);
  padding: var(--gap);
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 1050px) {
  .panels { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .panels { grid-template-columns: 1fr; }
}

/* ── Panel sections ──────────────────────────────────────────── */
.panels > section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--gap);
}
.panels > section > h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: var(--gap);
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-border);
}

/* Scrollable select in Card Deck panel */
#card-browser-list {
  display: block;
  width: 100%;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.25rem;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  margin-bottom: 0.6rem;
  cursor: pointer;
  max-height: 60vh;
}
#card-browser-list:focus {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}
#card-browser-list option {
  padding: 0.3rem 0.4rem;
}

/* Scrollable card list in hand and table panels */
#hand-list,
#table-content {
  max-height: 72vh;
  overflow-y: auto;
}

/* ── Filter fieldset (styled as radio tabs) ──────────────────── */
#filter-fieldset {
  border: none;
  padding: 0;
  margin-bottom: var(--gap);
}
#filter-fieldset legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: 0.35rem;
}
.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.filter-options label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
/* Visually hide the radio but keep it accessible */
.filter-options input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.tab-label {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  min-height: 36px;
  line-height: 1.8;
}
.filter-options input[type="radio"]:checked + .tab-label {
  background: #1a2a3a;
  color: #ffffff;
  border-color: #1a2a3a;
}
.filter-options input[type="radio"]:focus-visible + .tab-label {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

/* ── Card component ──────────────────────────────────────────── */
.card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--color-surface);
}
.card--expedition {
  background: var(--exp-bg);
  border-color: var(--exp-border);
}
.card--proof {
  background: var(--proof-bg);
  border-color: var(--proof-border);
}
.card--phenomenon {
  background: var(--phen-bg);
  border-color: var(--phen-border);
}

.card__name {
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0 0 0.2rem;
  line-height: 1.3;
}
.card__type {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.1rem;
}
.card--expedition .card__type { color: var(--exp-accent); }
.card--proof      .card__type { color: var(--proof-accent); }
.card--phenomenon .card__type { color: var(--phen-accent); }

.card__points {
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 0.15rem;
}
.card__ability {
  font-size: 0.82rem;
  color: var(--color-muted);
  margin-top: 0.3rem;
  font-style: italic;
  line-height: 1.4;
}

/* Checkbox label in hand */
.card__select-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.1rem;
}
.card__select-label input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 0.15rem;
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--color-focus);
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.45rem 0.9rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 38px;
  min-width: 38px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  text-align: center;
}

/* Dark navy — header New Round, dialog Confirm */
.btn--primary {
  background: #1a2a3a;
  color: #ffffff;
  border-color: #1a2a3a;
}
.btn--primary:hover { background: #0d1929; border-color: #0d1929; }

/* Light outlined — secondary actions */
.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn--secondary:hover { background: var(--color-bg); }

/* Blue — Add to Hand */
.btn--add {
  background: #1a5276;
  color: #ffffff;
  border-color: #1a5276;
  margin-top: 0.5rem;
  width: 100%;
}
.btn--add:hover { background: #154360; border-color: #154360; }

/* Red — Discard (Phenomenon card & toolbar) */
.btn--discard,
.btn--discard-toolbar {
  background: #922b21;
  color: #ffffff;
  border-color: #922b21;
}
.btn--discard       { margin-top: 0.5rem; }
.btn--discard:hover,
.btn--discard-toolbar:hover { background: #6e1f17; border-color: #6e1f17; }

/* ── Hand toolbar ────────────────────────────────────────────── */
.hand-toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: var(--gap);
}
.kbd-hint {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.85;
}

/* ── Expedition columns ──────────────────────────────────────── */
.expedition-column {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--color-bg);
}
.expedition-column h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--color-border);
}
.expedition-cards {
  padding: 0;
}

/* ── Empty state messages ────────────────────────────────────── */
.empty-message {
  color: var(--color-muted);
  font-style: italic;
  font-size: 0.9rem;
  padding: 0.5rem 0.25rem;
}
li.empty-message {
  list-style: none;
}

/* ── Dialog / Modal ──────────────────────────────────────────── */
dialog {
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 460px;
  width: 92%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  color: var(--color-text);
  background: var(--color-surface);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
dialog h2 {
  font-size: 1.1rem;
  margin-bottom: 0.4rem;
}
dialog > p {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin-bottom: 1rem;
}
dialog fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 1.1rem;
}
dialog fieldset legend {
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0 0.35rem;
}
.assign-label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.4rem;
}
#assign-options {
  display: block;
  width: 100%;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.25rem;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  margin-bottom: 1.1rem;
  cursor: pointer;
}
#assign-options:focus {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}
#assign-options option {
  padding: 0.3rem 0.4rem;
}
.dialog-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ── Hand badge & heading count ─────────────────────────── */
.hand-count {
  font-size: 0.85em;
  font-weight: normal;
  color: #666;
  margin-left: 0.3em;
}

.hand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #c0392b;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 1.4em;
  height: 1.4em;
  border-radius: 999px;
  padding: 0 0.25em;
  margin-left: 0.25rem;
  vertical-align: middle;
  line-height: 1;
}


/* ── Panel navigation (mobile only) ─────────────────────── */
.panel-nav {
  display: none;
}

/* ── Mobile layout (≤640px) ────────────────────────────── */
@media (max-width: 640px) {
  /* Tab bar */
  .panel-nav {
    display: flex;
    background: #1a2a3a;
    border-bottom: 3px solid #0d1929;
    position: sticky;
    top: var(--header-h, 58px);
    z-index: 15;
  }
  .panel-tab {
    flex: 1;
    padding: 0.6rem 0.4rem;
    min-height: 44px;
    background: transparent;
    color: rgba(255, 255, 255, 0.65);
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -3px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition: color 0.12s, border-color 0.12s;
  }
  .panel-tab[aria-selected="true"] {
    color: #ffffff;
    border-bottom-color: #4a9fd4;
  }
  .panel-tab:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: -2px;
  }

  /* Panel visibility */
  .panels {
    display: block;
    padding: 0;
  }
  .panels > section {
    display: none;
    border: none;
    border-radius: 0;
    border-top: 1px solid var(--color-border);
    padding: var(--gap);
  }
  .panels > section.is-active {
    display: block;
  }

  /* Card browser list — keep a sensible scroll height */
  #card-browser-list {
    max-height: 40vh;
  }

  /* Remove max-height cap on hand and table panels */
  #hand-list,
  #table-content {
    max-height: none;
  }

  /* Status message */
  .status-message {
    margin: 0.5rem;
  }

  /* Touch targets (Apple HIG minimum 44px) */
  .btn {
    min-height: 44px;
  }

  /* Full-width hand toolbar buttons */
  .hand-toolbar {
    flex-direction: column;
  }
  .hand-toolbar .btn {
    width: 100%;
  }

  /* Larger tap area for filter radio tabs */
  .tab-label {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Dialog adjustments */
  dialog {
    padding: 1rem;
    width: 96%;
  }
  #assign-options {
    max-height: 35vh;
    overflow-y: auto;
  }
}
