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

html, body { height: 100%; overflow: hidden; }

:root {
  --bg-0: #0d1017;
  --bg-1: #141925;
  --bg-2: #1b2231;
  --bg-3: #232c3f;
  --line: rgba(148, 163, 200, 0.14);
  --line-strong: rgba(148, 163, 200, 0.28);
  --text: #e9ecf4;
  --text-dim: #9aa5bd;
  --accent: #f5b942;
  --accent-soft: rgba(245, 185, 66, 0.16);
  --danger: #e0605a;
  --glass: rgba(16, 20, 30, 0.82);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
}

body {
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg-0);
  color: var(--text);
  user-select: none;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 240px; min-width: 240px;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  z-index: 2;
}
#logo {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 16px;
  font-size: 17px; font-weight: 700; letter-spacing: 0.4px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(245, 185, 66, 0.07), transparent);
}
.logo-icon { font-size: 20px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4)); }

#palette { flex: 1; overflow-y: auto; padding: 6px 12px 24px; scrollbar-width: thin; scrollbar-color: #39415a transparent; }
#palette::-webkit-scrollbar { width: 6px; }
#palette::-webkit-scrollbar-thumb { background: #39415a; border-radius: 3px; }
#palette::-webkit-scrollbar-thumb:hover { background: #4a5470; }

.pal-head {
  margin: 16px 2px 8px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 1.4px;
  text-transform: uppercase; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}
.pal-head::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* minmax(0,1fr): long nowrap labels must ellipsize, not widen the columns
   past the sidebar (that pushed the third column out of view) */
.pal-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.pal-item {
  min-width: 0;
  background: linear-gradient(180deg, var(--bg-3), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 2px 5px;
  text-align: center;
  cursor: grab;
  transition: transform 0.1s ease, border-color 0.1s ease, box-shadow 0.1s ease;
}
.pal-item:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}
.pal-item.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft), var(--bg-2));
  box-shadow: 0 0 0 1px var(--accent), 0 6px 16px rgba(245, 185, 66, 0.15);
}
.pal-item canvas { display: block; margin: 0 auto; image-rendering: pixelated; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35)); }
.pal-emoji { font-size: 25px; line-height: 44px; height: 44px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.pal-name { font-size: 9.5px; color: var(--text-dim); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.pal-item.active .pal-name { color: var(--accent); }

/* ---------- canvas area ---------- */
#canvas-wrap { flex: 1; position: relative; overflow: hidden; background: var(--bg-0); }
#app.nosidebar #sidebar { display: none; }
#sidebar-toggle {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  z-index: 5;
  width: 20px; height: 58px;
  background: var(--glass); color: var(--text-dim);
  border: 1px solid var(--line); border-left: none;
  border-radius: 0 9px 9px 0;
  font-size: 11px; cursor: pointer; padding: 0;
  backdrop-filter: blur(10px);
  transition: color 0.1s, border-color 0.1s, width 0.1s;
}
#sidebar-toggle:hover { color: var(--text); border-color: var(--line-strong); width: 24px; }
#game { position: absolute; inset: 0; image-rendering: pixelated; cursor: crosshair; }
#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 120% 105% at 50% 45%, transparent 62%, rgba(5, 8, 16, 0.38) 100%);
  z-index: 1;
}

/* ---------- top bar ---------- */
#topbar {
  /* left/right + auto margins: centered, but free to use the full canvas
     width — wider than that it wraps instead of sliding under the sidebar */
  position: absolute; top: 12px; left: 12px; right: 12px;
  width: fit-content; margin: 0 auto;
  display: flex; align-items: center; gap: 6px 11px;
  flex-wrap: wrap; justify-content: center;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  z-index: 3;
}
#clock { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 148px; letter-spacing: 0.2px; }
.divider { width: 1px; height: 18px; background: var(--line-strong); }
.chip {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px; font-weight: 600;
  color: var(--text);
}
.stat { color: var(--text-dim); }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }

#speed { display: flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
#speed button {
  background: transparent; color: var(--text-dim);
  border: none; border-right: 1px solid var(--line);
  padding: 3px 10px;
  font-size: 13px; cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
#speed button:last-child { border-right: none; }
#speed button:hover { color: var(--text); background: var(--bg-3); }
#speed button.locked { opacity: 0.3; cursor: not-allowed; }
#speed button.active { background: var(--accent); color: #171207; }

#filebtns { display: flex; gap: 5px; }
#filebtns button {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 3px 9px; font-size: 13px; cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}
#filebtns button:hover { border-color: var(--line-strong); transform: translateY(-1px); }

/* ---------- hint bar ---------- */
#hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: var(--glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 18px;
  font-size: 12px; color: var(--text-dim);
  pointer-events: none;
  max-width: 82%;
  text-align: center;
  z-index: 3;
}

