:root {
  --pane-width: clamp(300px, 27vw, 390px);
  --ink: #18201f;
  --muted: #60706b;
  --panel: #f7fbf6;
  --panel-strong: #ffffff;
  --line: #d7e2dc;
  --green: #2f8f62;
  --teal: #167c82;
  --amber: #c87b20;
  --red: #c24735;
  --shadow: 0 18px 54px rgba(15, 32, 32, 0.24);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #d8efe8;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app {
  display: grid;
  grid-template-columns: 1fr var(--pane-width);
  width: 100vw;
  height: 100vh;
  direction: ltr;
}

.map-shell {
  position: relative;
  grid-column: 1;
  direction: rtl;
  min-width: 0;
  overflow: hidden;
  background: #cce7dd;
}

.city-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.time-hud {
  position: absolute;
  inset-block-start: max(14px, env(safe-area-inset-top));
  inset-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}

.time-copy {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 12px;
  min-width: 240px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 10px 28px rgba(24, 32, 31, 0.12);
  backdrop-filter: blur(10px);
}

.time-day strong,
.time-day span,
.time-money strong,
.time-money span {
  display: block;
  line-height: 1.25;
}

.time-day span,
.time-money span {
  color: var(--muted);
}

.time-money {
  padding-inline-start: 12px;
  border-inline-start: 1px solid rgba(45, 61, 57, 0.22);
}

.time-money strong {
  direction: ltr;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.time-track {
  position: relative;
  height: 18px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 999px;
  background: linear-gradient(90deg, #ed8a56 0%, #f5d36d 35%, #73bfd8 73%, #549b79 100%);
  box-shadow: inset 0 2px 7px rgba(24, 32, 31, 0.18), 0 10px 28px rgba(24, 32, 31, 0.12);
  overflow: hidden;
}

.time-track.night {
  background: linear-gradient(90deg, #1e355f 0%, #304973 45%, #5d6484 100%);
}

.speed-controls {
  display: grid;
  grid-template-columns: 40px minmax(54px, auto) 40px;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 10px 28px rgba(24, 32, 31, 0.12);
  backdrop-filter: blur(10px);
  direction: ltr;
  pointer-events: auto;
}

.speed-button {
  min-width: 40px;
  min-height: 40px;
  border-radius: 8px;
  background: #203b38;
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 900;
}

.speed-button:disabled {
  background: #a9bab4;
}

.speed-label {
  direction: ltr;
  min-width: 54px;
  color: #203b38;
  text-align: center;
  font-weight: 900;
}

.celestial-marker {
  --progress: 0;
  position: absolute;
  inset-block-start: 50%;
  inset-inline-end: calc(var(--progress) * (100% - 30px));
  width: 30px;
  height: 30px;
  border-radius: 999px;
  transform: translateY(-50%);
  box-shadow: 0 0 22px rgba(255, 211, 88, 0.75);
}

.celestial-marker.sun {
  background: #ffd650;
}

.celestial-marker.moon {
  background: #f1f5ff;
  box-shadow: inset -8px 1px 0 #aebad0, 0 0 18px rgba(217, 229, 255, 0.7);
}

.home-prompt {
  position: absolute;
  inset-block-start: 74px;
  inset-inline-start: 50%;
  transform: translateX(50%);
  max-width: min(520px, calc(100% - 30px));
  padding: 13px 18px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 700;
  pointer-events: none;
}

.map-tools {
  position: absolute;
  inset-block-end: max(18px, env(safe-area-inset-bottom));
  inset-inline-start: max(18px, env(safe-area-inset-left));
  display: grid;
  gap: 8px;
}

.icon-button {
  width: 46px;
  min-width: 46px;
  height: 46px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  box-shadow: 0 10px 26px rgba(21, 32, 32, 0.16);
  font-size: 1.45rem;
  font-weight: 800;
}

.skip-day {
  position: absolute;
  inset-block-end: max(18px, env(safe-area-inset-bottom));
  inset-inline-end: 18px;
  width: 44px;
  min-width: 44px;
  height: 44px;
  border-radius: 8px;
  background: rgba(28, 39, 42, 0.26);
  color: #ffffff;
  opacity: 0.2;
  transition: opacity 160ms ease, background 160ms ease;
}

.skip-day:hover,
.skip-day:focus-visible {
  opacity: 1;
  background: rgba(28, 39, 42, 0.72);
}

.side-pane {
  display: flex;
  flex-direction: column;
  grid-column: 2;
  direction: rtl;
  gap: 16px;
  min-width: 0;
  height: 100%;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  border-inline-start: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
}

.save-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.save-button {
  min-height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  background: #e4f1ec;
  color: #1f6651;
  font-weight: 800;
}

.danger-save {
  background: #f2e2de;
  color: var(--red);
}

.pane-section {
  min-width: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-block-end: 8px;
  color: #30413d;
  font-size: 0.95rem;
  font-weight: 800;
}

.small-action {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  background: #e4f1ec;
  color: #1f6651;
  font-weight: 700;
}

.workers-list,
.jobs-list,
.events-log {
  display: grid;
  gap: 8px;
}

.worker-row,
.job-row,
.event-row,
.offer-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.worker-row {
  display: grid;
  grid-template-columns: 18px 1fr auto auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  color: var(--ink);
  cursor: pointer;
  text-align: start;
}

.worker-dot {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0, 0, 0, 0.18);
  border-radius: 999px;
}

.worker-meta {
  min-width: 0;
}

.worker-meta strong,
.worker-meta small {
  display: block;
}

.worker-meta small,
.job-row small,
.event-row small {
  color: var(--muted);
}

.worker-status {
  min-width: 72px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef4f1;
  color: #435955;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
}

.fire-worker-button {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background: #f2e2de;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 800;
}

.job-row {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 11px 12px;
  color: var(--ink);
  text-align: start;
}

.job-row strong {
  overflow-wrap: anywhere;
}

.job-profit {
  direction: ltr;
  color: var(--green);
  font-weight: 800;
}

.job-profit.loss {
  color: var(--red);
}

.event-row {
  padding: 10px 12px;
  line-height: 1.35;
}

.active-offer-slot {
  margin-block-end: 8px;
}

.offer-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-color: #b9d7cb;
  box-shadow: 0 12px 30px rgba(24, 32, 31, 0.1);
}

.offer-card p {
  margin: 0;
  line-height: 1.45;
}

.offer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  background: var(--green);
  color: #ffffff;
}

