:root {
  --bg: #0e141b;
  --panel: rgba(18, 26, 36, 0.9);
  --panel-solid: #18222f;
  --border: #3a4f66;
  --border-light: #597592;
  --text: #f3efe6;
  --muted: #9fb0c2;
  --primary: #d96b78;
  --primary-hover: #ea7d8a;
  --accent: #4aa88c;
  --gold: #f0be59;
  --health: #e06377;
  --happy: #f0be59;
  --know: #5ba4e5;
  --bonds: #56c297;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans KR', 'Hahmlet', system-ui, -apple-system, sans-serif;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.px-ico {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
  image-rendering: pixelated;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  background: #273647;
  border: 1px solid #4c647e;
  border-radius: 4px;
  color: var(--gold);
}

/* Pixel Buttons */
.px-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background: #243344;
  border: 2px solid var(--border-light);
  box-shadow: 0 2px 0 #0b1017;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.08s ease, background 0.15s ease;
}

.px-btn:hover:not(:disabled) {
  background: #2f4359;
}

.px-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #0b1017;
}

.px-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-btn {
  background: var(--primary);
  border-color: #f29ca7;
}
.primary-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.accent-btn {
  background: var(--accent);
  border-color: #84dbc0;
  color: #092019;
}
.accent-btn:hover:not(:disabled) {
  background: #5bc2a2;
}

.ghost-btn {
  background: rgba(36, 51, 68, 0.72);
}

.danger-btn {
  background: #402730;
  border-color: #844e61;
}

.icon-btn {
  padding: 6px 8px;
  min-width: 32px;
}

.lg-btn {
  padding: 12px 20px;
  font-size: 15px;
}

/* Unified Single Top HUD */
.hud-bar {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 12px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  z-index: 12;
}

.hud-identity {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1.05;
}

.pixel-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 5px;
  background: #27384b;
  border: 2px solid var(--gold);
  border-radius: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  font-size: 12.5px;
  color: var(--gold);
  flex-shrink: 0;
}

.hud-title-group {
  min-width: 0;
}

.hud-name-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.hud-name-row strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag-pill {
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: #26394d;
  border: 1px solid #486583;
  color: #dbe8f5;
  white-space: nowrap;
}

.tag-pill.subtle {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--muted);
}

.hud-sub-row {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Middle Timeline Block */
.hud-timeline {
  flex: 1.25;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.time-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.time-month {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  white-space: nowrap;
}

.activity-pill {
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(74, 168, 140, 0.16);
  border: 1px solid rgba(132, 219, 192, 0.5);
  color: #b7f5e1;
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-pair {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 8px;
  align-items: center;
}

.year-progress-wrap {
  display: grid;
  grid-template-columns: 1fr 30px;
  align-items: center;
  gap: 5px;
}

.life-arc-wrap {
  display: flex;
  align-items: center;
}

.prog-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  text-align: right;
  color: #dbe8f5;
}

.year-progress-track,
.life-arc-track {
  position: relative;
  width: 100%;
  height: 8px;
  background: #0c1219;
  border: 1px solid #35475a;
  border-radius: 4px;
  overflow: hidden;
}

.year-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4aa88c, #f0be59);
  transition: width 0.08s linear;
}

.year-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    90deg,
    transparent,
    transparent calc(100% / 12 - 1px),
    rgba(255, 255, 255, 0.16) calc(100% / 12 - 1px),
    rgba(255, 255, 255, 0.16) calc(100% / 12)
  );
}

.life-arc-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5ba4e5, #d96b78);
  transition: width 0.25s ease;
}

.life-milestones {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.life-ms-dot {
  position: absolute;
  top: 50%;
  width: 4px;
  height: 6px;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.3);
  border-radius: 1px;
}

.life-ms-dot.reached {
  background: var(--gold);
}

/* Right Block: Economy + Speed + Settings */
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.hud-economy {
  display: flex;
  align-items: center;
  gap: 10px;
}

.econ-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.econ-label {
  font-size: 9.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.econ-box strong {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--gold);
}

