/*!
 * City Planner — city-planner.css
 * Everything is scoped under #game.cp-game so it cannot leak into the site
 * template. Colours meet WCAG AA contrast on the dark chrome.
 */

#game.cp-game {
  --cp-bg: #17202b;
  --cp-panel: #1f2a37;
  --cp-panel-2: #273444;
  --cp-line: #3a4a5e;
  --cp-text: #eef3f8;
  --cp-muted: #a9b7c6;
  --cp-accent: #f2cf4a;
  --cp-accent-ink: #1b1b1b;
  --cp-good: #4cc985;
  --cp-warn: #f0b13a;
  --cp-bad: #ff7a6b;
  --cp-r: #4caf50;
  --cp-c: #3d8bdb;
  --cp-i: #e2b52e;
  --cp-focus: #ffd54a;

  position: relative;
  display: block;
  width: 100%;
  height: clamp(540px, 82vh, 920px);
  aspect-ratio: auto;
  padding: 0;
  overflow: hidden;
  background: var(--cp-bg);
  color: var(--cp-text);
  font-family: Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.35;
  border-radius: 12px;
  user-select: none;
  -webkit-user-select: none;
}
#game.cp-game:fullscreen { height: 100vh; border-radius: 0; }
#game.cp-game:-webkit-full-screen { height: 100vh; border-radius: 0; }

#game.cp-game *, #game.cp-game *::before, #game.cp-game *::after { box-sizing: border-box; }

#game.cp-game button {
  font: inherit;
  color: var(--cp-text);
  background: var(--cp-panel-2);
  border: 1px solid var(--cp-line);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
  line-height: 1.2;
  transition: background .12s, border-color .12s, transform .05s;
}
#game.cp-game button:hover:not(:disabled) { background: #314257; border-color: #52667e; }
#game.cp-game button:active:not(:disabled) { transform: translateY(1px); }
#game.cp-game button:disabled { opacity: .45; cursor: default; }
#game.cp-game button.primary { background: var(--cp-accent); color: var(--cp-accent-ink); border-color: #c9a92e; font-weight: 800; }
#game.cp-game button.primary:hover:not(:disabled) { background: #ffdc5c; }
#game.cp-game :focus { outline: none; }
#game.cp-game :focus-visible,
#game.cp-game .cp-canvas:focus-visible {
  outline: 3px solid var(--cp-focus);
  outline-offset: 2px;
}
#game.cp-game kbd {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .85em;
  background: #0f161f;
  border: 1px solid var(--cp-line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
}

