/* ===== Life Simulation – full stylesheet ===== */
/* Designed for Fairbanks / pallet-town-winter style light backgrounds:
   text sits on semi-opaque dark pills; panels stay mostly transparent. */

:root {
  --bg: #0d0d11;
  --panel: rgba(18, 18, 24, 0.72);
  --panel-solid: #16161c;
  --card: rgba(30, 30, 38, 0.55);
  --card-hover: rgba(40, 40, 50, 0.7);
  --border: rgba(255, 255, 255, 0.14);
  --text: #f0f0f5;
  --muted: #b0b0c0;
  --gold: #c9a227;
  --gold-h: #e0b83a;
  --danger: #c0392b;
  --ok: #27ae60;
  --partner: #2e6b4f;
  --friend: #2e5a8b;
  --family: #8b5a2e;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
}

body {
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.45;
  background-color: #1a1a22;
  background-image: url("../game-photos/pallet-town-winter.jpg");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
}

/* Fallback if image missing */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, rgba(12, 16, 28, 0.35), rgba(8, 10, 18, 0.55));
  pointer-events: none;
  z-index: 0;
}

body > * {
  position: relative;
  z-index: 1;
}

/* ===== Header ===== */
.header {
  background: rgba(16, 16, 22, 0.88);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
  gap: 8px;
  backdrop-filter: blur(6px);
}

.header h1 {
  font-size: 1.15rem;
  color: var(--gold);
  letter-spacing: 0.5px;
}

.header-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

#year-display {
  font-weight: 600;
  margin-right: 6px;
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 10px;
  border-radius: 8px;
}

/* ===== Buttons ===== */
button,
.action-btn {
  background: var(--gold);
  color: #111;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.86rem;
  cursor: pointer;
  font-weight: 600;
  line-height: 1.2;
}

button:hover,
.action-btn:hover {
  background: var(--gold-h);
}

button.secondary,
.action-btn.secondary {
  background: rgba(50, 50, 60, 0.9);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover,
.action-btn.secondary:hover {
  background: rgba(70, 70, 85, 0.95);
}

button.danger,
.action-btn.danger {
  background: var(--danger);
  color: #fff;
}

button.success,
.action-btn.success {
  background: var(--ok);
  color: #fff;
}

/* Action button rows — horizontal wrap, less empty space */
#action-buttons,
#job-buttons,
#education-buttons,
#housing-buttons,
#vehicle-buttons,
#insurance-buttons,
#family-actions,
#relationship-actions,
#career-actions,
#sports-actions,
#stayhome-actions,
#legacy-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

#action-buttons .action-btn,
.action-btn {
  flex: 1 1 130px;
  min-width: 120px;
  max-width: 200px;
}

/* ===== Main layout ===== */
#main-game {
  display: grid;
  /* 2 columns: left = player + log, right = households + orphans under them */
  grid-template-columns: minmax(280px, 360px) 1fr;
  grid-template-rows: auto auto;
  grid-template-areas:
    "player people"
    "log    orphan";
  gap: 12px;
  padding: 12px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
  width: 100%;
  box-sizing: border-box;
}

.player-column {
  grid-area: player;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  min-width: 0;
  width: 100%;
}

.people-panel {
  grid-area: people;
  min-width: 0;
  width: 100%;
}

