* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    sans-serif;
  background: repeating-linear-gradient(
    45deg,
    #15181c 0 12px,
    #1a1e23 12px 24px
  );
  color: #e8e8e8;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 20px;
  background: linear-gradient(180deg, #2a2f38 0%, #22262d 100%);
  border-bottom: 3px solid #ffd86b;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

#topbar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ffd86b;
  text-shadow: 0 1px 0 #000;
}

#stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

#stats .stat {
  color: #cfd6e0;
  white-space: nowrap;
}

#money {
  font-size: 20px;
  font-weight: 800;
  color: #ffd86b;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition:
    transform 0.15s,
    color 0.15s;
}

#money.gain {
  color: #78dc8c;
  transform: scale(1.18);
}

#money.loss {
  color: #e85a5a;
  transform: scale(1.18);
}

#game-area {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 14px 20px 20px;
  flex: 1;
}

#play-zone {
  position: relative;
  width: 100%;
  max-width: calc(74vh * 20 / 14);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#day-hud {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

#quota-bar {
  flex: 1;
  position: relative;
  height: 28px;
  background: #1e2228;
  border: 2px solid #3a414d;
  border-radius: 7px;
  overflow: hidden;
}

#quota-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #b8923f, #ffd86b);
  transition: width 0.25s ease-out;
}

#quota-bar.done {
  border-color: #78dc8c;
}

#quota-bar.done #quota-fill {
  background: linear-gradient(90deg, #3f9a55, #78dc8c);
}

#quota-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-shadow:
    0 1px 2px #000,
    0 0 4px rgba(0, 0, 0, 0.6);
}

#time-left {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #e8e8e8;
  padding: 0 12px;
  background: #1e2228;
  border: 2px solid #3a414d;
  border-radius: 7px;
  white-space: nowrap;
}

#time-left.urgent {
  color: #e85a5a;
  border-color: #e85a5a;
  animation: pulse 0.6s infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.06);
  }
}

#shop-panel {
  position: absolute;
  top: 46px;
  left: 10px;
  width: 250px;
  background: linear-gradient(
    180deg,
    rgba(42, 47, 56, 0.96) 0%,
    rgba(30, 34, 40, 0.96) 100%
  );
  border: 2px solid #ffd86b;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 50;
  animation: fade-in 0.15s ease-out;
}

#shop-panel.hidden {
  display: none;
}

.sp-title {
  font-size: 13px;
  font-weight: 700;
  color: #ffd86b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.sp-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 5px;
  font-size: 12.5px;
  cursor: pointer;
  border: 1px solid transparent;
}

.sp-item.buyable:hover {
  border-color: #ffd86b;
  background: rgba(255, 216, 107, 0.08);
}

.sp-item.owned {
  opacity: 0.5;
  cursor: default;
}

.sp-item.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.sp-key {
  width: 16px;
  height: 16px;
  border: 1px solid #565e6d;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9aa3b0;
  flex-shrink: 0;
}

.sp-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-price {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #9aa3b0;
}

.sp-item.buyable .sp-price {
  color: #78dc8c;
}

.sp-item.owned .sp-price {
  color: #78dc8c;
}

.sp-hint {
  margin-top: 8px;
  font-size: 10.5px;
  color: #9aa3b0;
  text-align: center;
}

#game {
  background: #3a3f48;
  border: 4px solid #1a1d22;
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 1px #565e6d,
    0 0 60px rgba(255, 216, 107, 0.06),
    0 12px 40px rgba(0, 0, 0, 0.55);
  width: 100%;
  height: auto;
  aspect-ratio: 20 / 14;
}

#hints {
  display: flex;
  gap: 24px;
  padding: 10px 20px;
  background: #2a2f38;
  border-top: 1px solid #3a414d;
  font-size: 12px;
  color: #9aa3b0;
  justify-content: center;
}

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
  animation: fade-in 0.2s ease-out;
}

#modal-overlay.hidden {
  display: none;
}

#modal-card {
  background: linear-gradient(180deg, #2a2f38 0%, #1e2228 100%);
  border: 3px solid #ffd86b;
  border-radius: 8px;
  padding: 28px 32px;
  max-width: 520px;
  min-width: 360px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
}

.modal-title {
  margin: 0 0 14px 0;
  font-size: 22px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ffd86b;
  text-shadow: 0 1px 0 #000;
}

.modal-body {
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 18px;
}

.modal-section {
  margin: 14px 0;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.25);
  border-left: 3px solid #ffd86b;
  border-radius: 0 4px 4px 0;
  font-size: 13px;
  line-height: 1.6;
}

