:root {
  --floor: #1f2230;
  --floor-2: #2a2e40;
  --safety: #f7c934;
  --safety-deep: #d9a90f;
  --kenney: #7078c0;
  --signal: #ef4b3f;
  --steel: #dfe3ec;
  --steel-2: #c6ccda;
  --ink: #1d1f26;
  --display: 'Saira Stencil One', 'Arial Black', sans-serif;
  --body: 'Barlow Semi Condensed', 'Arial Narrow', sans-serif;
  --hazard: repeating-linear-gradient(-45deg, var(--safety) 0 14px, var(--ink) 14px 28px);
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--floor);
  font-family: var(--body);
  color: var(--steel);
  -webkit-user-select: none;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

kbd {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-weight: 700;
  background: var(--ink);
  color: var(--steel);
  border: 1px solid #454a5e;
  border-bottom-width: 3px;
  border-radius: 4px;
  padding: 0 0.35rem;
  font-size: 0.8rem;
}

/* ---------- full screen layers ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#loading {
  background: var(--floor);
}

.loading-box {
  width: min(320px, 80vw);
  text-align: center;
}

.logo-small {
  font-family: var(--display);
  font-size: 2rem;
  color: var(--safety);
  margin-bottom: 1rem;
}

.loading-bar {
  height: 10px;
  background: var(--floor-2);
}

.loading-bar .progress-bar {
  background: var(--hazard);
  background-size: 40px 40px;
}

.loading-text {
  margin-top: 0.6rem;
  opacity: 0.7;
}

#title {
  background: linear-gradient(180deg, rgba(20, 22, 32, 0.15) 0%, rgba(20, 22, 32, 0.35) 55%, rgba(20, 22, 32, 0.85) 100%);
  align-items: flex-end;
  padding-bottom: 7vh;
}

.title-wrap {
  text-align: center;
  padding: 0 16px;
  max-width: 720px;
}

.logo {
  font-family: var(--display);
  font-weight: 400;
  line-height: 0.82;
  margin: 0 0 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35));
}

.logo-line {
  font-size: clamp(3.2rem, 11vw, 7.5rem);
  color: var(--steel);
}

/* The memorable bit: CHAOS is painted on a hazard plate that's slightly askew. */
.logo-line-2 {
  color: var(--ink);
  background: var(--safety);
  padding: 0.05em 0.25em 0;
  transform: rotate(-3deg);
  box-shadow: 0 0 0 6px var(--ink), 0 0 0 12px var(--safety);
  margin-top: 0.15em;
}

.tagline {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 1.6rem 0 1.4rem;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}

.title-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.btn {
  font-family: var(--body);
  font-weight: 700;
}

.btn-clock {
  font-size: 1.35rem;
  padding: 0.55rem 2.2rem;
  box-shadow: 0 4px 0 var(--safety-deep), 0 8px 18px rgba(0, 0, 0, 0.4);
}

.btn-clock:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--safety-deep);
}

.title-actions .btn-outline-light {
  background: rgba(20, 22, 32, 0.55);
}

.title-foot {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.9rem;
  opacity: 0.8;
}

.credit {
  opacity: 0.7;
}

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#hud .btn {
  pointer-events: auto;
}

.hud-ticket {
  position: absolute;
  top: 14px;
  left: 16px;
  background: var(--steel);
  color: var(--ink);
  border-radius: 6px;
  padding: 0.5rem 0.9rem 0.55rem 1.4rem;
  min-width: 250px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  border-left: 10px solid transparent;
  border-image: var(--hazard) 1;
  border-image-width: 0 0 0 10px;
}

.hud-shift {
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.1;
}

.hud-quota {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.35rem 0;
}

.hud-progress {
  flex: 1;
  height: 8px;
  background: var(--steel-2);
}

.hud-progress .progress-bar {
  background: var(--kenney);
}

.hud-num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.95rem;
}

.hud-strikes {
  display: flex;
  gap: 0.3rem;
  font-size: 1.15rem;
}

.hud-strikes .bi-cone-striped {
  color: #e7742d;
}

.hud-strikes .lost {
  color: #9aa0b0;
  opacity: 0.45;
}

.hud-strikes .lost.just {
  animation: strike-pop 0.6s ease-out;
}

@keyframes strike-pop {
  0% { transform: scale(1.8); color: var(--signal); opacity: 1; }
  100% { transform: scale(1); }
}

.hud-score {
  position: absolute;
  top: 12px;
  right: 130px;
  text-align: right;
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.6);
}