.orphan-panel {
  grid-area: orphan;
  min-width: 0;
  width: 100%;
  max-height: 280px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.log-panel {
  grid-area: log;
  max-height: min(42vh, 420px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Tablet: 2 columns */
@media (max-width: 1100px) {
  #main-game {
    grid-template-columns: 1fr 1fr !important;
    grid-template-areas:
      "player people"
      "log    orphan" !important;
  }
  .player-column { grid-area: player; position: static; max-height: none; }
  .people-panel { grid-area: people; }
  .orphan-panel { grid-area: orphan; }
  .log-panel { grid-area: log; }
}

/* Phone: single column, full width */
@media (max-width: 700px) {
  #main-game {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px;
    padding: 8px;
    width: 100% !important;
    max-width: 100% !important;
  }
  .player-column,
  .people-panel,
  .orphan-panel,
  .log-panel,
  .panel {
    position: static !important;
    max-height: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
  .player-column {
    order: 1;
  }
  .people-panel {
    order: 2;
  }
  .orphan-panel {
    order: 3;
  }
  .log-panel {
    order: 4;
  }
  .header {
    flex-direction: column;
    align-items: stretch;
  }
  .header-controls {
    width: 100%;
  }
  .header-controls button {
    flex: 1 1 auto;
  }
  #action-buttons .action-btn,
  .action-btn {
    flex: 1 1 calc(50% - 6px) !important;
    max-width: none !important;
    min-width: 0 !important;
  }
  .household-card {
    width: calc(50% - 8px) !important;
    min-width: 0 !important;
  }
  .player-card .stat-row,
  .player-card .bits {
    gap: 4px 6px;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--gold);
  background: rgba(0, 0, 0, 0.5);
  display: inline-block;
  padding: 4px 12px;
  border-radius: 8px;
}

/* People / households — transparent so winter bg shows */
.people-panel,
.panel.people-panel,
#npc-list,
.npc-list {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

.people-panel {
  min-height: 200px;
}

.orphan-panel {
  background: rgba(18, 18, 24, 0.65);
}

.log-panel {
  grid-area: log !important;
  grid-column: auto !important;
  max-height: min(42vh, 420px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
}

#log,
.log {
  overflow-y: auto;
  max-height: 220px;
  font-size: 0.82rem;
  color: var(--muted);
}

#log div,
.log div {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

/* ===== Player card — horizontal stats ===== */
.player-card {
  background: rgba(22, 22, 30, 0.82);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.player-card strong {
  font-size: 1.1rem;
  color: var(--gold);
}

.player-card .stat-row,
.player-card .bits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  margin-top: 6px;
  font-size: 0.88rem;
}

.player-card .stat-row span,
.player-card .bits span {
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.family-box {
  margin-top: 8px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  font-size: 0.86rem;
}

.health-bad,
.money-bad {
  color: #ff8a8a;
}

.health-ok,
.money-good {
  color: #7dcea0;
}

/* Tags */
.tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  margin-right: 4px;
}

.tag.married { background: var(--partner); }
.tag.family { background: var(--family); }
.tag.home { background: #3a5a7a; }
.tag.homeless { background: var(--danger); }
.tag.lgbt { background: #6b3a8a; }
.tag.bigot { background: #5a3a2a; }
.tag.foster { background: #4a4a6a; }
.tag.observer { background: #555; }

/* ===== Household cards ===== */
#npc-list {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
  gap: 12px 10px !important;
  align-items: start;
  width: 100%;
  box-sizing: border-box;
  overflow: visible;
}

.household-card {
  background: transparent !important;
  border: none !important;
  padding: 4px !important;
  cursor: pointer;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  width: 100% !important;
  max-width: 120px !important;
  min-width: 0 !important;
  margin: 0 auto !important;
  box-sizing: border-box;
  text-align: center;
  overflow: hidden;
}

.household-card img {
  width: 88px !important;
  height: 70px !important;
  max-width: 88px !important;
  max-height: 70px !important;
  object-fit: contain !important;
  display: block;
  margin: 0 auto 6px !important;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  transition: transform 0.15s;
}

.household-card:hover img {
  transform: scale(1.06);
}

.household-card .hh-label {
  display: block;
  background: rgba(0, 0, 0, 0.6);
  color: #f0f0f5;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 0.75rem;
  line-height: 1.3;
  max-width: 100%;
  text-shadow: 0 1px 2px #000;
  word-break: break-word;
}

@media (max-width: 900px) {
  #npc-list {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
  }
  .household-card img {
    width: 78px !important;
    height: 62px !important;
    max-width: 78px !important;
    max-height: 62px !important;
  }
}

@media (max-width: 700px) {
  #npc-list {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px 8px !important;
  }
  .household-card {
    max-width: none !important;
  }
  .household-card img {
    width: 100px !important;
    height: 80px !important;
    max-width: 100px !important;
    max-height: 80px !important;
  }
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  align-items: center;
}

.filter-bar select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(20, 20, 28, 0.85);
  color: var(--text);
  font-size: 0.85rem;
}

/* Orphan list */
.orphan-list {
  max-height: 50vh;
  overflow-y: auto;
  font-size: 0.85rem;
}

/* ===== Modals ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: rgba(22, 22, 30, 0.96);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  max-width: 640px;
  width: 94vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  color: var(--text);
}

.modal h2 {
  color: var(--gold);
  margin-bottom: 10px;
  font-size: 1.2rem;
}

.modal h3 {
  margin: 12px 0 6px;
  font-size: 0.95rem;
  color: #ddd;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

.modal-close:hover {
  color: #fff;
}

/* Create character — horizontal form grid */
#create-modal .modal {
  max-width: 680px;
}

/* Character creator — ALWAYS horizontal grid */
#create-modal.modal-overlay,
#create-modal {
  align-items: stretch !important;
  justify-content: center !important;
  padding: 8px !important;
}
#create-modal .modal {
  max-width: min(960px, 100%) !important;
  width: 100% !important;
  margin: auto !important;
  box-sizing: border-box !important;
}
#create-modal .create-grid,
#create-modal .form-grid,
.create-grid,
.btn-grid,
div.create-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 12px 14px !important;
  margin: 12px 0 16px !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}
@media (min-width: 600px) {
  #create-modal .create-grid,
  div.create-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}
@media (min-width: 900px) {
  #create-modal .create-grid,
  div.create-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }
}

#create-modal .create-grid > div,
.create-grid > div {
  display: flex !important;
  flex-direction: column !important;
  gap: 4px !important;
  margin: 0 !important;
  width: 100% !important;
  min-width: 0 !important;
}

#create-modal .create-grid label,
.create-grid label {
  display: block !important;
  margin: 0 !important;
  font-size: 0.82rem !important;
  color: #c8c8d4 !important;
  font-weight: 600 !important;
}

#create-modal .form-grid {
  grid-template-columns: 1fr 1fr !important;
  gap: 10px 14px !important;
  text-align: left !important;
}