.modal-section strong {
  color: #ffd86b;
  display: block;
  margin-bottom: 4px;
}

.modal-stats {
  margin: 14px 0;
}

.modal-stats .stat-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed #3a414d;
  padding: 4px 0;
}

.modal-stats .k {
  color: #9aa3b0;
}

.modal-stats .v {
  color: #e8e8e8;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
}

.modal-btn {
  background: linear-gradient(180deg, #2e343d 0%, #232830 100%);
  border: 2px solid #3a414d;
  border-radius: 6px;
  color: #e8e8e8;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition:
    border-color 0.1s,
    transform 0.05s;
}

.modal-btn:hover {
  border-color: #7ba8e8;
}

.modal-btn:active {
  transform: translateY(1px);
}

.modal-btn.primary {
  background: linear-gradient(180deg, #5a8fd0 0%, #3a5c8a 100%);
  border-color: #ffd86b;
  color: #fff;
}

/* candidate cards in the recruitment popup */
.shop-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 8px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid #3a414d;
  border-radius: 6px;
  padding: 7px 10px;
}

.shop-item.owned {
  opacity: 0.7;
  border-color: #4a6e52;
}

.shop-item .icon {
  font-size: 22px;
}

.shop-item .info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.shop-item .name {
  font-weight: 700;
  font-size: 13px;
  color: #e8e8e8;
}

.shop-item .desc {
  font-size: 11.5px;
  color: #9aa3b0;
}

.shop-item .owned-tag {
  font-size: 12px;
  font-weight: 700;
  color: #78dc8c;
  white-space: nowrap;
}

.modal-btn.buy {
  padding: 6px 14px;
  font-size: 13px;
  border-color: #ffd86b;
  color: #ffd86b;
  white-space: nowrap;
}

.modal-btn.buy:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: #3a414d;
  color: #9aa3b0;
}

#suspicion.hot {
  color: #e85a5a;
  font-weight: 700;
}

.orientation-choice {
  cursor: pointer;
  transition:
    border-color 0.1s,
    background 0.1s;
}

.orientation-choice:hover {
  border-left-color: #78dc8c;
  background: rgba(255, 216, 107, 0.08);
}

/* Moving-truck modal: radio rows for what to carry to the next garage */
.moving-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  padding: 8px 12px;
  cursor: pointer;
  transition:
    border-color 0.1s,
    background 0.1s;
}

.moving-choice strong {
  display: inline;
  margin-bottom: 0;
}

.moving-choice:hover {
  border-left-color: #78dc8c;
  background: rgba(255, 216, 107, 0.08);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* --- Dialogue toasts (portrait + text, top-right, screen-fixed) --- */

#toasts {
  position: fixed;
  top: 64px; /* below the topbar */
  right: 12px;
  z-index: 90; /* under modals (100), above touch controls (60) */
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
  max-width: min(320px, 78vw);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(
    180deg,
    rgba(42, 47, 56, 0.97),
    rgba(30, 34, 40, 0.97)
  );
  border: 2px solid #ffd86b;
  border-radius: 10px;
  padding: 8px 12px 8px 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  color: #e8e8e8;
  font-size: 13px;
  line-height: 1.35;
  opacity: 0;
  transform: translateX(20px);
  transition:
    opacity 0.25s ease-out,
    transform 0.25s ease-out;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast.hide {
  opacity: 0;
  transform: translateX(20px);
}

.toast .portrait {
  font-size: 26px;
  line-height: 1;
  flex-shrink: 0;
}

.toast .text {
  flex: 1;
}

@media (pointer: coarse), (max-width: 700px) {
  #toasts {
    top: 42px;
    right: 8px;
    max-width: 68vw;
  }

  .toast {
    font-size: 12px;
    padding: 6px 10px;
  }

  .toast .portrait {
    font-size: 22px;
  }
}

/* --- Touch controls (mobile) --- */

#touch-controls.hidden {
  display: none;
}

#touch-controls {
  /* Fixed to the screen, NOT to the (small, centered) board — so the joystick
     and buttons stay anchored to the viewport corners (and use the letterbox
     margins) regardless of the board size or any future camera panning. */
  position: fixed;
  inset: 0;
  pointer-events: none; /* only the joystick/buttons capture touches */
  z-index: 60;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#touch-controls .tc-stick,
#touch-controls .tc-btn {
  pointer-events: auto;
  touch-action: none;
}