.hud-score-num {
  font-family: var(--display);
  font-size: 2.6rem;
  line-height: 1;
  color: var(--steel);
  font-variant-numeric: tabular-nums;
}

.hud-combo {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--safety);
}

.hud-combo.bump {
  animation: combo-bump 0.35s ease-out;
}

@keyframes combo-bump {
  0% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.hud-pause {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 46px;
  height: 46px;
  font-size: 1.4rem;
  padding: 0;
  border: 2px solid #454a5e;
}

.hud-restart {
  right: 70px;
}

.btn-power.placing {
  border-color: #3fc96f;
  color: #3fc96f;
  box-shadow: 0 0 18px rgba(63, 201, 111, 0.5);
}

.sw-key.auto {
  border-color: #3fc96f;
  color: #3fc96f;
  width: auto;
  padding: 0 0.3rem;
  gap: 0.2rem;
}

.sw-key.placing {
  animation: key-pulse 0.9s ease-in-out infinite;
}

@keyframes key-pulse {
  50% { transform: translate(-50%, -50%) scale(1.25); }
}

.hud-powers {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.75rem;
}

.btn-power {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(29, 31, 38, 0.88);
  color: var(--steel);
  border: 2px solid #454a5e;
  padding: 0.45rem 0.9rem;
  overflow: hidden;
}

.btn-power:hover,
.btn-power:focus-visible {
  background: var(--ink);
  color: var(--safety);
  border-color: var(--safety);
}

.btn-power:disabled {
  opacity: 0.45;
  color: var(--steel);
}

.btn-power .bi {
  font-size: 1.2rem;
}

.power-count {
  background: var(--safety);
  color: var(--ink);
  border-radius: 999px;
  min-width: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.power-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 0;
  background: var(--safety);
}

.btn-power.active {
  border-color: var(--safety);
  box-shadow: 0 0 18px rgba(247, 201, 52, 0.5);
}

.hud-toast {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--display);
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  color: var(--steel);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.hud-toast.show {
  animation: toast 1.6s ease-out forwards;
}

.hud-toast.bad {
  color: var(--signal);
}

.hud-toast.good {
  color: var(--safety);
}

@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.9); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  25% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -16px); }
}

/* ---------- 3D-anchored labels ---------- */

#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.sw-key {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--safety);
  border: 2px solid var(--safety);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-size: 1.5rem;
  color: var(--steel);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  animation: popup 1.1s ease-out forwards;
}

.popup.good { color: #ffffff; }
.popup.gold { color: var(--safety); font-size: 1.9rem; }
.popup.bad { color: var(--signal); font-family: var(--body); font-weight: 800; font-size: 1.2rem; }

@keyframes popup {
  0% { opacity: 0; margin-top: 10px; }
  15% { opacity: 1; margin-top: 0; }
  100% { opacity: 0; margin-top: -60px; }
}

/* ---------- shift ticket modals ---------- */

.modal-backdrop.show {
  opacity: 0.55;
}

.ticket {
  --bs-modal-color: var(--ink);
  background: var(--steel);
  color: var(--ink);
  border: none;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  position: relative;
}

/* Punched holes down the left edge, like a time-clock card. */
.ticket::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 30px;
  bottom: 14px;
  width: 10px;
  background: radial-gradient(circle, var(--floor) 0 4px, transparent 4.5px) 0 0 / 10px 22px repeat-y;
  opacity: 0.85;
}

.ticket .modal-body,
.ticket .modal-header,
.ticket .modal-footer {
  padding-left: 2.1rem;
  padding-right: 1.4rem;
}

.ticket .modal-footer {
  border-top: 2px dashed var(--steel-2);
  background: #d3d8e3;
}

.ticket-strip {
  height: 14px;
  background: var(--hazard);
}

.ticket-strip-red {
  background: repeating-linear-gradient(-45deg, var(--signal) 0 14px, var(--ink) 14px 28px);
}

