.house-scores-page {
  --house-accent-soft: color-mix(in srgb, var(--primary) 9%, var(--bg-secondary));
  --house-accent-softer: color-mix(in srgb, var(--primary) 5%, var(--bg-secondary));
  display: grid;
  gap: 18px;
  min-width: 0;
}

.house-scores-header,
.house-score-entry-panel,
.house-standings-panel,
.house-history-panel {
  min-width: 0;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-secondary);
}

.house-scores-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  overflow: hidden;
  padding: 22px 24px;
  background: var(--house-accent-softer);
}

.house-scores-header::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--primary);
}

.house-scores-intro { min-width: 0; }
.house-scores-header h1,
.house-section-heading h2 {
  margin: 0;
  color: var(--text-primary);
  letter-spacing: -.02em;
}

.house-scores-header h1 { font-size: clamp(24px, 2vw, 30px); }
.house-section-heading h2 { font-size: 18px; }
.house-scores-header p,
.house-section-heading p {
  margin: 6px 0 0;
  color: var(--text-secondary);
  line-height: 1.45;
}
.house-scores-header p { max-width: 62ch; }

.house-week-field,
.house-score-form label {
  display: grid;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 750;
}

.house-week-field {
  flex: 0 0 190px;
  padding: 10px 12px 12px;
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--border-color));
  border-radius: 10px;
  background: var(--bg-secondary);
}

.house-week-field input,
.house-score-form input,
.house-score-form select,
.house-score-form textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
}

.house-week-field input { border: 0; padding: 0; background: transparent; font-weight: 750; }
.house-score-form input:focus,
.house-score-form select:focus { border-color: var(--primary); outline: 3px solid color-mix(in srgb, var(--primary) 20%, transparent); outline-offset: 1px; }

/* HOUSE SCORES DATE PICKER VISIBILITY: isolate native icon treatment to this page. */
.house-week-field input[type="date"] { max-width: 100%; color-scheme: light; }
:root[data-theme="dark"] .house-week-field input[type="date"],
:root[data-theme-name="midnight-blue"] .house-week-field input[type="date"],
:root[data-theme-name="obsidian"] .house-week-field input[type="date"],
:root[data-theme-name="high-contrast"] .house-week-field input[type="date"] { color-scheme: dark; }
.house-week-field input[type="date"]::-webkit-calendar-picker-indicator { width: 24px; height: 24px; margin: 0; cursor: pointer; opacity: 1; filter: none !important; }
.house-week-field input[type="date"]:focus-visible { outline: 3px solid var(--primary); outline-offset: 4px; }