.tc-stick {
  position: absolute;
  left: 3%;
  top: 50%;
  transform: translateY(
    -50%
  ); /* side-anchored: keeps the bottom (cars) clear */
  width: clamp(96px, 24vw, 150px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(30, 34, 40, 0.45);
  border: 2px solid rgba(255, 216, 107, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tc-knob {
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 216, 107, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.04s linear;
}

.tc-actions {
  position: absolute;
  right: 3%;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column; /* stacked on the right edge, narrow footprint */
  align-items: center;
  gap: 12px;
}

.tc-btn {
  width: clamp(56px, 14vw, 84px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255, 216, 107, 0.55);
  background: rgba(30, 34, 40, 0.55);
  color: #fff;
  font-size: clamp(22px, 6vw, 34px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.tc-btn-act {
  width: clamp(72px, 18vw, 104px);
  border-color: rgba(120, 220, 140, 0.7);
}

.tc-btn.tc-active {
  background: rgba(255, 216, 107, 0.35);
  transform: scale(0.94);
}

/* --- Landscape lock: "rotate your phone" banner (touch + portrait only) --- */

#rotate-overlay {
  display: none;
}

@media (pointer: coarse) and (orientation: portrait) {
  #rotate-overlay {
    position: fixed;
    inset: 0;
    z-index: 200; /* above modals and touch controls */
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e2228;
    color: #ffd86b;
    text-align: center;
    padding: 24px;
  }

  .rotate-icon {
    font-size: 56px;
    margin-bottom: 16px;
    animation: rotate-hint 1.8s ease-in-out infinite;
  }

  #rotate-overlay p {
    font-size: 18px;
    color: #e8e8e8;
    max-width: 320px;
    line-height: 1.5;
  }
}

@keyframes rotate-hint {
  0%,
  100% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(-90deg);
  }
}

/* --- Responsive / touch layout --- */

@media (pointer: coarse), (max-width: 700px) {
  /* Lock the page to the viewport: the board fits, nothing scrolls. */
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  #app {
    min-height: 0;
    height: 100svh;
  }

  #hints {
    display: none; /* keyboard shortcuts are irrelevant on touch */
  }

  /* Slim the chrome so the playfield keeps as much height as possible. */
  #topbar {
    gap: 4px 10px;
    padding: 5px 12px;
  }

  #topbar h1 {
    font-size: 14px;
  }

  #stats {
    gap: 3px 10px;
    font-size: 11px;
  }

  #money {
    font-size: 16px;
  }

  #game-area {
    padding: 6px 8px;
    justify-content: center;
    align-items: center; /* center the board in the leftover vertical space */
    min-height: 0;
  }

  /* Constrain the board by the available HEIGHT (short in landscape) instead
     of the full width, so the whole game fits without scrolling. The reserve
     covers the topbar + day HUD + paddings (even if the topbar wraps to 2 rows). */
  #play-zone {
    max-width: calc((100svh - 92px) * 20 / 14);
    gap: 6px;
  }

  #day-hud {
    gap: 8px;
  }

  #quota-bar {
    height: 22px;
  }

  #time-left {
    font-size: 15px;
    padding: 0 10px;
  }

  #modal-overlay {
    padding: 8px;
  }

  /* Cap the height to the viewport and scroll inside, so the title and the
     action buttons (start, hire, buy…) stay reachable on short landscape screens. */
  #modal-card {
    min-width: min(340px, 92vw);
    max-width: 92vw;
    max-height: 92svh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 18px;
  }

  .modal-title {
    font-size: 18px;
    margin-bottom: 10px;
  }

  .modal-body {
    font-size: 13px;
    margin-bottom: 12px;
  }

  .modal-section {
    margin: 10px 0;
  }

  #shop-panel {
    width: min(250px, 88vw);
    max-height: 78svh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-btn {
    padding: 14px 22px;
    min-height: 48px;
  }

  .sp-item {
    min-height: 44px;
  }
}

/* --- Camera mode (touch): let the board fill the screen --- */
/* The 20:14 letterbox is dropped so the canvas fills the available area; the
   camera (render.js) follows the player and pinch adjusts the zoom. Scoped to
   real touch devices so a narrow desktop window keeps the fitted board above. */
@media (pointer: coarse) {
  #game-area {
    align-items: stretch;
    padding: 4px 6px 6px;
  }

  #play-zone {
    max-width: none;
    width: auto;
    flex: 1;
    min-height: 0;
  }

  #game {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    height: auto;
    aspect-ratio: auto; /* break the 20:14 lock — fill the screen */
    border-width: 2px;
    touch-action: none; /* pinch-zoom is the game's, not the browser's */
  }
}
