/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sky-day-top: #b8dff8;
  --sky-day-bot: #f0f8ff;
  --sky-night-top: #0d1b35;
  --sky-night-bot: #1e3a5f;
  --taxi-yellow: #f5a623;
  --taxi-blue: #29b6f6;
  --text-dark: #1a1a1a;
  --text-gray: #b0b0b0;
  --box-border: #1a1a1a;
  --box-done: #c8c8c8;
  --accent: #29b6f6;
  font-size: 16px;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: #f0f8ff;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── Screen container ── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ── Sky ── */
.sky-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(180deg, var(--sky-day-top) 0%, var(--sky-day-bot) 100%);
  transition: background 1s ease;
}
.sky-bg.night {
  background: linear-gradient(180deg, var(--sky-night-top) 0%, var(--sky-night-bot) 100%);
}

/* ── Sky orb (sun/moon) ── */
.sky-orb {
  position: absolute;
  top: 28px;
  right: 28px;
  width: 52px;
  height: 52px;
}

/* Orb content is injected as inline SVG by game.js */

/* ── Taxi lane ── */
.taxi-lane {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 52px;
  overflow: hidden;
  z-index: 10;
}

/* ── Taxi SVG inline via background ── */
.taxi {
  position: absolute;
  bottom: 6px;
  width: 72px;
  height: 38px;
}

/* Taxi body drawn in JS as inline SVG */
.taxi-yellow { color: #f5a623; }
.taxi-blue   { color: #29b6f6; }

/* ── Getting Started screen ── */
.start-content {
  position: relative;
  z-index: 5;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 32px 80px;
  gap: 12px;
}
.logo {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -1.5px;
  color: var(--text-dark);
}
.tagline {
  font-size: 15px;
  color: #666;
  margin-bottom: 24px;
}
.start-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.field input {
  padding: 14px 16px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 10px;
  outline: none;
  background: white;
  color: var(--text-dark);
  transition: border-color 0.2s;
}
.field input:focus {
  border-color: var(--accent);
}

.btn-primary {
  margin-top: 8px;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  color: white;
  background: var(--text-dark);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: transform 0.1s, background 0.2s;
}
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  position: relative;
  z-index: 10;
  margin: 0 auto 80px;
  padding: 14px 32px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
  background: white;
  border: 2px solid var(--text-dark);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s;
}
.btn-secondary:active { transform: scale(0.97); }

/* ── Intro screen ── */
.intro-message {
  position: relative;
  z-index: 5;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 32px 80px;
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 700;
  color: var(--text-dark);
  text-align: center;
  line-height: 1.3;
  letter-spacing: -0.3px;
}
.intro-message.fade-out {
  animation: fadeOut 0.6s ease forwards;
}
@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-16px); }
}

/* ── Game screen ── */
.game-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  padding: 20px 20px 0;
  pointer-events: none;
}
.timer-box {
  font-size: 22px;
  font-weight: 700;
  border: 2.5px solid var(--text-dark);
  border-radius: 6px;
  padding: 6px 14px;
  background: rgba(255,255,255,0.85);
  color: var(--text-dark);
  letter-spacing: 0.5px;
  min-width: 80px;
  text-align: center;
}
.timer-box.urgent {
  border-color: #e53935;
  color: #e53935;
  animation: pulse-urgent 0.8s ease infinite;
}
@keyframes pulse-urgent {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* ── Word grid ── */
.word-grid-wrap {
  position: relative;
  z-index: 5;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 16px 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}
.word-grid-wrap::-webkit-scrollbar { display: none; }
.word-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  transition: all 0.4s ease;
}
.word-grid.building-formed {
  border: 4px solid #1a1a1a;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  padding: 6px 6px 0;
  background: white;
}

/* Word row */
.word-row {
  display: flex;
  gap: 4px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  position: relative;
}
.word-row.visible { opacity: 1; transform: translateY(0); }