.secondary-button {
  background: #e8efec;
  color: #263633;
}

.compact-button {
  min-height: 40px;
  padding: 0 12px;
  white-space: nowrap;
}

.details-toggle {
  grid-column: 1;
  justify-self: end;
}

.danger-button {
  background: #f2e2de;
  color: var(--red);
}

.empty-state {
  padding: 12px;
  border: 1px dashed #c5d5cf;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(13, 25, 28, 0.48);
}

.modal.is-open {
  display: flex;
}

.modal:has(.equation-dialog),
.modal:has(.all-jobs-dialog) {
  padding: 0;
}

.dialog {
  width: min(94vw, 760px);
  max-height: min(88vh, 760px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: #fbfdfb;
  box-shadow: var(--shadow);
}

.welcome-dialog {
  width: min(92vw, 520px);
  padding: 28px;
  text-align: center;
}

.welcome-dialog h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 5vw, 3.2rem);
  letter-spacing: 0;
}

.welcome-dialog p {
  margin: 0 0 22px;
  color: #40514d;
  font-size: 1.1rem;
  line-height: 1.5;
}

.welcome-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.equation-dialog {
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 14px;
  width: 100vw;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
  padding: 16px;
  direction: ltr;
}

.equation-dialog > * {
  direction: rtl;
}

.equation-dialog .graph-canvas {
  direction: ltr;
}