#create-modal .form-grid label {
  display: block !important;
  margin: 0 !important;
  font-size: 0.88rem !important;
}

/* Kill any block-stacking rules that force vertical lists inside create modal */
#create-modal label:not(.grid-option),
#create-modal .modal > label {
  /* only when NOT inside create-grid children handled above */
}
#create-modal .modal > div:not(.create-grid):not(.form-grid) {
  /* leave alone */
}

#create-modal select,
#create-modal input[type="text"],
#create-modal input[type="number"],
.modal select,
.modal input[type="text"],
.modal input[type="number"] {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #444;
  background: #1e1e26;
  color: #eee;
  box-sizing: border-box;
  margin-top: 4px;
}

.grid-option {
  display: block;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1.3;
}

.grid-option:hover {
  border-color: var(--gold);
  background: rgba(0, 0, 0, 0.55);
}

.grid-option input {
  margin-right: 4px;
}

/* Job / trade lists inside modals */
#job-list,
#trade-list,
#legacy-choices,
#social-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#job-list .action-btn,
#trade-list .action-btn,
#legacy-choices .action-btn,
#social-body .action-btn {
  max-width: none;
  width: 100%;
}

#social-body .btn-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

#social-body .btn-grid .action-btn,
#social-body .btn-grid .grid-option {
  max-width: none;
  width: 100%;
}

/* Quiz / license */
.quiz-q {
  margin: 10px 0;
  padding: 10px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
}

/* Influence row */
.influence-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* Mobile */
@media (max-width: 700px) {
  .header h1 {
    font-size: 1rem;
  }
  .player-column {
    position: static;
    max-height: none;
  }
  #create-modal .form-grid {
    grid-template-columns: 1fr;
  }
  .action-btn {
    max-width: none;
  }
}


/* ===== FINAL mobile overrides (highest priority) ===== */
@media (max-width: 700px) {
  html, body {
    overflow-x: hidden;
    width: 100%;
  }
  #main-game {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    padding: 8px !important;
    margin: 0 !important;
  }
  .player-column,
  .people-panel,
  .orphan-panel,
  .log-panel {
    width: 100% !important;
    max-width: 100% !important;
    position: static !important;
    max-height: none !important;
  }
  .people-panel {
    grid-column: auto !important;
  }
  .log-panel {
    grid-column: auto !important;
  }
  #npc-list {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100% !important;
    gap: 10px 8px !important;
  }
  .household-card {
    width: 100% !important;
    max-width: none !important;
    margin: 0 auto !important;
  }
  .household-card img {
    width: 100px !important;
    height: 80px !important;
    max-width: 100px !important;
    max-height: 80px !important;
  }
  #action-buttons {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
  }
  #action-buttons .action-btn {
    max-width: none !important;
    width: 100% !important;
    flex: none !important;
  }
  .player-card {
    width: 100%;
  }
  /* Create character: full width, 2 columns on phone */
  #create-modal .modal {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 12px;
  }
  #create-modal .create-grid {
    grid-template-columns: 1fr 1fr !important;
    width: 100% !important;
  }
  #create-modal .create-grid > div {
    width: 100% !important;
  }
  #create-modal select,
  #create-modal input {
    width: 100% !important;
    font-size: 16px !important; /* prevents iOS zoom */
  }
}



/* ===== FINAL household size lock (desktop + mobile) ===== */
#npc-list {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 12px 10px !important;
  align-items: flex-start !important;
  justify-content: flex-start !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}
.household-card {
  width: 110px !important;
  max-width: 110px !important;
  min-width: 0 !important;
  margin: 0 !important;
  padding: 2px !important;
  overflow: hidden !important;
  flex: 0 0 110px !important;
}
.household-card img {
  width: 90px !important;
  height: 70px !important;
  max-width: 90px !important;
  max-height: 70px !important;
  object-fit: contain !important;
}
.household-card .hh-label {
  font-size: 0.72rem !important;
  padding: 3px 5px !important;
  width: 100% !important;
  box-sizing: border-box;
}
@media (max-width: 700px) {
  .household-card {
    width: calc(50% - 8px) !important;
    max-width: calc(50% - 8px) !important;
    flex: 0 0 calc(50% - 8px) !important;
  }
  .household-card img {
    width: 100px !important;
    height: 80px !important;
    max-width: 100px !important;
    max-height: 80px !important;
  }
}


/* ===== Desktop: 2 columns — player/log left, households/orphans right ===== */
@media (min-width: 701px) {
  #main-game {
    display: grid !important;
    grid-template-columns: minmax(280px, 360px) 1fr !important;
    grid-template-rows: auto auto !important;
    grid-template-areas:
      "player people"
      "log    orphan" !important;
  }
  .player-column { grid-area: player !important; }
  .people-panel  { grid-area: people !important; }
  .orphan-panel  {
    grid-area: orphan !important;
    grid-column: unset !important;
    max-height: 300px;
  }
  .log-panel {
    grid-area: log !important;
    grid-column: unset !important;
    grid-row: unset !important;
    max-height: min(42vh, 420px);
    width: 100% !important;
  }
}