/* Starter row — today's word */
.word-row.starter-row::after {
  content: "Today's word";
  position: absolute;
  bottom: -16px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: #aaa;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}
.word-grid.building-formed .starter-row::after { display: none; }

/* Letter box */
.letter-box {
  width: 48px;
  height: 50px;
  border: 2.5px solid var(--box-border);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  position: relative;
  transition: border-color 0.2s, background 0.2s;
}
.letter-box.active-box {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(41, 182, 246, 0.25);
}
.letter-box.constrained {
  background: #f0f8ff;
}
.letter-box .letter-char {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-dark);
  text-transform: uppercase;
  letter-spacing: 0;
  line-height: 1;
  user-select: none;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* Completed row */
.word-row.completed .letter-box {
  border-color: var(--box-done);
}
.word-row.completed .letter-char {
  color: var(--box-done);
}

/* Shake animation for invalid word */
.word-row.shake {
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

/* Window mode — applied after letters have faded */
.word-row.window-mode .letter-box {
  width: 38px;
  height: 32px;
  border-width: 2px;
  border-color: #1a1a1a;
  border-radius: 3px;
  background: white;
  transition: width 0.3s ease, height 0.3s ease;
}
.word-row.window-mode .letter-char { display: none; }

/* Door on bottom completed row */
.word-row.has-door::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 26px;
  height: 30px;
  background: white;
  border: 2px solid #1a1a1a;
  border-bottom: none;
  border-radius: 3px 3px 0 0;
  z-index: 2;
}

/* ── On-screen keyboard ── */
.keyboard {
  position: relative;
  z-index: 10;
  background: rgba(240, 240, 240, 0.95);
  padding: 8px 6px 12px;
  border-top: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.kb-key {
  min-width: 30px;
  height: 44px;
  padding: 0 4px;
  background: white;
  border: 1.5px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dark);
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.kb-key:active, .kb-key.pressed { background: #e0e0e0; }
.kb-wide { min-width: 56px; font-size: 12px; }

/* ── Post-game ── */
.post-message {
  position: relative;
  z-index: 5;
  padding: 32px 28px 12px;
  font-size: clamp(20px, 5.5vw, 26px);
  font-weight: 700;
  color: var(--text-dark);
  text-align: center;
  line-height: 1.3;
  letter-spacing: -0.2px;
}

.city-viewport {
  position: relative;
  z-index: 5;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.city-street {
  flex: 1;
  display: flex;
  align-items: flex-end;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 24px;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.city-street::-webkit-scrollbar { display: none; }

.street-floor {
  position: relative;
  height: 58px;
  overflow: hidden;
}

/* Building SVG wrapper */
.building-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Person walking a dog ── */
.person-dog {
  position: absolute;
  bottom: 6px;
  right: 64px;
  width: 68px;
  height: 42px;
}

/* ── Toast notification ── */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(50, 50, 50, 0.92);
  color: white;
  padding: 22px 32px;
  border-radius: 14px;
  text-align: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  min-width: 220px;
  max-width: 80vw;
  backdrop-filter: blur(4px);
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.toast-message {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.4;
}
.toast-check {
  font-size: 28px;
  margin-top: 8px;
  display: none;
  color: #aee;
}

/* ── Taxi animation ── */
@keyframes taxi-move {
  from { left: -90px; }
  to   { left: calc(100% + 10px); }
}
.taxi.moving {
  animation: taxi-move linear infinite;
}

/* ── Night stars ── */
.stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 1s;
}
.sky-bg.night .stars { opacity: 1; }
.star {
  position: absolute;
  background: white;
  border-radius: 50%;
  animation: twinkle 3s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1; }
}

/* ── Responsive ── */
@media (min-width: 480px) {
  .letter-box { width: 52px; height: 54px; }
  .letter-box .letter-char { font-size: 26px; }
}
@media (min-width: 600px) {
  .letter-box { width: 56px; height: 58px; }
}

/* ── Letter fade animation ── */
@keyframes letter-fade {
  to { opacity: 0; }
}
.letter-fading {
  animation: letter-fade 0.3s ease forwards;
}
