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

:root {
  --bg: #071119;
  --panel: rgba(13, 24, 34, 0.9);
  --panel-solid: #111e2b;
  --border: rgba(163, 184, 201, 0.22);
  --text: #eef6fb;
  --muted: #94aab9;
  --green: #2ecc71;
  --red: #e74c3c;
  --yellow: #f1c40f;
  --blue: #4aa3df;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

.game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #071119;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
}

.hud {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 10;
  width: min(1080px, calc(100vw - 32px));
  height: 244px;
  padding: 12px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(220px, 0.7fr);
  gap: 12px;
  border: 1px solid rgba(44, 25, 13, 0.85);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.08), transparent 18%, rgba(0,0,0,0.12) 52%, rgba(255,255,255,0.05)),
    repeating-linear-gradient(0deg, #7b5432 0 13px, #704a2b 13px 27px);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55), inset 0 2px rgba(255,255,255,0.16);
}

.desk-service-area,
.desk-ledger-strip {
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 6px;
  background: rgba(18, 24, 29, 0.72);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
  padding: 12px;
}

.desk-service-area {
  background:
    linear-gradient(135deg, rgba(244, 229, 190, 0.18), rgba(244, 229, 190, 0.05)),
    rgba(18, 24, 29, 0.68);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.desk-header,
.hud-capital {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.hud-title {
  font-size: 15px;
  font-weight: 800;
  color: #f6d58c;
  text-shadow: 0 1px rgba(0,0,0,0.45);
}

.hud-date,
.panel-kicker,
.hud-grid span,
.hud-capital span,
.hud-standing span {
  font-size: 10px;
  line-height: 1.2;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.icon-btn,
.tool-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.icon-btn:hover,
.tool-btn:hover,
.slot-btn:hover,
.btn:hover { filter: brightness(1.08); }

#dayTime {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hud-timer,
.rep-track {
  height: 6px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
}

.hud-timer-fill,
.rep-fill {
  width: 100%;
  height: 100%;
  background: var(--blue);
}

.desk-ledger-strip {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.desk-ledger-strip > div,
.desk-meter {
  background: rgba(4, 10, 14, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 8px 10px;
}

.desk-ledger-strip > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.desk-ledger-strip .desk-meter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
}

.desk-meter .hud-timer,
.desk-meter .rep-track {
  grid-column: 1 / -1;
}

.desk-ledger-strip strong,
.desk-meter strong {
  display: block;
  margin-top: 0;
  font-size: 15px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.mode-banner,
.interaction-prompt {
  position: absolute;
  left: 50%;
  z-index: 8;
  transform: translateX(-50%);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(11, 22, 31, 0.86);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  padding: 9px 14px;
  pointer-events: none;
}

.mode-banner { top: 16px; }
.interaction-prompt { bottom: 120px; display: none; }
.interaction-prompt.show { display: block; }

.build-panel,
.ledger-panel {
  position: absolute;
  z-index: 12;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.build-panel {
  left: 16px;
  bottom: 176px;
  width: min(720px, calc(100vw - 32px));
  padding: 12px;
  display: none;
}

.build-panel.show { display: block; }

.build-head,
.build-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.build-tools { margin-top: 10px; justify-content: flex-start; }
.tool-btn.active { border-color: var(--yellow); color: var(--yellow); }
.icon-btn.active { border-color: var(--blue); color: var(--blue); }

.shop-scroll {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.shop-item {
  flex: 0 0 104px;
  min-height: 132px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  padding: 9px 8px;
  text-align: center;
  cursor: pointer;
}

.shop-item.selected { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(74, 163, 223, 0.3); }
.shop-item.unaffordable { opacity: 0.45; }
.shop-item.owned { border-color: rgba(46, 204, 113, 0.7); }
.shop-item-art { width: 48px; height: 48px; object-fit: contain; image-rendering: pixelated; display: block; margin: 0 auto 6px; }
.shop-item-icon { font-size: 26px; line-height: 1; margin-bottom: 5px; }
.shop-item-name { min-height: 28px; font-size: 11px; font-weight: 800; line-height: 1.2; }
.shop-item-cost { margin-top: 4px; color: var(--yellow); font-size: 11px; font-weight: 800; }
.shop-item-size, .shop-item-owned { margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 700; }
.shop-item-owned { color: var(--green); }

.ledger-panel {
  left: 50%;
  bottom: 176px;
  width: min(760px, calc(100vw - 32px));
  max-height: 28vh;
  padding: 12px;
  overflow: hidden;
  transform: translate(-50%, calc(100% + 28px));
  opacity: 0;
  pointer-events: none;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.ledger-panel.show {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}

.ledger-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  max-height: 20vh;
  overflow: auto;
}

.log-item {
  border-left: 3px solid var(--blue);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.log-item .day-tag { margin-bottom: 2px; color: var(--muted); font-size: 10px; }
.log-item.good { border-left-color: var(--green); }
.log-item.bad { border-left-color: var(--red); }
.log-item.warn { border-left-color: var(--yellow); }
.log-item.neutral { border-left-color: var(--blue); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.54);
}

.overlay.show { display: flex; }

.overlay-box {
  width: min(440px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

.desk-event-layer {
  display: block;
  flex: 1;
  min-height: 0;
  margin-top: 10px;
  visibility: hidden;
  pointer-events: none;
}

.desk-event-layer.show {
  visibility: visible;
  pointer-events: auto;
}

.decision-card {
  height: 100%;
  overflow: auto;
  border: 1px solid rgba(52, 35, 20, 0.7);
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.16), transparent 48%),
    #ead9b6;
  box-shadow: 0 8px 0 rgba(0,0,0,0.16);
  color: #26170d;
  text-align: left;
}

.event-head { display: flex; align-items: center; gap: 9px; padding: 7px 12px; border-bottom: 1px solid rgba(38, 23, 13, 0.22); }
.event-icon { font-size: 22px; line-height: 1; }
.event-meta .type { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.decision-card .event-meta .type,
.decision-card .detail-row .key,
.decision-card .eod-row .key { color: #795c3d; }
.event-meta { min-width: 0; }
.event-meta .title { margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 900; }
.event-body {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 7px 12px 0;
}
.event-body.eod-body {
  display: block;
  padding: 4px 0;
}
.detail-row { display: block; min-width: 0; padding: 5px 8px; border: 1px solid rgba(38, 23, 13, 0.16); border-radius: 4px; background: rgba(255,255,255,0.28); font-size: 11px; }
.eod-row { display: flex; justify-content: space-between; gap: 16px; padding: 8px 14px; border-bottom: 1px solid rgba(38, 23, 13, 0.16); font-size: 14px; }
.detail-row .key, .eod-row .key { color: var(--muted); }
.detail-row .val { display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 900; text-align: left; }
.eod-row span:last-child { font-weight: 800; text-align: right; }
.green { color: var(--green); }
.red { color: var(--red); }
.yellow { color: var(--yellow); }
.blue { color: var(--blue); }

.btn-row { display: grid; gap: 8px; padding: 8px 12px 10px; }
.btn-row.two-col { grid-template-columns: 1fr 1fr; }
.btn-row.three-col { grid-template-columns: 0.9fr 1fr 1fr; }
.btn-row.one-col { grid-template-columns: 1fr; }
.btn {
  border: 0;
  border-radius: 6px;
  padding: 9px 8px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}
.btn:disabled { opacity: 0.35; pointer-events: none; }
.btn-green,
.btn-dark {
  border: 2px double currentColor;
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.12), rgba(255,255,255,0)),
    rgba(248, 236, 203, 0.08);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transform: rotate(-1.5deg);
  box-shadow: 0 3px 0 rgba(0,0,0,0.22);
}
.btn-row.two-col .btn-green { transform: rotate(1.5deg); }
.btn-green { color: var(--green); }
.btn-dark { color: var(--red); }
.btn-blue { background: var(--blue); color: #06131d; }
.btn-purple { background: linear-gradient(135deg, #9b59b6, var(--blue)); color: #fff; }
.btn-small { padding: 8px 7px; font-size: 11px; }
.cant-fund { margin: 5px 12px 0; padding: 5px 8px; border-radius: 6px; background: rgba(231, 76, 60, 0.15); color: var(--red); font-size: 11px; font-weight: 800; }

.dots { display: none; justify-content: center; gap: 7px; padding: 0 0 12px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(38, 23, 13, 0.2); }
.dot.done { background: var(--green); }
.dot.current { background: var(--blue); }

.overlay-box { padding: 24px; text-align: center; }
.event-info-box { max-width: 460px; padding: 0; text-align: left; }
.event-info-body { padding: 14px 18px 18px; }
.event-info-body p { color: var(--muted); font-size: 14px; line-height: 1.45; }
.event-info-list { margin-top: 12px; display: grid; gap: 8px; }
.event-info-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 5px; background: rgba(255,255,255,0.05); font-size: 13px; }
.event-info-row span:first-child { color: var(--muted); }
.event-info-row span:last-child { font-weight: 800; text-align: right; }
.menu-box { max-width: 380px; padding: 0; text-align: left; }
.menu-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.menu-title, .overlay-title { font-size: 22px; font-weight: 900; }
.menu-close-btn { border: 0; background: transparent; color: var(--muted); font-size: 22px; cursor: pointer; }
.menu-section-label { padding: 14px 18px 8px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.menu-divider { height: 1px; background: var(--border); margin-top: 4px; }
.menu-full-btn { width: calc(100% - 36px); margin: 12px 18px 18px; }
.slot-card { margin: 0 12px 8px; padding: 12px; border: 1px solid var(--border); border-radius: 6px; background: rgba(255,255,255,0.05); }
.slot-card-top, .slot-btns { display: flex; justify-content: space-between; gap: 8px; }
.slot-name, .slot-saved-at { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.slot-info { margin: 8px 0; font-size: 13px; }
.slot-info.empty { color: var(--muted); font-style: italic; }
.slot-btn { flex: 1; border: 0; border-radius: 5px; padding: 8px 6px; font-size: 12px; font-weight: 900; cursor: pointer; }
.slot-btn-save { background: var(--blue); color: #06131d; }
.slot-btn-load { background: var(--green); color: #05110a; }
.slot-btn-delete { background: rgba(255,255,255,0.1); color: var(--red); }
.restart-confirm { margin: 0 18px 18px; padding: 14px; border: 1px solid rgba(231, 76, 60, 0.35); border-radius: 6px; background: rgba(231, 76, 60, 0.12); text-align: center; }
.restart-confirm p { margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.restart-confirm-btns { display: flex; gap: 8px; }
.restart-confirm-btns .btn { flex: 1; }
.overlay-icon { font-size: 54px; margin-bottom: 10px; }
.overlay-title.win { color: var(--green); }
.overlay-title.lose { color: var(--red); }
.overlay-body { margin: 10px 0 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.overlay-stat { margin: 5px 0; color: var(--muted); font-size: 13px; }
.overlay-stat strong { color: var(--text); }

.touch-controls {
  position: absolute;
  z-index: 11;
  left: 16px;
  right: 16px;
  bottom: 176px;
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

.touch-dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 4px;
}

.touch-dpad button,
.touch-actions button {
  pointer-events: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(13, 24, 34, 0.82);
  font-size: 13px;
  font-weight: 900;
}

.touch-dpad [data-touch="up"] { grid-column: 2; grid-row: 1; }
.touch-dpad [data-touch="left"] { grid-column: 1; grid-row: 2; }
.touch-dpad [data-touch="down"] { grid-column: 2; grid-row: 3; }
.touch-dpad [data-touch="right"] { grid-column: 3; grid-row: 2; }
.touch-actions { display: flex; flex-direction: column; gap: 8px; align-self: end; }
.touch-actions button { width: 82px; height: 48px; }

@media (max-width: 760px) {
  .hud {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    height: 360px;
    transform: none;
    grid-template-columns: 1fr;
    padding: 10px;
  }
  .desk-ledger-strip strong, .desk-meter strong { font-size: 14px; }
  .event-body { grid-template-columns: 1fr; }
  .ledger-panel {
    left: 10px;
    right: 10px;
    bottom: 276px;
    width: auto;
    transform: translateY(calc(100% + 28px));
  }
  .ledger-panel.show { transform: translateY(0); }
  .build-panel { left: 10px; right: 10px; bottom: 276px; width: auto; }
  .touch-controls { display: flex; }
  .mode-banner { top: 10px; bottom: auto; max-width: calc(100vw - 28px); text-align: center; }
  .interaction-prompt { bottom: 312px; }
}