.house-scores-layout {
  display: grid;
  grid-template-columns: minmax(330px, .86fr) minmax(420px, 1.14fr);
  grid-template-areas:
    "entry standings"
    "history standings";
  grid-template-rows: auto 1fr;
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.house-score-entry-panel { grid-area: entry; }
.house-standings-panel { grid-area: standings; }
.house-history-panel { grid-area: history; container-type: inline-size; }

.house-score-entry-panel,
.house-standings-panel,
.house-history-panel { padding: 20px; }

.house-section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.house-score-form { display: grid; gap: 18px; }
.house-score-fields { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(120px, .6fr); gap: 12px; }
.house-score-input-wrap { position: relative; display: block; }
.house-score-input-wrap > input { padding-right: 48px; font-weight: 750; }
.house-score-input-wrap > span {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
}

.house-score-picker { margin: 0; padding: 0; border: 0; }
.house-score-picker legend { margin-bottom: 8px; color: var(--text-secondary); font-size: 12px; font-weight: 750; }
.house-score-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.house-score-option {
  display: grid;
  place-items: center;
  gap: 2px;
  min-width: 0;
  min-height: 58px;
  padding: 7px 4px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease, transform .1s ease;
}
.house-score-option strong { font-size: 20px; line-height: 1; }
.house-score-option span { overflow: hidden; max-width: 100%; color: var(--text-muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.house-score-option:hover,
.house-score-option[aria-pressed="true"] { border-color: var(--primary); background: var(--house-accent-soft); color: var(--primary); }
.house-score-option[aria-pressed="true"] span { color: var(--primary); }
.house-score-option:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.house-score-option:active { transform: scale(.98); }

.house-form-status { min-height: 20px; color: var(--success, #15803d); font-size: 13px; }
.house-form-status.is-error { color: var(--danger, #b91c1c); }
#houseScoreSave { min-height: 48px; font-weight: 750; }

.house-standings { display: grid; gap: 4px; }
.house-standing-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto 68px;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 7px 10px;
  border-radius: 10px;
}
.house-standing-row + .house-standing-row { border-top: 1px solid var(--border-color); border-top-left-radius: 0; border-top-right-radius: 0; }
.house-standing-row.is-leading { background: var(--house-accent-soft); }
.house-standing-rank {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 800;
}
.house-standing-row.is-leading .house-standing-rank { border-color: var(--primary); background: var(--bg-secondary); color: var(--primary); }
.house-standing-name { display: grid; min-width: 0; gap: 3px; }
.house-standing-class { overflow: hidden; color: var(--text-primary); font-weight: 780; text-overflow: ellipsis; white-space: nowrap; }
.house-standing-name small { color: var(--text-muted); font-size: 11px; }
.house-standing-rounds { color: var(--text-muted); font-size: 11px; }
.house-standing-average { text-align: right; color: var(--text-primary); font-size: 20px; white-space: nowrap; }
.house-standing-average small { color: var(--text-muted); font-size: 10px; font-weight: 650; }

.house-history-heading { align-items: center; }
#houseScoresParticipation { display: grid; gap: 3px; }
#houseScoresParticipation strong { color: var(--text-primary); font-size: 14px; }
#houseScoresParticipation small { color: var(--text-muted); font-size: 11px; line-height: 1.4; }
.house-missing-classes { width: fit-content; margin-top: 8px; color: var(--text-secondary); font-size: 13px; }
.house-missing-classes summary { min-height: 44px; padding: 10px 0; cursor: pointer; font-weight: 750; }
.house-missing-classes ul { display: grid; gap: 5px; margin: 0 0 4px 18px; padding: 0; }
.house-score-history { min-width: 0; }
.house-history-table { min-width: 0; }
.house-history-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.4fr) 80px 64px minmax(130px, 1fr) 82px;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 13px;
}
.house-history-row:last-child { border-bottom: 0; }
.house-history-row span { min-width: 0; overflow-wrap: anywhere; }
.house-history-row small { display: block; margin-top: 2px; color: var(--text-muted); }
.house-history-header { min-height: 38px; color: var(--text-muted); font-size: 10px; font-weight: 780; letter-spacing: .05em; text-transform: uppercase; }
.house-score-value { display: inline-grid; place-items: center; min-width: 38px; height: 32px; padding: 0 5px; border: 1px solid var(--primary); border-radius: 8px; background: var(--house-accent-softer); color: var(--primary); font-size: 15px; }
.house-delete-score { min-height: 40px; }

/* History can be narrow in the left desktop column as well as on phones. */
@container (max-width: 680px) {
  .house-history-heading { align-items: stretch; flex-wrap: wrap; }
  .house-history-header { display: none; }
  .house-history-table { display: grid; gap: 10px; }
  .house-history-row:not(.house-history-header) {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 16px;
    padding: 13px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-primary);
  }
  .house-history-row:not(.house-history-header) span { display: grid; gap: 3px; }
  .house-history-row:not(.house-history-header) span::before { content: attr(data-label); color: var(--text-muted); font-size: 9px; font-weight: 780; letter-spacing: .05em; text-transform: uppercase; }
  .house-history-row:not(.house-history-header) span:first-child { grid-column: 1 / -1; }
  .house-history-row:not(.house-history-header) span:nth-child(4) { grid-column: 1; }
  .house-history-row:not(.house-history-header) span:last-child { align-self: end; justify-self: end; }
  .house-score-value { justify-self: start; }
}

@media (max-width: 900px) {
  .house-scores-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "entry" "history" "standings"; grid-template-rows: auto; }
  .house-standing-row { grid-template-columns: 36px minmax(0, 1fr) auto 68px; }
}

@media (max-width: 600px) {
  .house-scores-page { gap: 12px; }
  .house-scores-header { align-items: stretch; flex-direction: column; gap: 16px; padding: 18px; }
  .house-week-field { flex-basis: auto; width: auto; }
  .house-score-entry-panel,
  .house-standings-panel,
  .house-history-panel { padding: 16px; border-radius: 12px; }
  .house-section-heading { margin-bottom: 15px; }
  .house-score-fields { grid-template-columns: 1fr; }
  .house-score-options { gap: 6px; }
  .house-score-option { min-height: 60px; }
  .house-score-option span { font-size: 9px; }
  .house-standing-row { grid-template-columns: 34px minmax(0, 1fr) 64px; gap: 9px; padding-inline: 4px; }
  .house-standing-rounds { display: none; }
  .house-standing-average { font-size: 19px; }
  .house-history-heading { align-items: stretch; flex-direction: column; }
  #houseScoresExport { align-self: start; min-height: 44px; }
}

@media (max-width: 340px) {
  .house-score-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .house-standing-name small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .house-score-option { transition: none; }
}
