:root {
  --bg: #f7f7f5;
  --card-bg: #ffffff;
  --border: #e2e2df;
  --text: #1f1f1d;
  --text-muted: #6b6b66;
  --accent: #2f6f4f;
  --accent-hover: #245a3f;
  --danger: #b3261e;
  --good-bg: #e8f5ec;
  --good-text: #1e5c38;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

.site-header {
  max-width: 860px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 0.5rem;
  text-align: center;
}

.site-header h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--text-muted);
  margin: 0.25rem 0 0;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
}

.card h2 {
  margin-top: 0;
  font-size: 1.25rem;
}

.card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.hint {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.faq {
  padding-top: 0;
}

.faq details {
  border-top: 1px solid var(--border);
  padding: 0.9rem 0;
}

.faq details:last-of-type {
  padding-bottom: 0;
}

.faq summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.98rem;
  list-style: none;
}

.faq summary::-webkit-details-marker {
  display: none;
}

.faq summary::before {
  content: '+';
  display: inline-block;
  width: 1.1rem;
  color: var(--accent);
  font-weight: 700;
}

.faq details[open] summary::before {
  content: '\2212';
}

.faq summary:hover {
  color: var(--accent);
}

.faq-body {
  margin-top: 0.6rem;
  padding-left: 1.1rem;
  font-size: 0.92rem;
  color: var(--text);
}

.faq-body p {
  margin: 0 0 0.7rem;
}

.faq-body p:last-child {
  margin-bottom: 0;
}

.field-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  min-width: 180px;
}

.field span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

input[type="text"],
input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font-size: 0.95rem;
  width: 100%;
  background: var(--card-bg);
  color: var(--text);
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.names-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.names-grid-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  gap: 0.75rem;
}

.names-grid-header span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.remove-roommate {
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.remove-roommate:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

.remove-roommate:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#add-roommate {
  margin-bottom: 1.5rem;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.mode-picker {
  margin-bottom: 1.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.mode-option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.mode-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--good-bg);
}

.mode-option input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.turn-matrix {
  margin: 1rem 0;
}

.turn-matrix thead th {
  text-align: center;
}

.col-price {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.turn-matrix .row-label {
  white-space: nowrap;
}

.active-row {
  background: var(--good-bg);
}

.active-row .row-label {
  color: var(--good-text);
}

.inactive-row {
  color: var(--text-muted);
}

.inactive-row .row-label {
  color: var(--text-muted);
}

.matrix-cell {
  text-align: center;
}

.matrix-cell.held-cell {
  color: var(--text);
  font-weight: 600;
}

.tag {
  display: block;
  min-height: 1.2em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
}

/* The active row's cells hold a <button> instead of plain text. Its enclosing <td> drops
 * the usual cell padding so the button itself — using the exact same padding, border width,
 * and font size as a plain (inactive) cell — occupies exactly the space that cell would have,
 * keeping every row the same height regardless of which row is currently active. */
td.active-cell {
  padding: 0;
}

.room-choice-cell {
  display: block;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  background: transparent;
  cursor: pointer;
}

.room-choice-cell:hover {
  background: var(--good-bg);
}

.room-choice-cell.current {
  background: var(--good-bg);
  color: var(--good-text);
}

.auction-log {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.auction-log li {
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border-radius: 6px;
}

button {
  font-size: 0.95rem;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
}

button.primary {
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

button.secondary:hover {
  background: var(--bg);
}

.actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
  text-align: right;
}

th:first-child, td:first-child {
  text-align: left;
}

thead th {
  background: var(--bg);
  font-weight: 600;
}

.row-label {
  background: var(--bg);
  font-weight: 600;
  white-space: nowrap;
}

.val-input {
  min-width: 5.5rem;
  text-align: right;
}

.row-total {
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-muted);
}

.results-table .price,
tfoot .price {
  font-weight: 700;
  color: var(--accent);
}

.check-table td.assigned {
  background: var(--good-bg);
  color: var(--good-text);
  font-weight: 700;
}

.check-table td.tied {
  background: var(--good-bg);
  color: var(--good-text);
  font-weight: 700;
  opacity: 0.75;
}

.check-table .tag {
  display: block;
  min-height: 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: inherit;
}

.site-footer {
  max-width: 860px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem 2.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

.site-footer a {
  color: var(--accent);
}

@media (max-width: 520px) {
  .actions {
    flex-direction: column-reverse;
  }
  .actions button {
    width: 100%;
  }
}

.site-header .logo { display: block; margin: 0 auto 0.5rem; }