.econ-box strong.muted-val {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.speed-controls {
  display: flex;
  align-items: center;
  gap: 3px;
}

.speed-btn {
  padding: 5px 7px;
  min-width: 30px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
  font-weight: 700;
}

.speed-btn.active {
  background: #3a4e2f;
  border-color: var(--gold);
  color: var(--gold);
}

.pause-btn.paused {
  background: var(--primary);
  border-color: #f29ca7;
  color: #ffffff;
}

/* Settings Popover */
.settings-popover {
  position: absolute;
  top: 72px;
  right: 12px;
  width: 245px;
  padding: 8px;
  background: var(--panel-solid);
  border: 2px solid var(--border-light);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 25;
}

.menu-item-btn {
  width: 100%;
  justify-content: flex-start;
  padding: 8px 10px;
  font-size: 12.5px;
}

.menu-item-btn.active {
  background: #234740;
  border-color: #84dbc0;
  color: #b7f5e1;
}

.menu-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 2px 0;
}

/* Compact Live Event Feed */
.live-feed {
  position: absolute;
  left: 12px;
  bottom: 136px;
  width: min(352px, calc(100vw - 24px));
  padding: 6px 10px;
  background: rgba(15, 22, 31, 0.82);
  border: 1px solid var(--border);
  border-radius: 8px;
  backdrop-filter: blur(4px);
  z-index: 9;
  cursor: pointer;
}

.live-feed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 4px;
}

.feed-more-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 10.5px;
  color: var(--muted);
  cursor: pointer;
}

.feed-more-btn:hover {
  color: var(--text);
}

.live-feed-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.live-feed-item {
  font-size: 11px;
  line-height: 1.35;
  color: #c8d2de;
  padding-left: 6px;
  border-left: 2px solid var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-feed-item.latest {
  border-left-color: var(--gold);
  color: #ffffff;
}

/* Bottom HUD Panels */
.hud-panel {
  position: absolute;
  bottom: 12px;
  padding: 9px 11px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  z-index: 10;
}

.left-panel {
  left: 12px;
  width: min(352px, calc(100vw - 24px));
}

.right-panel {
  right: 12px;
  padding: 8px 10px;
}

.action-bar-single {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}

.stat-row {
  display: grid;
  grid-template-columns: 78px 1fr 24px;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
}

.stat-lbl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  color: #e4ded2;
}

.stat-bar {
  height: 9px;
  background: #0d131a;
  border: 1px solid #35475a;
  border-radius: 4px;
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  width: 50%;
  transition: width 0.35s ease;
}

.stat-fill.health { background: var(--health); }
.stat-fill.happy { background: var(--happy); }
.stat-fill.know { background: var(--know); }
.stat-fill.bonds { background: var(--bonds); }

.stat-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-align: right;
  color: var(--muted);
}

.focus-row {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.focus-lbl {
  font-size: 11px;
  color: var(--muted);
}

.focus-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.focus-pill {
  padding: 2px 7px;
  font-size: 11px;
  font-family: inherit;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid #334558;
  border-radius: 999px;
  cursor: pointer;
}

.focus-pill.active {
  background: #2b455e;
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 600;
}

/* Overlays & Modals */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 11, 16, 0.74);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}

.modal-card {
  width: min(600px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--panel-solid);
  border: 2px solid var(--border-light);
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65);
  overflow: hidden;
}

.birth-card {
  padding: 24px;
  gap: 14px;
}

.brand-badge {
  align-self: flex-start;
  padding: 4px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: #273748;
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 6px;
}

.birth-card h1 {
  margin: 0;
  font-family: 'Hahmlet', serif;
  font-size: clamp(22px, 3vw, 27px);
  line-height: 1.3;
}

.lead {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}

