/* CityRT Authentic Stylesheet & Design Tokens */

:root {
  /* Exact CityRT Production Color Tokens */
  --sk-paper: #faf9f5;
  --sk-paper2: #f3ede0;
  --sk-oat: #e3dacc;
  --sk-manilla: #ebdbbc;
  --sk-ink: #2a2320;
  --sk-ink2: #4a403a;
  --sk-mute: #85796d;
  --sk-clay: #d97757;
  --sk-clay-d: #b35a3c;
  --sk-clay-l: #f4d6c8;
  --sk-kraft: #d4a27f;
  --sk-olive: #788c5d;
  --sk-good: #4f7f34;
  --sk-bad: #b5443a;
  --sk-sky: #6a9bcc;

  /* Fonts */
  --sk-ui: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --sk-hand: "Pangolin", "Segoe Print", cursive;
  --sk-spring: cubic-bezier(.3, 1.55, .5, 1);

  --r-color: #4CAF50;
  --c-color: #2196F3;
  --i-color: #FF9800;

  --shadow-sm: 0 2px 8px rgba(42, 35, 32, 0.06);
  --shadow-md: 0 4px 18px rgba(42, 35, 32, 0.1);
  --shadow-lg: 0 10px 32px rgba(42, 35, 32, 0.18);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 9999px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--sk-paper2);
  color: var(--sk-ink);
  font-family: var(--sk-ui);
  font-size: 14px;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

/* UI Layers */
.ui-layer {
  position: absolute;
  z-index: 10;
  pointer-events: none;
}

.ui-layer > * {
  pointer-events: auto;
}

/* ==========================================================================
   TOP HUD BAR
   ========================================================================== */
#hud-container {
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: center;
}

.hud-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--sk-paper);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--sk-oat);
  box-shadow: var(--shadow-md);
  max-width: 1200px;
  width: 100%;
}

.hud-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* City Identity */
.city-section {
  padding-right: 12px;
  border-right: 1px solid var(--sk-oat);
  cursor: pointer;
}

.city-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--sk-ink);
  white-space: nowrap;
}

.city-name:hover {
  text-decoration: underline;
}

/* Vital Statistics */
.stats-section {
  display: flex;
  gap: 10px;
  flex: 1;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.65);
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--sk-oat);
  font-size: 13px;
  font-weight: 600;
}

.stat-sub {
  font-size: 11px;
  font-weight: 500;
  margin-left: 2px;
}

.stat-sub.positive {
  color: var(--sk-good);
}

.stat-sub.negative {
  color: var(--sk-bad);
}

/* RCI Demand Meter */
.rci-section {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-sm);
  border: 1px solid var(--sk-oat);
}

.rci-bar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.rci-label {
  font-size: 9px;
  font-weight: 700;
}

.rci-label.r { color: var(--r-color); }
.rci-label.c { color: var(--c-color); }
.rci-label.i { color: var(--i-color); }

.rci-track {
  width: 7px;
  height: 24px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.rci-fill {
  width: 100%;
  border-radius: 4px;
  transition: height 0.4s ease;
}

.rci-fill.r { background: var(--r-color); }
.rci-fill.c { background: var(--c-color); }
.rci-fill.i { background: var(--i-color); }

/* Speed Controls */
.speed-section {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-left: 1px solid var(--sk-oat);
  border-right: 1px solid var(--sk-oat);
}

.stat-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--sk-mute);
  white-space: nowrap;
}

.speed-buttons {
  display: flex;
  gap: 3px;
}

.btn-speed {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sk-oat);
  background: white;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-speed:hover {
  background: var(--sk-oat);
}

.btn-speed.active {
  background: var(--sk-ink);
  color: white;
  border-color: var(--sk-ink);
}

/* Actions Section */
.actions-section {
  display: flex;
  gap: 6px;
}

.btn-hud {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--sk-oat);
  background: white;
  font-size: 12px;
  font-weight: 600;
  color: var(--sk-ink);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-hud:hover {
  background: var(--sk-oat);
}

.btn-hud.btn-accent {
  background: var(--sk-clay);
  color: white;
  border-color: var(--sk-clay);
}

.btn-hud.btn-accent:hover {
  background: var(--sk-clay-d);
}

.btn-hud-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--sk-oat);
  background: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   LEFT TOOLBAR (Construction & Tools Panel)
   ========================================================================== */
#toolbar-container {
  top: 76px;
  left: 12px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
}