.ticket-strip.win {
  background: repeating-linear-gradient(-45deg, #3fc96f 0 14px, var(--ink) 14px 28px);
}

.ticket-strip.lose {
  background: repeating-linear-gradient(-45deg, var(--signal) 0 14px, var(--ink) 14px 28px);
}

.ticket-no {
  font-weight: 700;
  color: #5b6178;
  font-size: 1rem;
}

.ticket-title {
  font-family: var(--display);
  font-size: 2.1rem;
  line-height: 1.05;
  margin-bottom: 0.6rem;
}

.ticket-blurb {
  font-size: 1.12rem;
  font-weight: 500;
  max-width: 60ch;
}

.ticket-tip {
  background: #eef1f6;
  border-left: 4px solid var(--safety);
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  margin: 0;
}

.ticket-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.fact {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--ink);
  color: var(--steel);
  border-radius: 4px;
  padding: 0.2rem 0.55rem;
  font-weight: 700;
  font-size: 0.95rem;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  display: inline-block;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.ticket .btn-outline-dark {
  --bs-btn-color: var(--ink);
  --bs-btn-border-color: #8e94a8;
}

@media (min-width: 576px) {
  .modal-result {
    max-width: 620px;
  }
}

/* Time-clock stamp for the result. */
.stamp {
  position: absolute;
  right: 22px;
  top: 30px;
  transform: rotate(8deg);
  border: 3px solid currentColor;
  border-radius: 6px;
  padding: 0.15rem 0.6rem;
  font-family: var(--display);
  font-size: 1.5rem;
  color: #2e9e57;
  opacity: 0.9;
  text-align: center;
  line-height: 1.1;
}

.stamp.lose {
  color: var(--signal);
}

.stamp .stars {
  display: block;
  font-size: 1.2rem;
  letter-spacing: 0.1em;
}

.stamp.slam {
  animation: slam 0.45s cubic-bezier(0.2, 1.6, 0.5, 1) both;
}

@keyframes slam {
  0% { transform: rotate(8deg) scale(2.4); opacity: 0; }
  100% { transform: rotate(8deg) scale(1); opacity: 0.9; }
}

.ticket-table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--ink);
  margin-bottom: 0.75rem;
  max-width: 340px;
  font-size: 1.05rem;
}

.ticket-table td:first-child {
  padding-left: 0;
}

.ticket-table td.num {
  text-align: right;
  padding-right: 0.75rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.ticket-table tr.total td {
  border-top: 2px solid var(--ink);
  font-weight: 800;
}

.keys-table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--ink);
  max-width: 420px;
}

.keys-table td:first-child {
  padding-left: 0;
  width: 150px;
}

.credits {
  font-weight: 800;
  font-size: 1.15rem;
  background: var(--ink);
  color: var(--safety);
  border-radius: 4px;
  padding: 0.2rem 0.7rem;
  font-variant-numeric: tabular-nums;
}

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

.shop-item {
  background: #eef1f6;
  border: 2px solid var(--steel-2);
  border-radius: 6px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.shop-item h3 {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.shop-item p {
  margin: 0;
  font-weight: 500;
  flex: 1;
}

.shop-owned {
  font-weight: 700;
  color: #5b6178;
}

.roster {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.6rem;
}

.roster-card {
  text-align: left;
  background: #eef1f6;
  border: 2px solid var(--steel-2);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  color: var(--ink);
  font-family: var(--body);
}

.roster-card:hover:not(:disabled),
.roster-card:focus-visible {
  border-color: var(--ink);
  background: #fff;
}

.roster-card:disabled {
  opacity: 0.5;
}

.roster-card .r-no {
  font-weight: 700;
  color: #5b6178;
  font-size: 0.9rem;
}

.roster-card .r-name {
  font-weight: 800;
  font-size: 1.1rem;
  line-height: 1.15;
}

.roster-card .r-stars {
  color: var(--safety-deep);
  font-size: 0.95rem;
}

.roster-card .r-best {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  color: #5b6178;
}

.roster-card.overtime {
  background: var(--ink);
  color: var(--safety);
  border-color: var(--safety);
}

.roster-card.overtime .r-no,
.roster-card.overtime .r-best {
  color: var(--steel-2);
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem 1.25rem;
}

.help-item {
  display: flex;
  gap: 0.7rem;
  font-size: 1.05rem;
  font-weight: 500;
}

.help-item .bi {
  font-size: 1.5rem;
  color: var(--kenney);
}

.btn:focus-visible {
  outline: 3px solid var(--safety);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .hud-ticket {
    min-width: 0;
    left: 8px;
    top: 8px;
    padding: 0.35rem 0.6rem 0.4rem 1rem;
  }
  .hud-shift { font-size: 0.9rem; }
  .hud-score { right: 112px; top: 8px; }
  .hud-restart { right: 58px; }
  .hud-powers { gap: 0.4rem; }
  .hud-score-num { font-size: 1.8rem; }
  .hud-pause { top: 8px; right: 8px; width: 42px; height: 42px; }
  .power-name, .btn-power kbd { display: none; }
  .stamp { position: static; display: inline-block; margin-bottom: 0.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