.birth-roll-box {
  padding: 12px 14px;
  background: #101822;
  border: 2px solid var(--gold);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.roll-label {
  font-size: 12px;
  color: var(--muted);
}

.roll-country {
  font-family: 'Hahmlet', serif;
  font-size: 17px;
  color: var(--gold);
}

.birth-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.birth-advanced {
  background: rgba(15, 23, 32, 0.65);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.birth-advanced summary {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: #dbe8f5;
  cursor: pointer;
  list-style: none;
}

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

.birth-form {
  display: grid;
  grid-template-columns: 1fr 170px;
  gap: 10px;
  margin-top: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

.field select,
.field input,
.field textarea {
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: #0f1720;
  border: 2px solid var(--border);
  border-radius: 6px;
}

.controls-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11.5px;
  color: var(--muted);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  background: #121a24;
}

.modal-header h2 {
  margin: 0;
  font-family: 'Hahmlet', serif;
  font-size: 17px;
}

.modal-body {
  padding: 15px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 11px;
  font-size: 14px;
  line-height: 1.55;
}

.choice-list,
.shop-list,
.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  padding: 11px 12px;
  background: #101720;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.log-entry {
  padding: 7px 10px;
  border-left: 3px solid var(--gold);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0 6px 6px 0;
  font-size: 13px;
}

/* Minigames */
.mg-stage {
  padding: 14px;
  background: #0d131a;
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.mg-symbols {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.mg-sym-btn {
  width: 58px;
  height: 58px;
  font-size: 24px;
  background: #1e2b3a;
  border: 2px solid var(--border-light);
  border-radius: 8px;
  cursor: pointer;
}

.mg-sym-btn.lit {
  background: #3a593d;
  border-color: var(--gold);
  transform: scale(1.06);
}

.timing-track {
  position: relative;
  width: 100%;
  height: 28px;
  background: #17202b;
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.timing-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(240, 190, 89, 0.35);
  border-left: 2px solid var(--gold);
  border-right: 2px solid var(--gold);
}

.timing-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  background: #ffffff;
  box-shadow: 0 0 8px #ffffff;
}

/* Toast at Bottom-Center (never blocks top buildings) */
.toast {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  background: rgba(16, 23, 32, 0.95);
  border: 1px solid var(--gold);
  color: #fce2a6;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  z-index: 40;
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

@media (max-width: 1080px) {
  .hud-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .hud-timeline {
    order: 3;
    flex: 1 1 100%;
    border-left: none;
    border-right: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 5px 0 0 0;
  }
}

@media (max-width: 860px) {
  .hud-bar {
    top: 8px;
    left: 8px;
    right: 8px;
    padding: 6px 9px;
    gap: 6px;
  }
  .pixel-badge {
    min-width: 32px;
    height: 32px;
    font-size: 11px;
  }
  .hud-sub-row,
  .life-arc-wrap {
    display: none;
  }
  .hud-economy {
    gap: 6px;
  }
  .econ-box strong {
    font-size: 11px;
  }
  .hud-right {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }
  .hud-timeline {
    min-width: 0;
  }
  .progress-pair {
    grid-template-columns: 1fr;
  }
  .speed-controls {
    gap: 2px;
  }
  .speed-btn {
    padding: 4px 5px;
    min-width: 24px;
    font-size: 10.5px;
  }
  .icon-btn {
    padding: 4px 6px;
    min-width: 28px;
  }
  .settings-popover {
    top: 122px;
    right: 8px;
  }
  .live-feed {
    display: none;
  }
  .left-panel {
    left: 8px;
    right: 8px;
    width: auto;
    bottom: 58px;
    padding: 6px 9px;
  }
  .stat-list {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .stat-row {
    grid-template-columns: 14px 1fr 20px;
    gap: 3px;
    font-size: 10.5px;
  }
  .stat-lbl {
    font-size: 0;
    gap: 0;
  }
  .focus-row {
    margin-top: 5px;
    padding-top: 5px;
    gap: 4px;
  }
  .focus-lbl {
    display: none;
  }
  .focus-pill {
    padding: 2px 6px;
    font-size: 10.5px;
  }
  .right-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 5px 8px;
  }
  .action-bar-single {
    justify-content: space-between;
    gap: 4px;
  }
  .btn-lbl-hide-sm {
    display: none;
  }
  .birth-form {
    grid-template-columns: 1fr;
  }
  .overlay {
    padding: 0;
  }
  .modal-card {
    max-height: 82vh;
    align-self: flex-end;
    border-radius: 14px 14px 0 0;
  }
  .birth-card {
    align-self: center;
    margin: 12px;
    border-radius: 12px;
    padding: 18px;
  }
  .toast {
    bottom: 132px;
  }
}