.toolbar-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--sk-paper);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 12px 10px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--sk-oat);
  box-shadow: var(--shadow-md);
  overflow-y: auto;
  max-height: calc(100vh - 100px);
  scrollbar-width: thin;
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tool-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--sk-mute);
  padding: 2px 6px;
  letter-spacing: 0.5px;
}

.btn-tool {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--sk-ink);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  text-align: left;
}

.btn-tool:hover {
  background: rgba(255, 255, 255, 0.7);
  border-color: var(--sk-oat);
}

.btn-tool.active {
  background: white;
  border-color: var(--sk-ink);
  box-shadow: var(--shadow-sm);
}

.tool-icon {
  font-size: 15px;
}

.tool-label {
  flex: 1;
  white-space: nowrap;
}

.tool-cost {
  font-size: 10px;
  color: var(--sk-mute);
  font-weight: 500;
}

.tool-key {
  font-size: 9px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--sk-mute);
}

.btn-tool.btn-danger.active {
  background: #FFEBEE;
  border-color: var(--sk-bad);
  color: var(--sk-bad);
}

/* Zone buttons color indicators */
.btn-zone-r.active { background: #E8F5E9; border-color: var(--r-color); }
.btn-zone-c.active { background: #E3F2FD; border-color: var(--c-color); }
.btn-zone-i.active { background: #FFF3E0; border-color: var(--i-color); }

/* ==========================================================================
   CATALOG BROWSER MODAL (824 buildings + 12 styles)
   ========================================================================== */
.catalog-modal-card {
  background: var(--sk-paper);
  width: 95%;
  max-width: 1050px;
  max-height: 88vh;
  border-radius: var(--radius-lg);
  border: 1px solid var(--sk-oat);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: modalPop 0.2s var(--sk-spring);
  overflow: hidden;
}

.catalog-header {
  padding: 18px 24px 12px;
  border-bottom: 1px solid var(--sk-oat);
  background: white;
}

.cat-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.cat-modal-title {
  font-size: 18px;
  font-weight: 700;
}

.active-style-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.cat-subtitle {
  font-size: 12px;
  color: var(--sk-mute);
  margin-top: 4px;
}

/* Style Selector Bar */
.style-selector-bar {
  padding: 10px 24px;
  background: var(--sk-paper2);
  border-bottom: 1px solid var(--sk-oat);
  display: flex;
  align-items: center;
  gap: 12px;
}

.style-bar-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--sk-ink);
  white-space: nowrap;
}

.style-pills-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}

.btn-style-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: white;
  border: 1px solid var(--sk-oat);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.btn-style-pill:hover {
  background: var(--sk-paper);
}

.btn-style-pill.active {
  background: var(--sk-ink);
  color: white;
  border-color: var(--sk-ink);
}

.style-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

/* Category Filter Bar */
.cat-filter-bar {
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--sk-oat);
  background: white;
}

.cat-tabs-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.btn-cat-tab {
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--sk-mute);
  cursor: pointer;
  white-space: nowrap;
}

.btn-cat-tab:hover {
  color: var(--sk-ink);
  background: var(--sk-paper2);
}

.btn-cat-tab.active {
  background: var(--sk-paper2);
  color: var(--sk-ink);
  border-color: var(--sk-oat);
}

.cat-search-box {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--sk-oat);
  font-size: 12px;
  width: 200px;
  outline: none;
}

.cat-search-box:focus {
  border-color: var(--sk-clay);
}

/* Building Grid */
.catalog-grid {
  padding: 20px 24px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  flex: 1;
  background: var(--sk-paper2);
}

.catalog-card {
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--sk-oat);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.catalog-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-thumb-box {
  position: relative;
  width: 100%;
  height: 100px;
  background: var(--sk-paper);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.card-style-tag {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 9px;
  font-weight: 700;
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
}

.card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.card-desc {
  font-size: 11px;
  color: var(--sk-mute);
  line-height: 1.3;
}

.btn-card-select {
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--sk-oat);
  background: var(--sk-paper2);
  color: var(--sk-ink);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-card-select:hover {
  background: var(--sk-clay);
  color: white;
  border-color: var(--sk-clay);
}

.catalog-footer {
  padding: 12px 24px;
  background: white;
  border-top: 1px solid var(--sk-oat);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.catalog-count-label {
  font-size: 12px;
  color: var(--sk-mute);
}

/* ==========================================================================
   INSPECTOR CARD (Bottom-Right)
   ========================================================================== */
#inspector-container {
  bottom: 20px;
  right: 20px;
  width: 310px;
}

.inspector-card {
  background: var(--sk-paper);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--sk-oat);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inspect-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inspect-icon {
  font-size: 24px;
}

.inspect-title-box {
  flex: 1;
}

.inspect-title {
  font-size: 14px;
  font-weight: 700;
}

.inspect-subtitle {
  font-size: 11px;
  color: var(--sk-mute);
}

.btn-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--sk-mute);
}

