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

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d9cf5;
  --accent-dim: #2a6fad;
  --good: #3ecf8e;
  --warn: #f5b83d;
  --bad: #f55d5d;
  --radius: 12px;
  --font: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

body {
  background:
    radial-gradient(ellipse at 20% 0%, #1a3050 0%, transparent 55%),
    radial-gradient(ellipse at 80% 100%, #1a2838 0%, transparent 50%),
    var(--bg);
}

.site-back {
  margin: 0;
  padding: 12px 16px 0;
  max-width: 1100px;
  margin-inline: auto;
}

.site-back a {
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}

.site-back a:hover {
  color: var(--accent);
}

.site-copyright {
  max-width: 1100px;
  margin: 32px auto 24px;
  padding: 16px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  border-top: 1px solid var(--surface-2);
}

.site-copyright p {
  margin: 0 0 8px;
}

.site-copyright p:last-child {
  margin-bottom: 0;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid #2d3d52;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field span {
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
select {
  padding: 0.6rem 0.75rem;
  border: 1px solid #3d5068;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field output {
  font-size: 0.95rem;
  font-weight: 600;
}

.name-len {
  font-size: 0.8rem;
  color: var(--muted);
}

.name-len.is-over {
  color: var(--bad);
  font-weight: 600;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn {
  padding: 0.65rem 1.25rem;
  border: 1px solid #3d5068;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: #2e4058;
  border-color: var(--accent-dim);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-dim);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 0.85rem;
}

.btn.ghost:hover:not(:disabled) {
  color: var(--text);
}

.btn.full {
  width: 100%;
  margin-top: 0.5rem;
}

.hint {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.howto-list {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  color: var(--text);
}

.howto-list li {
  margin-bottom: 0.55rem;
}

.howto-list li:last-child {
  margin-bottom: 0;
}

.howto-list strong {
  color: var(--accent);
}

.btn-help {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 90;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--accent-dim);
  background: var(--surface);
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  transition: background 0.15s, transform 0.15s;
}

.btn-help:hover {
  background: #263548;
  transform: scale(1.05);
}

#screen-game:not(.active) .btn-help {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 10, 18, 0.72);
}

.modal-panel {
  position: relative;
  width: min(520px, 100%);
  max-height: min(85vh, 640px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid #3d5068;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem 1.5rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.modal-panel h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.modal-close {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
  background: var(--surface-2);
}

.cash-chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 180px;
  margin-top: 0.5rem;
}

.rival-status {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.rival-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid #334558;
  border-radius: 8px;
  font-size: 0.85rem;
}

.rival-chip.is-player {
  border-color: var(--accent-dim);
}

.rival-chip.is-dead {
  opacity: 0.55;
}

.rival-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.rival-chip .name {
  flex: 1;
  font-weight: 600;
}

.rival-chip .cash {
  color: var(--muted);
  font-size: 0.8rem;
}

.game-date-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: linear-gradient(135deg, #1e3350 0%, var(--surface) 100%);
  border: 1px solid #2d4a68;
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.1rem;
  margin-bottom: 1rem;
  transition: background 0.4s ease, border-color 0.4s ease;
}

.game-date-banner.economy-boom {
  background: linear-gradient(135deg, #143328 0%, #1a2e38 55%, var(--surface) 100%);
  border-color: #2d6b52;
  box-shadow: inset 0 0 40px rgba(62, 207, 142, 0.08);
}

.game-date-banner.economy-normal {
  background: linear-gradient(135deg, #1e3350 0%, var(--surface) 100%);
  border-color: #2d4a68;
}

.game-date-banner.economy-recess {
  background: linear-gradient(135deg, #3a1e28 0%, #1e2838 55%, var(--surface) 100%);
  border-color: #6b3a48;
  box-shadow: inset 0 0 40px rgba(245, 93, 93, 0.06);
}

.game-date-info {
  flex: 0 0 auto;
  text-align: center;
  min-width: 9rem;
}

.company-visual {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  overflow: hidden;
}

.pixel-scene {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 120px;
  image-rendering: -moz-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.pixel-person-new {
  animation: pixel-pop 0.45s ease-out;
}

.pixel-count-badge {
  animation: pixel-pop 0.45s ease-out;
}

.pixel-count-label {
  font-family: "Courier New", Consolas, monospace;
  font-weight: 700;
  fill: #e8edf4;
}

@keyframes pixel-pop {
  0% {
    transform: translateY(8px);
    opacity: 0;
  }
  60% {
    transform: translateY(-3px);
    opacity: 1;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

.game-date-label {
  margin: 0 0 0.15rem;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.game-date-value {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.04em;
}

.game-date-sub {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

@media (max-width: 600px) {
  .game-date-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .game-date-info {
    min-width: 0;
  }

  .pixel-scene {
    max-height: 100px;
  }
}

@media (max-width: 500px) {
  .game-date-value {
    font-size: 1.85rem;
  }
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.status-item {
  background: var(--surface);
  border: 1px solid #2d3d52;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.status-item .label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.status-item .value {
  font-size: 1rem;
  font-weight: 600;
}

.economy-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.85rem !important;
}

.economy-boom {
  background: rgba(62, 207, 142, 0.2);
  color: var(--good);
}

.economy-normal {
  background: rgba(61, 156, 245, 0.2);
  color: var(--accent);
}

.economy-recess {
  background: rgba(245, 93, 93, 0.2);
  color: var(--bad);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 700px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.stats-dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 1rem;
  margin: 0;
}

.stats-dl dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.stats-dl dd {
  margin: 0;
  text-align: right;
  font-weight: 600;
}

.staff-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.project-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.project-card {
  background: var(--surface-2);
  border: 1px solid #334558;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.project-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.project-rate {
  font-size: 0.8rem;
  color: var(--accent);
}

.project-desc {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.engineer-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.bid-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bid-card {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid #334558;
  border-radius: 8px;
  cursor: pointer;
}

.bid-card-selected {
  border-color: var(--accent-dim);
  background: #263548;
}

.bid-card input {
  margin-top: 0.25rem;
  accent-color: var(--accent);
}

.bid-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.bid-type {
  font-size: 0.85rem;
  color: var(--accent);
}

.bid-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.bid-chance {
  display: inline-block;
  margin-left: 0.5rem;
  color: var(--good);
  font-weight: 600;
}

.contract-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.contract-card {
  background: var(--surface-2);
  border: 1px solid #3a5568;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.contract-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.contract-type {
  font-size: 0.85rem;
  color: var(--accent);
}

.contract-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.contract-meta .staff-count {
  color: var(--text);
}

.contract-card.contract-full {
  border-left-color: var(--warn);
}

.contract-card.contract-full .staff-count {
  color: var(--warn);
}

.engineer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 0.75rem;
  align-items: start;
  padding: 0.75rem;
  background: var(--surface-2);
  border: 1px solid #334558;
  border-radius: 8px;
}

@media (max-width: 700px) {
  .engineer-row {
    grid-template-columns: 1fr;
  }
}

.eng-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.salary-adjust {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  flex: 1;
}

.eng-salary {
  flex: 1;
  min-width: 120px;
  accent-color: var(--accent);
}

.eng-salary-display {
  transition: color 0.15s ease;
}

.engineer-row:has(.eng-salary:active) .eng-salary-display,
.engineer-row:has(.eng-salary:focus) .eng-salary-display {
  color: var(--accent);
}

.eng-founder {
  font-size: 0.8rem;
  color: var(--muted);
}

.btn-salary {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.engineer-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}

.eng-name {
  font-weight: 600;
  min-width: 7rem;
}

.eng-stat {
  font-size: 0.85rem;
  color: var(--muted);
}

.eng-stat strong {
  color: var(--text);
}

.eng-stat.mot-high strong {
  color: var(--good);
}

.eng-stat.mot-mid strong {
  color: var(--warn);
}

.eng-stat.mot-low strong {
  color: var(--bad);
}

.eng-assignment {
  min-width: 200px;
  padding: 0.5rem 0.6rem;
  border: 1px solid #3d5068;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}

.btn-sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
}

.btn-fire {
  border-color: #6b3a3a;
  color: #f5a0a0;
}

.log-card {
  max-height: 220px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  font-size: 0.85rem;
}

.log-list li {
  padding: 0.35rem 0;
  border-bottom: 1px solid #2a3848;
  color: var(--muted);
}

.log-list li:first-child {
  color: var(--text);
}

.ranking-list {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
}

.ranking-list li {
  margin-bottom: 0.35rem;
}

.ranking-list .score {
  font-weight: 700;
  color: var(--accent);
}

.ranking-list .meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.end-card {
  text-align: center;
}

.end-message {
  font-size: 1.05rem;
  margin-bottom: 1.5rem;
}

.end-stats {
  max-width: 280px;
  margin: 0 auto 1.5rem;
}

.end-stats .score {
  font-size: 1.5rem;
  color: var(--accent);
}

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

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

.toast-root {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 0.5rem;
  width: min(420px, calc(100% - 2rem));
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid #3d5068;
  border-left-width: 4px;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.45;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

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

.toast-success {
  border-left-color: var(--good);
}

.toast-error {
  border-left-color: var(--bad);
}

.toast-info {
  border-left-color: var(--accent);
}