/* ---------------- Layout ---------------- */
.cp-app {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.cp-main {
  display: grid;
  grid-template-columns: auto 1fr 230px;
  min-height: 0;
}

/* ---------------- Top status bar ---------------- */
.cp-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 7px 10px;
  background: linear-gradient(#26334a, #1c2636);
  border-bottom: 2px solid #0c121a;
}
.cp-city { display: flex; flex-direction: column; min-width: 120px; }
.cp-name {
  font-family: Fredoka, Nunito, sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--cp-accent);
  line-height: 1.1;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cp-class { font-size: 12px; color: var(--cp-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.cp-stats { display: flex; gap: 14px; }
.cp-stat { display: flex; flex-direction: column; min-width: 70px; }
.cp-stat span:last-child { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.cp-lbl { font-size: 11px; color: var(--cp-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.cp-bad { color: var(--cp-bad) !important; }
.cp-speed { display: flex; gap: 0; }
#game.cp-game .cp-speed button { border-radius: 0; padding: 5px 9px; font-size: 11px; letter-spacing: -1px; min-width: 38px; }
#game.cp-game .cp-speed button:first-child { border-radius: 7px 0 0 7px; }
#game.cp-game .cp-speed button:last-child { border-radius: 0 7px 7px 0; }
#game.cp-game .cp-speed button[aria-pressed="true"] { background: var(--cp-accent); color: var(--cp-accent-ink); border-color: #c9a92e; }
#game.cp-game .cp-speed button.held { background: #7a6a2a; color: #fff; }
.cp-menu { display: flex; flex-wrap: wrap; gap: 5px; margin-left: auto; }
#game.cp-game .cp-menu button { padding: 5px 9px; font-weight: 700; font-size: 13px; }
#game.cp-game #cp-sound.off { opacity: .55; text-decoration: line-through; }
#game.cp-game .cp-side-toggle { display: none; }

/* ---------------- Toolbar ---------------- */
.cp-toolbar {
  background: var(--cp-panel);
  border-right: 2px solid #0c121a;
  padding: 6px 6px 10px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
.cp-tgroup + .cp-tgroup { margin-top: 6px; }
.cp-tgroup-label { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: var(--cp-muted); margin: 0 0 3px 2px; }
.cp-tgrid { display: grid; grid-template-columns: repeat(2, 38px); gap: 4px; }
#game.cp-game .cp-tool {
  position: relative;
  width: 38px; height: 38px;
  padding: 6px;
  display: grid;
  place-items: center;
  color: #dfe7ef;
  background: var(--cp-panel-2);
}
.cp-tool svg { width: 24px; height: 24px; }
#game.cp-game .cp-tool[aria-pressed="true"] { background: #3c5070; border-color: var(--cp-accent); box-shadow: inset 0 0 0 1px var(--cp-accent); }
#game.cp-game .cp-tool.locked { opacity: .45; }
.cp-lock { display: none; position: absolute; right: 1px; bottom: 1px; width: 12px; height: 12px; color: #fff; }
.cp-tool.locked .cp-lock { display: block; }
.cp-lock svg { width: 12px; height: 12px; }
#game.cp-game .cp-tool.hint { animation: cp-pulse 1.2s ease-in-out infinite; }
@keyframes cp-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(242, 207, 74, .9); } 50% { box-shadow: 0 0 0 5px rgba(242, 207, 74, 0); } }

/* ---------------- Map view ---------------- */
.cp-view { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #0e1621; }
.cp-canvas { display: block; position: absolute; inset: 0; touch-action: none; }
.cp-zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; z-index: 2; }
#game.cp-game .cp-zoom button { width: 34px; height: 34px; padding: 0; font-size: 20px; font-weight: 800; background: rgba(31, 42, 55, .92); }
.cp-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(12, 18, 28, .85); color: var(--cp-accent);
  font-family: Fredoka, sans-serif; font-weight: 700; letter-spacing: .15em;
  padding: 4px 14px; border-radius: 999px; pointer-events: none; z-index: 2;
}
.cp-tutorial {
  position: absolute; left: 10px; top: 10px; z-index: 3;
  width: min(330px, calc(100% - 20px));
  background: rgba(20, 28, 40, .96);
  border: 2px solid var(--cp-accent);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.cp-tut-step { font-size: 11px; font-weight: 800; color: var(--cp-accent); text-transform: uppercase; letter-spacing: .08em; }
.cp-tut-text { margin: 4px 0 8px; }
.cp-tut-btns { display: flex; justify-content: space-between; gap: 8px; }

/* ---------------- Side panel ---------------- */
.cp-side {
  background: var(--cp-panel);
  border-left: 2px solid #0c121a;
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
}
.cp-card { background: var(--cp-panel-2); border: 1px solid var(--cp-line); border-radius: 9px; padding: 7px; }
.cp-card-h { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: var(--cp-muted); margin-bottom: 5px; }
.cp-card-h small { text-transform: none; letter-spacing: 0; font-weight: 700; }
.cp-mini { display: block; width: 100%; aspect-ratio: 120 / 100; image-rendering: pixelated; border-radius: 5px; cursor: pointer; background: #0e1621; }
.cp-rci { display: flex; justify-content: center; gap: 18px; height: 78px; }
.cp-rci-col { display: flex; flex-direction: column; align-items: center; gap: 3px; height: 100%; }
.cp-rci-bar { position: relative; width: 18px; flex: 1; background: #141c26; border: 1px solid var(--cp-line); border-radius: 3px; }
.cp-rci-bar::after { content: ""; position: absolute; left: -4px; right: -4px; top: 50%; height: 1px; background: #8696a8; }
.cp-rci-fill { position: absolute; left: 1px; right: 1px; bottom: 50%; height: 0; border-radius: 2px 2px 0 0; transition: height .4s; }
.cp-rci-fill.neg { bottom: auto; top: 50%; border-radius: 0 0 2px 2px; opacity: .65; }
.cp-rci-fill.capped { outline: 2px dashed var(--cp-bad); }
.cp-rci-r { background: var(--cp-r); }
.cp-rci-c { background: var(--cp-c); }
.cp-rci-i { background: var(--cp-i); }
.cp-rci-lbl { font-weight: 800; font-size: 12px; }
.cp-power { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--cp-muted); }
.cp-bar { display: inline-block; vertical-align: middle; width: 70px; height: 7px; background: #141c26; border-radius: 4px; overflow: hidden; margin-left: 6px; }
.cp-power .cp-bar { width: 100%; margin: 0; }
.cp-bar i { display: block; height: 100%; }
.cp-overlays { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
#game.cp-game .cp-ov { font-size: 12px; padding: 4px 5px; font-weight: 700; text-align: left; }
#game.cp-game .cp-ov[aria-pressed="true"],
#game.cp-game .cp-ov[aria-pressed="true"]:hover:not(:disabled) { background: var(--cp-accent); color: var(--cp-accent-ink); border-color: #c9a92e; }
#game.cp-game .cp-speed button[aria-pressed="true"]:hover:not(:disabled) { background: #ffdc5c; color: var(--cp-accent-ink); }
.cp-legend { margin-top: 6px; font-size: 12px; min-height: 22px; }
.cp-ramp { height: 10px; border-radius: 5px; border: 1px solid var(--cp-line); }
.cp-ramp-lbl { display: flex; justify-content: space-between; color: var(--cp-muted); margin-top: 2px; }
.cp-sw { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; }
.cp-sw i { width: 11px; height: 11px; border-radius: 2px; display: inline-block; border: 1px solid #000; }
.cp-info { font-size: 13px; }
.cp-info p { margin: 0 0 6px; }
.cp-kv { width: 100%; border-collapse: collapse; }
.cp-kv th { text-align: left; font-weight: 700; color: var(--cp-muted); padding: 2px 4px 2px 0; white-space: nowrap; font-size: 12px; }
.cp-kv td { padding: 2px 0; font-size: 12px; }
.cp-kv .cp-bar { width: 50px; }
.cp-muted { color: var(--cp-muted); }

/* ---------------- Ticker ---------------- */
.cp-ticker {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px;
  background: #0f1620;
  border-top: 2px solid #0c121a;
  min-height: 36px;
}
.cp-ticker-badge { background: var(--cp-bad); color: #1a0f0d; font-weight: 800; font-size: 11px; letter-spacing: .08em; padding: 2px 6px; border-radius: 4px; }
#game.cp-game .cp-ticker-text {
  flex: 1; min-width: 0; text-align: left; background: transparent; border: none; padding: 3px 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700;
}
#game.cp-game .cp-ticker-text.lvl-good { color: var(--cp-good); }
#game.cp-game .cp-ticker-text.lvl-warn { color: var(--cp-warn); }
#game.cp-game .cp-ticker-text.lvl-alert { color: var(--cp-bad); }
#game.cp-game .cp-ticker-text.flash { animation: cp-flash .9s ease-out; }
@keyframes cp-flash { from { background: rgba(242, 207, 74, .28); } to { background: transparent; } }
#game.cp-game .cp-log-btn { font-size: 12px; padding: 3px 9px; }

/* ---------------- Tooltip ---------------- */
.cp-tip {
  position: absolute; z-index: 20; width: 240px;
  background: #0f161f; border: 1px solid var(--cp-accent); border-radius: 8px;
  padding: 8px 10px; pointer-events: none; box-shadow: 0 8px 20px rgba(0, 0, 0, .5);
  font-size: 13px;
}
.cp-tip[hidden] { display: none; }
.cp-tip-h { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 3px; }
.cp-tip-h span { color: var(--cp-accent); font-weight: 800; }
.cp-tip-d { color: #d5dee8; }
.cp-tip-lock { color: var(--cp-bad); font-weight: 700; margin-top: 4px; }
.cp-tip-k { color: var(--cp-muted); font-size: 12px; margin-top: 4px; }

/* ---------------- Dialogs ---------------- */
#game.cp-game dialog.cp-dlg {
  color: var(--cp-text);
  background: var(--cp-panel);
  border: 2px solid var(--cp-line);
  border-radius: 12px;
  padding: 0;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  user-select: text;
  -webkit-user-select: text;
}
#game.cp-game dialog.cp-dlg-wide { width: min(680px, calc(100vw - 24px)); }
#game.cp-game dialog.cp-dlg::backdrop { background: rgba(5, 10, 18, .6); }
.cp-form { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.cp-form h2 { margin: 0; font-family: Fredoka, Nunito, sans-serif; font-size: 22px; color: var(--cp-accent); }
.cp-form h3 { margin: 6px 0 0; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--cp-muted); }
.cp-form label { display: flex; flex-direction: column; gap: 3px; font-weight: 700; font-size: 13px; }
.cp-form input[type="text"], .cp-form select {
  font: inherit; color: var(--cp-text); background: #121a24;
  border: 1px solid var(--cp-line); border-radius: 7px; padding: 6px 8px;
}
.cp-row { display: flex; gap: 6px; }
.cp-row input { flex: 1; min-width: 0; }
.cp-new-grid { display: grid; grid-template-columns: 1fr 240px; gap: 14px; align-items: start; }
.cp-new-grid > div:first-child { display: flex; flex-direction: column; gap: 10px; }
.cp-thumb { width: 240px; height: 200px; image-rendering: pixelated; border-radius: 8px; border: 1px solid var(--cp-line); }
.cp-dlg-btns { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 4px; align-items: center; }
.cp-grow { flex: 1; }
.cp-file-btn { position: relative; display: inline-flex !important; flex-direction: row !important; align-items: center; background: var(--cp-panel-2); border: 1px solid var(--cp-line); border-radius: 7px; padding: 5px 10px; cursor: pointer; font-weight: 400 !important; font-size: 14px !important; }
.cp-file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cp-file-btn:focus-within { outline: 3px solid var(--cp-focus); outline-offset: 2px; }
.cp-slots { display: flex; flex-direction: column; gap: 6px; }
.cp-slot { display: grid; grid-template-columns: 76px 1fr auto; gap: 8px; align-items: center; background: var(--cp-panel-2); border: 1px solid var(--cp-line); border-radius: 8px; padding: 7px 9px; }
.cp-slot-name { font-weight: 800; }
.cp-slot-info { font-size: 13px; }
.cp-slot-btns { display: flex; gap: 5px; }
.cp-slider { display: grid !important; grid-template-columns: 1fr auto; grid-template-rows: auto auto; }
.cp-slider output { font-weight: 800; color: var(--cp-accent); }
.cp-slider input { grid-column: 1 / -1; accent-color: var(--cp-accent); width: 100%; }
.cp-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.cp-table th, .cp-table td { padding: 4px 6px; border-bottom: 1px solid var(--cp-line); text-align: right; }
.cp-table th[scope="row"], .cp-table tbody th, .cp-table tr > th:first-child { text-align: left; }
.cp-table thead th { color: var(--cp-muted); font-size: 12px; }
.cp-table tr.net td, .cp-table tr.net th { font-weight: 800; }
.cp-table tfoot td { font-weight: 800; }
.cp-keys th { width: 42%; }
.cp-keys td { text-align: left; }
.cp-check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 600 !important; }
.cp-check input { width: 18px; height: 18px; accent-color: var(--cp-accent); }
.cp-dis-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.cp-help-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 5px; }
.cp-log { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.cp-log li { padding: 5px 8px; background: var(--cp-panel-2); border-radius: 6px; border-left: 4px solid var(--cp-line); font-size: 13px; }
.cp-log li.lvl-good { border-left-color: var(--cp-good); }
.cp-log li.lvl-warn { border-left-color: var(--cp-warn); }
.cp-log li.lvl-alert { border-left-color: var(--cp-bad); }
.cp-log-date { color: var(--cp-muted); font-weight: 700; }
#game.cp-game .cp-log button { padding: 1px 7px; font-size: 12px; margin-left: 4px; }
.cp-eval-top { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cp-eval-top > div { background: var(--cp-panel-2); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; }
.cp-eval-top b { font-size: 20px; font-family: Fredoka, Nunito, sans-serif; color: var(--cp-accent); }
.cp-probs { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.cp-probs li { display: grid; grid-template-columns: 1fr 110px 44px; align-items: center; gap: 6px; }
.cp-probs .cp-bar { width: 100%; margin: 0; }
.cp-probs b { text-align: right; }

/* ---------------- Responsive ---------------- */
@media (max-width: 1100px) {
  .cp-main { grid-template-columns: auto 1fr 200px; }
}
@media (max-width: 760px) {
  #game.cp-game { height: clamp(520px, 86vh, 900px); border-radius: 8px; }
  .cp-main { grid-template-columns: auto 1fr; position: relative; }
  .cp-side {
    position: absolute; right: 0; top: 0; bottom: 0; width: min(250px, 80%); z-index: 6;
    transform: translateX(105%); transition: transform .2s ease;
    box-shadow: -8px 0 20px rgba(0, 0, 0, .4);
  }
  .cp-app.side-open .cp-side { transform: none; }
  #game.cp-game .cp-side-toggle { display: inline-block; }
  .cp-tgrid { grid-template-columns: repeat(2, 34px); }
  #game.cp-game .cp-tool { width: 34px; height: 34px; padding: 4px; }
  .cp-tgroup-label { font-size: 9px; }
  .cp-stats { gap: 10px; }
  .cp-name { font-size: 16px; max-width: 140px; }
  #game.cp-game .cp-menu button { padding: 4px 7px; font-size: 12px; }
  .cp-new-grid { grid-template-columns: 1fr; }
  .cp-thumb { width: 100%; height: auto; aspect-ratio: 120 / 100; }
  .cp-tip { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #game.cp-game *, #game.cp-game *::before, #game.cp-game *::after { animation: none !important; transition: none !important; }
}