.inspect-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inspect-coord {
  font-size: 11px;
  color: var(--sk-mute);
}

.inspect-stat {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
}

.inspect-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.badge.ok { background: #E8F5E9; color: var(--sk-good); }
.badge.warn { background: #FFF3E0; color: #E65100; }
.badge.off { background: #FFEBEE; color: var(--sk-bad); }

.inspect-meters {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.meter-bar {
  flex: 1;
  height: 6px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.meter-bar .fill {
  height: 100%;
}

.meter-bar .fill.green { background: var(--sk-good); }
.meter-bar .fill.orange { background: var(--sk-clay); }

.inspect-services {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.services-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--sk-mute);
  opacity: 0.5;
}

.chip.active {
  background: white;
  color: var(--sk-ink);
  font-weight: 600;
  opacity: 1;
  border: 1px solid var(--sk-oat);
}

.btn-demolish {
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid #FFCDD2;
  background: #FFEBEE;
  color: var(--sk-bad);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}

.btn-demolish:hover {
  background: #FFCDD2;
}

/* ==========================================================================
   NOTIFICATION TOAST
   ========================================================================== */
.ui-toast {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--sk-ink);
  color: white;
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s var(--sk-spring);
  z-index: 100;
}

.ui-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   MODALS LAYER (Financial Ledger & Share)
   ========================================================================== */
.ui-modal-layer {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal-backdrop {
  width: 100%;
  height: 100%;
  background: rgba(42, 35, 32, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--sk-paper);
  width: 100%;
  max-width: 580px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--sk-oat);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modalPop 0.2s var(--sk-spring);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--sk-mute);
}

.tax-control-box {
  background: rgba(0, 0, 0, 0.03);
  padding: 14px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tax-header {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.tax-val {
  color: var(--sk-sky);
  font-size: 16px;
}

.slider {
  width: 100%;
  accent-color: var(--sk-clay);
  cursor: pointer;
}

.tax-hint {
  font-size: 11px;
  color: var(--sk-mute);
}

.ledger-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}

.ledger-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
}

.col-title {
  font-size: 13px;
  font-weight: 700;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--sk-oat);
}

.ledger-item {
  display: flex;
  justify-content: space-between;
  color: var(--sk-mute);
}

.ledger-item .amount {
  font-weight: 600;
  color: var(--sk-ink);
}

.ledger-total {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--sk-oat);
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.ledger-total .amount.green { color: var(--sk-good); }
.ledger-total .amount.red { color: var(--sk-bad); }

.net-summary-banner {
  margin-top: 10px;
  padding: 12px;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 14px;
}

.net-summary-banner.positive {
  background: #E8F5E9;
  color: #1B5E20;
}

.net-summary-banner.negative {
  background: #FFEBEE;
  color: #B71C1C;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-primary {
  padding: 8px 20px;
  border-radius: var(--radius-pill);
  background: var(--sk-ink);
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary:hover {
  background: var(--sk-ink2);
}

/* Share Modal */
.share-desc {
  font-size: 13px;
  color: var(--sk-mute);
  line-height: 1.5;
}

.share-input-box {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.share-input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--sk-oat);
  background: white;
  font-size: 12px;
  color: var(--sk-ink);
}

.btn-copy {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--sk-clay);
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.btn-copy:hover {
  background: var(--sk-clay-d);
}

.copy-confirm {
  font-size: 12px;
  font-weight: 600;
  color: var(--sk-good);
  margin-bottom: 8px;
}

.backup-actions {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--sk-oat);
}

.backup-actions h4 {
  font-size: 12px;
  margin-bottom: 8px;
  color: var(--sk-mute);
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-sub {
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--sk-oat);
  background: white;
  font-size: 12px;
  cursor: pointer;
}

.btn-file {
  display: inline-block;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .hud-bar {
    padding: 6px 10px;
    gap: 8px;
  }
  .city-section { display: none; }
  .rci-section { display: none; }
  .actions-section #btn-hud-ledger { display: none; }
  #toolbar-container {
    top: auto;
    bottom: 12px;
    left: 12px;
    right: 12px;
  }
  .toolbar-panel {
    flex-direction: row;
    max-height: none;
    overflow-x: auto;
    width: 100%;
  }
  .tool-group {
    flex-direction: row;
  }
}