.dialog-header {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.dialog-header > div {
  flex: 1 1 280px;
}

.dialog-header h2,
.dialog-header p {
  margin: 0;
}

.dialog-header p {
  margin-block-start: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.close-button {
  box-shadow: none;
  background: #eef3f0;
}

.graph-canvas {
  grid-column: 2;
  grid-row: 2 / 5;
  width: 100%;
  height: 100%;
  min-height: 360px;
  border: 1px solid #ccd9d4;
  border-radius: 8px;
  background: #ffffff;
  touch-action: none;
}

.offer-controls {
  grid-column: 1;
  display: flex;
  align-items: end;
  gap: 10px;
}

.select-row {
  display: grid;
  gap: 5px;
  min-width: min(100%, 260px);
  color: #334743;
  font-weight: 800;
}

.select-row select {
  min-height: 44px;
  padding: 0 10px;
  border: 2px solid #c8d8d2;
  border-radius: 8px;
  background: #ffffff;
  color: #111c1a;
}

.equation-details {
  grid-column: 1;
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 8px;
}

.detail-pill {
  padding: 8px 10px;
  border-radius: 8px;
  background: #eef6f2;
  color: #334743;
  line-height: 1.25;
}

.formula-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.formula-row span {
  direction: ltr;
  font-size: 1.1rem;
  font-weight: 800;
}

.formula-row input {
  min-width: 0;
  min-height: 48px;
  padding: 0 12px;
  border: 2px solid #c8d8d2;
  border-radius: 8px;
  background: #ffffff;
  color: #111c1a;
  font-size: 1.05rem;
}

.formula-row input:focus {
  border-color: var(--teal);
  outline: 0;
}

.formula-feedback {
  grid-column: 1;
  min-height: 24px;
  color: var(--muted);
  line-height: 1.35;
}

.formula-feedback.good {
  color: var(--green);
  font-weight: 800;
}

.formula-feedback.bad {
  color: var(--red);
  font-weight: 800;
}

.dialog-actions {
  grid-column: 2;
  display: flex;
  justify-content: end;
  gap: 10px;
}

.equation-dialog.details-hidden .graph-canvas,
.equation-dialog.details-hidden .formula-row,
.equation-dialog.details-hidden .formula-feedback,
.equation-dialog.details-hidden .dialog-actions,
.equation-dialog.details-hidden .details-toggle {
  grid-column: 1 / -1;
}

.equation-dialog.details-hidden .graph-canvas {
  grid-row: 2;
}

.equation-dialog.details-hidden .details-toggle,
.equation-dialog.details-hidden .dialog-actions {
  justify-self: end;
}

.all-jobs-dialog {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 320px);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  width: 100vw;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
  padding: 16px;
}

.all-jobs-canvas {
  grid-column: 1;
  grid-row: 2;
  width: 100%;
  height: 100%;
  min-height: 360px;
  border: 1px solid #ccd9d4;
  border-radius: 8px;
  background: #ffffff;
  touch-action: none;
}

.all-jobs-legend {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
}

.legend-row {
  display: grid;
  grid-template-columns: 16px 1fr;
  align-items: start;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.legend-swatch {
  width: 16px;
  height: 16px;
  margin-block-start: 3px;
  border-radius: 4px;
}

.legend-row strong,
.legend-row small {
  display: block;
}

.legend-row small {
  color: var(--muted);
  direction: ltr;
  text-align: start;
}

.worker-history-dialog {
  width: min(94vw, 880px);
  max-height: min(88vh, 760px);
  padding: 16px;
}

.game-event-dialog {
  display: grid;
  gap: 14px;
  width: min(94vw, 720px);
  padding: 18px;
}

.game-event-message {
  margin: 0;
  color: #22312e;
  font-size: 1.08rem;
  line-height: 1.55;
}

.event-formula {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #cbd9d4;
  border-radius: 8px;
  background: #f0f7f4;
}

.event-formula span {
  color: var(--muted);
  font-weight: 800;
}

.event-formula strong {
  direction: ltr;
  overflow-wrap: anywhere;
  color: #15231f;
}

.event-result {
  min-height: 26px;
  color: var(--muted);
  font-weight: 800;
}

.event-result.good {
  color: var(--green);
}

.event-result.bad {
  color: var(--red);
}

.event-actions {
  grid-column: 1;
}

.worker-history-list {
  display: grid;
  gap: 8px;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr repeat(3, minmax(90px, auto));
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.history-row strong,
.history-row small,
.history-row span {
  display: block;
}

.history-row small {
  color: var(--muted);
}

.history-money {
  direction: ltr;
  font-weight: 800;
}

.history-empty {
  padding: 16px;
  border: 1px dashed #c5d5cf;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr minmax(240px, 36vh);
  }

  .map-shell,
  .side-pane {
    grid-column: 1;
  }

  .side-pane {
    border-block-start: 1px solid var(--line);
    border-inline-start: 0;
  }

  .time-hud {
    grid-template-columns: auto 1fr;
    gap: 7px;
  }

  .time-copy {
    justify-self: start;
    min-width: 224px;
  }

  .time-track {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .time-copy {
    grid-template-columns: 1fr;
    gap: 6px;
    min-width: 138px;
  }

  .time-money {
    padding-inline-start: 0;
    padding-block-start: 6px;
    border-inline-start: 0;
    border-block-start: 1px solid rgba(45, 61, 57, 0.22);
  }

  .equation-dialog,
  .all-jobs-dialog {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(320px, 1fr) auto auto auto auto;
    overflow: auto;
  }

  .graph-canvas,
  .all-jobs-canvas,
  .offer-controls,
  .equation-details,
  .details-toggle,
  .formula-row,
  .formula-feedback,
  .dialog-actions,
  .all-jobs-legend {
    grid-column: 1;
    grid-row: auto;
  }

  .equation-details {
    grid-template-columns: 1fr;
  }

  .history-row {
    grid-template-columns: 1fr;
  }

  .dialog-actions,
  .offer-actions,
  .event-actions {
    grid-template-columns: 1fr;
    flex-direction: column-reverse;
  }

  .worker-row {
    grid-template-columns: 18px 1fr auto;
  }

  .fire-worker-button {
    grid-column: 2 / -1;
    justify-self: start;
  }
}