/* ---------- info panel ---------- */
#info {
  display: none;
  position: absolute; top: 74px; right: 16px;
  width: 244px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 3;
}
.info-title { font-size: 15px; font-weight: 700; margin-bottom: 9px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.info-row { margin: 5px 0; color: var(--text-dim); }
#info button {
  margin-top: 12px; margin-right: 6px;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 5px 12px; font-size: 12px; cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}
#info button:hover { border-color: var(--danger); background: rgba(224, 96, 90, 0.12); }
#info button#info-close:hover { border-color: var(--line-strong); background: var(--bg-2); }

/* ---------- PVTV: the village news channel ---------- */
#tv {
  width: 178px; height: 128px;
  display: flex; flex-direction: column; gap: 3px;
  align-self: flex-end;
}
#tv-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px; font-weight: 700; letter-spacing: 0.8px; color: var(--text-dim);
  padding: 0 2px;
}
.tv-live { display: flex; align-items: center; gap: 4px; color: #ff5a54; font-size: 9px; font-weight: 800; }
.tv-live i { width: 6px; height: 6px; border-radius: 50%; background: #ff5a54; }
@keyframes tvblink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0.15; } }
.tv-live i { animation: tvblink 1.1s infinite; }
#tv-screen {
  flex: 1; min-height: 0;
  background: #101622;
  border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 5px 6px;
  display: flex; gap: 6px; align-items: flex-start;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#tv.breaking #tv-screen { border-color: #ff5a54; box-shadow: 0 0 10px rgba(255, 90, 84, 0.45); }
#tv-anchor {
  image-rendering: pixelated;
  width: 34px; height: 34px; flex: none;
  background: #1c2536;
  border: 1px solid var(--line); border-radius: 4px;
}
#tv-headline {
  font-size: 10px; line-height: 1.35; color: var(--text);
  overflow: hidden; max-height: 68px;
}
#tv-headline.breaking { color: #ffd7d5; font-weight: 600; }
#tv-ticker {
  height: 15px; overflow: hidden; white-space: nowrap; position: relative;
  background: #0c1018;
  border: 1px solid var(--line); border-radius: 4px;
  font-size: 9px; line-height: 13px; color: #9fe0ae;
}
#tv-ticker span {
  position: absolute; left: 0; top: 0;
  padding-left: 100%;
  animation: tvticker 22s linear infinite;
}
@keyframes tvticker { 0% { transform: translateX(0); } 100% { transform: translateX(-100%); } }

/* ---------- SimCity panel: RCI demand + minimap ---------- */
#sc-panel {
  position: absolute; bottom: 14px; right: 14px;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--glass);
  backdrop-filter: blur(12px) saturate(1.3);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 10px;
  box-shadow: var(--shadow);
  z-index: 3;
}
#rci { display: flex; gap: 7px; align-items: flex-end; padding-bottom: 2px; }
.rci-col { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.rci-track {
  width: 10px; height: 64px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  display: flex; flex-direction: column-reverse;
  overflow: hidden;
}
.rci-track i { display: block; width: 100%; height: 0%; transition: height 0.6s ease; }
#rci-r { background: linear-gradient(180deg, #5fd484, #2f9e54); }
#rci-c { background: linear-gradient(180deg, #74a2f0, #3f6ec0); }
#rci-i { background: linear-gradient(180deg, #f0cc6a, #c09a2f); }
.rci-col b { font-size: 10px; }
.rci-r { color: #5fd484; } .rci-c { color: #74a2f0; } .rci-i { color: #f0cc6a; }
#minimap {
  width: 128px; height: 128px;
  image-rendering: pixelated;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
  display: block;
}

/* ---------- toasts ---------- */
#toasts {
  position: absolute; bottom: 52px; left: 16px;
  display: flex; flex-direction: column; gap: 7px;
  pointer-events: none;
  z-index: 3;
}
.toast {
  background: var(--glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  padding: 8px 13px;
  font-size: 12.5px;
  animation: slidein 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  max-width: 350px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.toast.out { opacity: 0; transform: translateX(-10px); transition: opacity 0.4s, transform 0.4s; }
@keyframes slidein { from { transform: translateX(-18px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- task book / journal ---------- */
#btn-journal { position: relative; }
#journal-badge {
  display: none;
  position: absolute; top: -6px; right: -6px;
  min-width: 16px; height: 16px;
  align-items: center; justify-content: center;
  background: var(--danger); color: #fff;
  border-radius: 999px;
  font-size: 9.5px; font-weight: 700;
  padding: 0 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
#journal {
  display: none;
  position: absolute; top: 74px; left: 16px;
  width: 320px; max-height: calc(100% - 160px);
  flex-direction: column;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 4;
  overflow: hidden;
}
#journal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px 9px;
  font-weight: 700; font-size: 14px;
  border-bottom: 1px solid var(--line);
}
#journal-head button {
  background: transparent; color: var(--text-dim);
  border: none; font-size: 13px; cursor: pointer; padding: 2px 5px;
}
#journal-head button:hover { color: var(--text); }
#journal-tabs { display: flex; gap: 6px; padding: 8px 12px 0; }
#journal-tabs button {
  flex: 1;
  background: var(--bg-2); color: var(--text-dim);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 0; font-size: 12px; cursor: pointer;
}
#journal-tabs button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
#journal-list {
  flex: 1; overflow-y: auto;
  padding: 8px 12px 12px;
  scrollbar-width: thin; scrollbar-color: #39415a transparent;
}
#journal-list::-webkit-scrollbar { width: 6px; }
#journal-list::-webkit-scrollbar-thumb { background: #39415a; border-radius: 3px; }
.j-item {
  display: flex; align-items: baseline; gap: 7px;
  padding: 5px 7px; margin: 3px 0;
  background: rgba(35, 44, 63, 0.5);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px; line-height: 1.35;
}
.j-item .j-ico { flex: none; }
.j-item .j-text { flex: 1; }
.j-item .j-day { flex: none; font-size: 10px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.j-item.done .j-text { text-decoration: line-through; color: var(--text-dim); }
.j-item.done { opacity: 0.75; }
.j-item.fail .j-text { text-decoration-color: var(--danger); }
.j-item.news { flex-direction: column; gap: 2px; }
.j-item.news .j-day { align-self: flex-start; }
.j-sep {
  margin: 12px 2px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--text-dim);
}
.j-empty { padding: 18px 8px; color: var(--text-dim); font-size: 12px; text-align: center; }

