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

body {
  background: #111;
  color: #eee;
  font-family: 'Courier New', monospace;
  height: 100vh;
  overflow: hidden;
}

#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── Color Selection ── */
#color-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  background: #1a1a1a;
}

#color-screen h1 {
  font-size: 2rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #e0e0e0;
}

#color-screen p.subtitle {
  color: #888;
  font-size: 0.9rem;
  letter-spacing: 2px;
}

#color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  max-width: 600px;
}

.color-swatch {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}

.color-swatch:hover { transform: scale(1.12); }
.color-swatch.selected { border-color: #fff; transform: scale(1.12); }

#color-screen button {
  margin-top: 1rem;
  padding: 0.75rem 2.5rem;
  font-size: 1rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: #333;
  color: #888;
  border: 1px solid #555;
  cursor: not-allowed;
  transition: all 0.2s;
}

#color-screen button.active {
  background: #e31e1e;
  color: #fff;
  border-color: #e31e1e;
  cursor: pointer;
}

/* ── Train Selection ── */
#train-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  background: #1a1a1a;
  overflow-y: auto;
  padding: 2rem;
}

#train-screen h1 {
  font-size: 2rem;
  letter-spacing: 4px;
  text-transform: uppercase;
}

#train-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 900px;
}

.train-card {
  border: 3px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.train-card:hover { transform: scale(1.03); }
.train-card.selected { border-color: #e31e1e; }

.train-card img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
}

.train-card .train-name {
  background: #222;
  padding: 6px 10px;
  font-size: 0.8rem;
  letter-spacing: 2px;
  text-align: center;
}

#train-screen button {
  padding: 0.75rem 2.5rem;
  font-size: 1rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: #333;
  color: #888;
  border: 1px solid #555;
  cursor: not-allowed;
  transition: all 0.2s;
}

#train-screen button.active {
  background: #e31e1e;
  color: #fff;
  border-color: #e31e1e;
  cursor: pointer;
}

/* ── Painting Mode ── */
#painting-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #000;
}

#bg-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#bg-layer img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#night-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 20, 0.55);
  z-index: 1;
  pointer-events: none;
}

#paint-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  cursor: crosshair;
  touch-action: none;
}

/* ── Toolbar ── */
#toolbar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: rgba(10, 10, 10, 0.85);
  border-top: 1px solid #333;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  flex-wrap: wrap;
}

.toolbar-divider {
  width: 1px;
  height: 40px;
  background: #444;
  margin: 0 4px;
}

.toolbar-color {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.1s;
  flex-shrink: 0;
}

.toolbar-color:hover { transform: scale(1.15); }
.toolbar-color.active { border-color: #fff; transform: scale(1.15); }

.nozzle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 4px;
  background: transparent;
  transition: border-color 0.1s;
  flex-shrink: 0;
}

.nozzle-btn:hover { border-color: #666; }
.nozzle-btn.active { border-color: #e31e1e; }

.nozzle-dot {
  background: #fff;
  border-radius: 50%;
}

#paint-timer {
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  letter-spacing: 2px;
  color: #0f0;
  min-width: 72px;
  flex-shrink: 0;
}

#paint-timer.timer-warning {
  color: #f90;
  animation: pulse-text 0.5s ease-in-out infinite alternate;
}

@keyframes pulse-text {
  from { opacity: 1; }
  to   { opacity: 0.4; }
}

.toolbar-action-btn {
  background: #1a1a1a;
  color: #aaa;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 5px 10px;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.toolbar-action-btn:hover {
  background: #333;
  color: #eee;
}

.toolbar-finish-btn {
  color: #4c4;
  border-color: #363;
}

.toolbar-finish-btn:hover {
  background: #1a2e1a;
  color: #6f6;
  border-color: #4c4;
}

/* ── Police overlay ── */
#police-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  background: rgba(0,0,0,0.4);
}

#escape-btn {
  padding: 1.2rem 3rem;
  font-size: 2rem;
  font-family: 'Courier New', monospace;
  letter-spacing: 6px;
  text-transform: uppercase;
  background: #e31e1e;
  color: #fff;
  border: none;
  cursor: pointer;
  animation: pulse 0.6s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1);   box-shadow: 0 0 20px #e31e1e; }
  to   { transform: scale(1.06); box-shadow: 0 0 50px #e31e1e; }
}

#escape-countdown {
  font-size: 1.2rem;
  letter-spacing: 3px;
  color: #ffd700;
}

/* ── Result screens ── */
#result-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
}

#result-screen.arrested { background: rgba(150, 0, 0, 0.7); }
#result-screen.saved    { background: rgba(0, 0, 0, 0.75); }

#result-screen h1 {
  font-size: 5rem;
  letter-spacing: 12px;
  text-transform: uppercase;
}

#result-screen.arrested h1 { color: #fff; text-shadow: 0 0 30px #f00; }
#result-screen.saved h1    { color: #0f0; text-shadow: 0 0 30px #0f0; }

#result-screen button {
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-family: 'Courier New', monospace;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: transparent;
  color: #eee;
  border: 1px solid #eee;
  cursor: pointer;
}

/* ── Username Screen ── */
#username-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: #1a1a1a;
}

#username-screen h1 {
  font-size: 2.5rem;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: #e31e1e;
}

#username-screen .subtitle {
  color: #888;
  font-size: 0.9rem;
  letter-spacing: 2px;
}

#username-input {
  background: #222;
  border: 1px solid #555;
  border-bottom: 2px solid #e31e1e;
  color: #eee;
  font-family: 'Courier New', monospace;
  font-size: 1.4rem;
  letter-spacing: 3px;
  padding: 8px 16px;
  outline: none;
  width: 280px;
  text-align: center;
}

#username-input::placeholder { color: #444; }

#username-screen #username-next {
  padding: 0.75rem 2.5rem;
  font-size: 1rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: #e31e1e;
  color: #fff;
  border: none;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  transition: background 0.2s;
  margin: 0;
}

#username-screen #username-next:hover { background: #c01010; }

#gallery-btn {
  background: transparent;
  color: #555;
  border: 1px solid #333;
  padding: 6px 16px;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  letter-spacing: 2px;
  font-size: 0.85rem;
  transition: color 0.2s;
}

#gallery-btn:hover { color: #aaa; }

/* ── Gallery ── */
#gallery-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #111;
  overflow: hidden;
}

#gallery-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 16px 24px;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

#gallery-header h1 {
  font-size: 1.5rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #e31e1e;
  margin: 0;
}

#gallery-back {
  background: #222;
  color: #aaa;
  border: 1px solid #444;
  padding: 6px 14px;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  letter-spacing: 2px;
}

#gallery-back:hover { color: #eee; background: #333; }

#gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.gallery-card {
  position: relative;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  overflow: hidden;
}

.gallery-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.gallery-card img:hover { opacity: 0.85; }

.gallery-meta {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gallery-author {
  color: #e31e1e;
  font-size: 0.85rem;
  letter-spacing: 2px;
}

.gallery-date {
  color: #666;
  font-size: 0.75rem;
}

.gallery-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.7);
  color: #888;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-delete:hover { color: #e31e1e; }

#gallery-empty {
  color: #555;
  text-align: center;
  letter-spacing: 2px;
  margin-top: 4rem;
  padding: 24px;
}
