:root {
  --bg-1: #f1f3f5;
  --bg-2: #dce3ea;
  --ink: #1c242e;
  --muted: #5f6b79;
  --panel: rgba(255, 255, 255, 0.8);
  --danger: #c93f4f;
  --ok: #2a8f66;
  --accent: #1f6fb2;
  --glow: rgba(31, 111, 178, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Tajawal", sans-serif;
  color: var(--ink);
  min-height: 100vh;
  background: radial-gradient(circle at 15% 20%, #fff 0%, var(--bg-1) 45%, var(--bg-2) 100%);
  overflow-x: hidden;
}

.bg-noise {
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(15, 23, 42, 0.08) 0.6px, transparent 0.6px);
  background-size: 4px 4px;
  opacity: 0.4;
  pointer-events: none;
  z-index: -1;
}

.game-shell {
  width: min(900px, 92vw);
  margin: 24px auto;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(27, 35, 45, 0.12);
  border-radius: 20px;
  box-shadow: 0 18px 45px rgba(15, 24, 36, 0.15);
  padding: 18px;
  display: grid;
  gap: 14px;
  transition: transform 300ms ease, box-shadow 300ms ease;
}

.game-shell.hostile {
  animation: shellShake 260ms linear 1;
  box-shadow: 0 0 0 2px rgba(201, 63, 79, 0.35), 0 16px 55px rgba(201, 63, 79, 0.22);
}

@keyframes shellShake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-4px, 1px);
  }
  50% {
    transform: translate(5px, -2px);
  }
  75% {
    transform: translate(-3px, 2px);
  }
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px dashed rgba(28, 36, 46, 0.2);
  padding-bottom: 10px;
}

.error-code {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.86rem;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ghost-btn {
  border: 1px solid rgba(28, 36, 46, 0.25);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 12px;
  font: inherit;
  cursor: pointer;
  transition: all 180ms ease;
}

.ghost-btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 6px 16px var(--glow);
}

.screen {
  min-height: 360px;
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 16px;
  border: 1px solid rgba(28, 36, 46, 0.1);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.84), rgba(244, 247, 250, 0.9));
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.screen h1 {
  margin: 0;
  font-size: clamp(1.4rem, 3.3vw, 2.2rem);
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.puzzle-area {
  width: 100%;
  margin-top: 18px;
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 170px;
}

.arena {
  width: min(600px, 96%);
  min-height: 170px;
  border: 1px dashed rgba(28, 36, 46, 0.28);
  border-radius: 16px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(241, 246, 250, 0.95));
}

.runaway-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.mini-note {
  color: var(--muted);
  margin: 0;
}

.drag-board {
  width: min(520px, 96%);
  display: grid;
  gap: 14px;
  place-items: center;
}

.drag-stage {
  width: 100%;
  min-height: 90px;
  border: 1px solid rgba(28, 36, 46, 0.17);
  border-radius: 14px;
  position: relative;
  background: rgba(255, 255, 255, 0.6);
}

.word-chip.dragging {
  opacity: 0.75;
}

.switch-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
  width: min(640px, 100%);
}

.switch-btn {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(28, 36, 46, 0.24);
  background: rgba(255, 255, 255, 0.9);
  font: inherit;
  cursor: pointer;
}

.switch-btn.active {
  background: linear-gradient(140deg, #1f6fb2, #1f4f7a);
  color: #fff;
}

.meter {
  width: min(460px, 96%);
  height: 12px;
  border-radius: 999px;
  background: rgba(28, 36, 46, 0.16);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #de7a2f, #c93f4f);
  transition: width 180ms ease;
}

.pulse-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #374557;
  cursor: pointer;
  border: 0;
  touch-action: manipulation;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(31, 111, 178, 0.25);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 0 11px rgba(31, 111, 178, 0);
  }
}

.wait-core {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(28, 36, 46, 0.2);
  border-top-color: #1f6fb2;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.terminal-card {
  width: min(620px, 98%);
  background: #0e141d;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  padding: 16px;
  color: #eaf2ff;
  font-family: "IBM Plex Mono", monospace;
  text-align: right;
  line-height: 1.8;
}

.narrator-box {
  border-radius: 14px;
  border: 1px solid rgba(28, 36, 46, 0.14);
  background: linear-gradient(145deg, rgba(13, 20, 29, 0.9), rgba(27, 40, 55, 0.9));
  color: #eef4ff;
  padding: 12px 14px;
  transition: transform 200ms ease;
}

.narrator-box.speaking {
  transform: translateY(-2px);
}

.narrator-tag {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  opacity: 0.85;
}

.narrator-box p {
  margin: 8px 0 0;
  line-height: 1.5;
}

.voice-config {
  border: 1px dashed rgba(28, 36, 46, 0.2);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.audio-controls {
  display: grid;
  gap: 8px;
}

.audio-row {
  display: grid;
  grid-template-columns: 100px 1fr 56px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.audio-row input[type="range"] {
  width: 100%;
}

.audio-row strong {
  color: var(--ink);
  text-align: left;
  font-size: 0.85rem;
}

.progress-wrap {
  display: grid;
  gap: 8px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.92rem;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: rgba(28, 36, 46, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #57ad84, #2e7ab0);
  transition: width 420ms cubic-bezier(0.28, 0.84, 0.42, 1);
}

.action-btn {
  border: none;
  background: linear-gradient(135deg, #28689f, #1b466b);
  color: #fff;
  border-radius: 12px;
  padding: 12px 18px;
  font: inherit;
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease;
}

.action-btn:hover {
  transform: translateY(-1px);
}

.word-chip {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  background: #1d2a36;
  color: #fff;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.drop-zone {
  width: min(360px, 92%);
  min-height: 70px;
  border: 2px dashed rgba(31, 111, 178, 0.55);
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.junk {
  font-family: "IBM Plex Mono", monospace;
  color: #6f7b88;
  font-size: 0.92rem;
}

.tiny-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(28, 36, 46, 0.24);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.tiny-dot:active {
  transform: scale(0.84);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.9);
  display: grid;
  place-items: center;
  z-index: 80;
}

.overlay.hidden {
  display: none;
}

.crash-card {
  background: #121821;
  color: #edf4ff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  width: min(480px, 90vw);
  padding: 24px;
  text-align: center;
}

.voice-gate-card {
  background: #121821;
  color: #edf4ff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  width: min(460px, 92vw);
  padding: 22px;
  text-align: center;
  display: grid;
  gap: 12px;
}

.voice-gate-card h2,
.voice-gate-card p {
  margin: 0;
}

.voice-gate-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.reveal {
  animation: reveal 430ms ease;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.end-note {
  max-width: 560px;
  line-height: 1.7;
  background: rgba(12, 17, 24, 0.92);
  color: #f4f8ff;
  border-radius: 14px;
  padding: 16px;
  text-align: right;
}

@media (max-width: 720px) {
  .top-bar,
  .progress-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions {
    width: 100%;
  }

  .ghost-btn {
    flex: 1;
  }

  .audio-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .audio-row strong {
    text-align: right;
  }

  .voice-gate-actions {
    flex-direction: column;
  }

  .screen {
    min-height: 430px;
  }

  .switch-grid {
    grid-template-columns: 1fr;
  }
}