/* ---------- help overlay ---------- */
#help {
  display: none;
  position: absolute; inset: 0;
  background: rgba(6, 9, 16, 0.72);
  backdrop-filter: blur(6px);
  align-items: center; justify-content: center;
  z-index: 10;
}
#help-card {
  width: min(600px, 92%);
  max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 30px 34px;
  font-size: 14px; line-height: 1.6;
  box-shadow: var(--shadow);
}
#help-card h1 { font-size: 23px; margin-bottom: 10px; letter-spacing: 0.2px; }
#help-card ul { margin: 14px 0 14px 22px; }
#help-card li { margin: 7px 0; color: var(--text-dim); }
#help-card li b { color: var(--text); }
.help-controls { color: var(--text-dim); font-size: 12.5px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
#help-close {
  margin-top: 18px;
  background: linear-gradient(180deg, #ffca5f, var(--accent));
  color: #171207;
  border: none; border-radius: 10px;
  padding: 10px 26px;
  font-size: 15px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(245, 185, 66, 0.3);
  transition: transform 0.1s, box-shadow 0.1s;
}
#help-close:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(245, 185, 66, 0.4); }

/* ---------- shared modals: settings, save slots, history charts ---------- */
.modal {
  display: none;
  position: absolute; inset: 0;
  background: rgba(6, 9, 16, 0.72);
  backdrop-filter: blur(6px);
  align-items: center; justify-content: center;
  z-index: 10;
}
.modal-card {
  width: min(520px, 92%);
  max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 26px 30px;
  font-size: 14px; line-height: 1.6;
  box-shadow: var(--shadow);
}
.modal-card h1 { font-size: 20px; margin-bottom: 14px; letter-spacing: 0.2px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  margin: 11px 0; color: var(--text-dim);
}
.set-row label { flex: 1; }
.set-row select, .set-row input[type="text"], .set-row input:not([type]) {
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 6px 10px; font-size: 13px; min-width: 210px;
}
.set-row input[type="range"] { width: 210px; accent-color: var(--accent); }
.set-row button {
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 7px 14px; font-size: 13px; cursor: pointer;
}
.set-row button:hover { border-color: var(--accent); }
#settings-close, #saveui-close, #statsui-close {
  margin-top: 16px;
  background: linear-gradient(180deg, #ffca5f, var(--accent));
  color: #171207;
  border: none; border-radius: 10px;
  padding: 9px 24px;
  font-size: 14px; font-weight: 700;
  cursor: pointer;
}
#saveui-slots { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.save-slot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg-3); border: 1px solid var(--line-strong); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; color: var(--text);
  transition: border-color 0.1s, transform 0.1s;
}
.save-slot:hover { border-color: var(--accent); transform: translateY(-1px); }
.save-slot .slot-meta { color: var(--text-dim); font-size: 12px; }
.save-slot.empty .slot-meta { font-style: italic; }
#stats-canvas { width: 100%; image-rendering: auto; background: var(--bg-3); border-radius: 10px; }

/* clickable toasts that pan the camera to an incident */
.toast.jump { cursor: pointer; border-color: var(--accent); }
.toast.jump:hover { background: var(--bg-3); }

/* the village tier chip */
#chip-tier { cursor: default; }

/* clickable people links in the inspector */
.p-link { color: var(--accent); cursor: pointer; }
.p-link:hover { text-decoration: underline; }
