:root {
  --bg-dark: #0b0d14;
  --panel-bg: rgba(18, 22, 34, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-main: #f0f4f8;
  --text-muted: #8a96a8;
  
  --light-color: #ffb830;
  --light-glow: rgba(255, 184, 48, 0.35);
  --shadow-color: #9d4edd;
  --shadow-glow: rgba(157, 78, 221, 0.35);
  
  --accent-cyan: #00f5d4;
  --accent-red: #ff0055;
  --accent-green: #38b000;
  --accent-blue: #3a86ff;
  
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(255, 184, 48, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(157, 78, 221, 0.07) 0%, transparent 45%);
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  max-width: 1600px;
  margin: 0 auto;
  padding: 12px 20px;
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 12px 24px;
  margin-bottom: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  filter: drop-shadow(0 0 10px var(--light-color));
}

.brand-text h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #ffffff 0%, var(--light-color) 60%, var(--shadow-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text-muted);
}

.level-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.level-indicator .label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
}

.level-indicator .val {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-cyan);
}

.status-pills {
  display: flex;
  gap: 12px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
}

.grace-pill {
  border-color: var(--accent-red);
  color: var(--accent-red);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  0% { box-shadow: 0 0 4px var(--accent-red); }
  100% { box-shadow: 0 0 16px var(--accent-red); }
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Mission Banner */
.mission-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 245, 212, 0.08);
  border: 1px solid rgba(0, 245, 212, 0.2);
  border-radius: 10px;
  padding: 8px 16px;
  margin-bottom: 12px;
  font-size: 13px;
}

.banner-label {
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--accent-cyan);
  font-size: 11px;
}

.banner-text {
  color: var(--text-main);
  font-weight: 500;
}

/* Buttons */
.btn {
  font-family: var(--font-family);
  font-weight: 700;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn.primary {
  background: linear-gradient(135deg, var(--light-color), #f77f00);
  color: #000;
  box-shadow: 0 4px 16px var(--light-glow);
}

.btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--light-glow);
}

.btn.primary-accent {
  background: linear-gradient(135deg, var(--shadow-color), #7209b7);
  color: #fff;
  box-shadow: 0 4px 16px var(--shadow-glow);
}

.btn.primary-accent:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--shadow-glow);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

/* Game Workspace */
.game-workspace {
  display: flex;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

.sidebar-panel {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 16px;
}

.character-card {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0.6;
}

.character-card.active {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.3);
}

#card-light.active {
  box-shadow: 0 0 24px var(--light-glow);
  border-color: var(--light-color);
}

#card-shadow.active {
  box-shadow: 0 0 24px var(--shadow-glow);
  border-color: var(--shadow-color);
}

.char-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.char-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.light-avatar {
  background: rgba(255, 184, 48, 0.15);
  border: 1px solid var(--light-color);
}

.shadow-avatar {
  background: rgba(157, 78, 221, 0.15);
  border: 1px solid var(--shadow-color);
}

.char-info h3 {
  font-size: 15px;
  font-weight: 700;
}

.badge {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
  margin-top: 2px;
}

.light-badge {
  background: rgba(255, 184, 48, 0.2);
  color: var(--light-color);
}

.shadow-badge {
  background: rgba(157, 78, 221, 0.2);
  color: var(--shadow-color);
}

.char-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.full-width {
  width: 100%;
}

.hotkey-badge {
  font-size: 10px;
  background: rgba(0, 0, 0, 0.3);
  padding: 3px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
}

.controls-card h4 {
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.control-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-main);
}

kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-cyan);
}

/* Canvas Area */
.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  position: relative;
  overflow: hidden;
}

.canvas-wrapper {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}

canvas {
  display: block;
  background: #050608;
}

/* Overlay Card */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 6, 8, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: opacity 0.3s;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: var(--panel-bg);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 32px 48px;
  text-align: center;
  max-width: 480px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}

.overlay-card h2 {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--light-color), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.overlay-card p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.overlay-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: 720px;
  max-width: 90vw;
  background: #111420;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 2px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 28px;
  cursor: pointer;
  transition: color 0.2s;
}

.close-btn:hover {
  color: var(--text-main);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.level-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.level-card:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
}

.level-card .num {
  font-size: 32px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.1);
  position: absolute;
  top: 10px;
  right: 14px;
  font-family: var(--font-mono);
}

.level-card h4 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--light-color);
}

.level-card p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* HUD: loot secured & timer */
.loot-pill.done {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.timer-pill {
  font-family: var(--font-mono);
}

.timer-pill.over-par {
  border-color: var(--light-color);
  color: var(--light-color);
}

/* Victory / campaign stats */
.overlay-stats {
  display: none;
  grid-template-columns: 1fr;
  gap: 6px;
  margin: -8px 0 22px;
  text-align: left;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-size: 13px;
}

.stat-label {
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-main);
}

/* Level select: progress, stars and locks */
.level-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
}

.level-meta .stars {
  color: var(--light-color);
  font-size: 14px;
  letter-spacing: 2px;
}

.level-card.completed {
  border-color: rgba(56, 176, 0, 0.45);
}

.level-card.locked {
  cursor: not-allowed;
  opacity: 0.45;
}

.level-card.locked:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  transform: none;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
}

.total-stars {
  font-weight: 800;
  color: var(--light-color);
  white-space: nowrap;
}

.modal-hint {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
}

/* Signed-in player & extra controls */
.player-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(0, 245, 212, 0.08);
  border: 1px solid rgba(0, 245, 212, 0.25);
  font-size: 13px;
  font-weight: 700;
  margin-right: 4px;
}

.player-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent-cyan);
}

/* Page transitions (login <-> game) */
body.page-enter {
  animation: page-fade-in 0.6s ease both;
}

body.page-exit {
  animation: page-fade-out 0.45s ease both;
}

@keyframes page-fade-in {
  from { opacity: 0; filter: blur(6px); }
  to { opacity: 1; filter: none; }
}

@keyframes page-fade-out {
  to { opacity: 0; filter: blur(6px); }
}

/* Mission intro title card */
.level-intro {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}

.level-intro.show {
  animation: intro-card 2.2s ease both;
}

.intro-num {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 6px;
  color: var(--accent-cyan);
}

.intro-title {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--light-color), var(--shadow-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 18px rgba(0, 0, 0, 0.8));
}

@keyframes intro-card {
  0% { opacity: 0; transform: scale(1.15); letter-spacing: 14px; }
  20% { opacity: 1; transform: scale(1); letter-spacing: normal; }
  75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.96); }
}

/* Toast notifications */
.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(18, 22, 34, 0.92);
  border: 1px solid rgba(0, 245, 212, 0.35);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}

.toast.show {
  animation: toast-life 3.6s ease both;
}

@keyframes toast-life {
  0% { opacity: 0; transform: translate(-50%, 20px); }
  12% { opacity: 1; transform: translate(-50%, 0); }
  85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 10px); }
}

/* Overlay entrance */
.overlay:not(.hidden) .overlay-card {
  animation: card-pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

@keyframes card-pop {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  body.page-enter, body.page-exit, .level-intro.show, .toast.show, .overlay:not(.hidden) .overlay-card {
    animation-duration: 0.01s;
  }
}

/* =============================================================
   RESPONSIVE PLAYFIELD, TOUCH CONTROLS & SETTINGS
   ============================================================= */

/* mobile.js sizes the wrapper to fit its panel; the canvas keeps its 900x650 resolution */
.canvas-wrapper canvas {
  width: 100%;
  height: 100%;
}

.touch-only {
  display: none;
}

body.touch-ui .touch-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.touch-only.unsupported {
  display: none !important;
}

/* Narrow desktop windows: drop the sidebar so the playfield keeps its size */
@media (max-width: 1100px) {
  .sidebar-panel {
    display: none;
  }
}

/* Compact header for tablets & phones */
@media (max-width: 900px) {
  .app-container {
    padding: 8px;
  }

  .top-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 12px;
  }

  .brand .subtitle,
  .level-indicator .label,
  .player-avatar {
    display: none;
  }

  .logo-icon {
    font-size: 20px;
  }

  .brand-text h1 {
    font-size: 15px;
    letter-spacing: 1px;
  }

  .level-indicator .val {
    font-size: 13px;
  }

  .status-pills {
    gap: 6px;
  }

  .pill {
    padding: 4px 10px;
    font-size: 11px;
  }

  .top-controls {
    flex-wrap: wrap;
    gap: 6px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }

  .top-controls .btn {
    padding: 7px 10px;
    font-size: 12px;
  }

  .mission-banner {
    padding: 6px 10px;
    margin-bottom: 8px;
    font-size: 12px;
  }

  /* Overlays escape the (small) canvas so their buttons stay readable and tappable */
  .canvas-container {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .overlay {
    position: fixed;
    z-index: 50;
  }

  .overlay-card {
    padding: 22px 20px;
    max-width: 92vw;
    max-height: 92dvh;
    overflow-y: auto;
  }

  .overlay-card h2 {
    font-size: 22px;
  }

  .overlay-actions {
    flex-wrap: wrap;
  }

  .modal-content {
    padding: 18px;
    max-height: 92dvh;
    overflow-y: auto;
  }

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

  .modal-footer {
    flex-wrap: wrap;
  }

  .intro-title {
    font-size: clamp(20px, 6vw, 40px);
  }
}

/* ---------------------------------------------------------- touch layout */
body.touch-ui {
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.touch-ui .app-container {
  height: 100dvh;
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
}

body.touch-ui .sidebar-panel,
body.touch-ui #btn-rewind {
  display: none; /* the UNDO touch button replaces the header rewind */
}

body.touch-ui .game-workspace {
  position: relative;
  flex-direction: column;
  gap: 8px;
}

body.touch-ui .canvas-container {
  flex: 1;
  min-height: 0;
  border-radius: 12px;
  touch-action: none;
}

.touch-controls {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 12px;
  height: 180px;
  flex-shrink: 0;
  touch-action: none;
}

.touch-controls.hidden {
  display: none;
}

body.left-handed .touch-controls {
  flex-direction: row-reverse;
}

.joystick-zone {
  position: relative;
  flex: 1;
  max-width: 260px;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 60%, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  border: 1px dashed rgba(255, 255, 255, 0.1);
  touch-action: none;
  overflow: hidden;
}

.joystick-base {
  position: absolute;
  left: 50%;
  top: 55%;
  width: 112px;
  height: 112px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  border: 2px solid rgba(255, 255, 255, 0.16);
  opacity: 0.65;
  transition: opacity 0.15s;
  pointer-events: none;
}

.joystick-base.active {
  opacity: 1;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 22px rgba(0, 245, 212, 0.25);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, #fff, var(--accent-cyan));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 16px rgba(0, 245, 212, 0.4);
}

.joystick-hint,
.tilt-indicator {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
}

.joystick-hint {
  top: 8px;
}

.tilt-indicator {
  bottom: 8px;
  color: var(--accent-cyan);
}

.tilt-indicator.hidden {
  display: none;
}

.touch-buttons {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  align-items: center;
  justify-items: center;
  padding: 4px;
}

body.left-handed .touch-buttons {
  direction: rtl;
}

.touch-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: rgba(18, 22, 34, 0.85);
  color: var(--text-main);
  font-family: var(--font-family);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s;
}

.touch-btn .touch-icon {
  font-size: 22px;
  line-height: 1;
}

.touch-btn .touch-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
}

.touch-btn.small {
  width: 64px;
  height: 64px;
}

.touch-btn.swap {
  grid-row: 1 / span 2;
  grid-column: 2;
  width: 104px;
  height: 104px;
  border-color: var(--light-color);
  background: radial-gradient(circle at 40% 35%, rgba(255, 184, 48, 0.35), rgba(18, 22, 34, 0.9));
  box-shadow: 0 0 22px var(--light-glow);
}

.touch-btn.swap .touch-icon {
  font-size: 34px;
}

.touch-btn.swap.shadow {
  border-color: var(--shadow-color);
  background: radial-gradient(circle at 40% 35%, rgba(157, 78, 221, 0.4), rgba(18, 22, 34, 0.9));
  box-shadow: 0 0 22px var(--shadow-glow);
}

#touch-undo { grid-row: 1; grid-column: 1; }
#touch-rotate { grid-row: 2; grid-column: 1; }

.touch-btn.ready {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 18px rgba(0, 245, 212, 0.55);
  animation: ready-pulse 1s ease-in-out infinite alternate;
}

@keyframes ready-pulse {
  to { box-shadow: 0 0 28px rgba(0, 245, 212, 0.85); }
}

.touch-btn.pressed {
  transform: scale(0.9);
}

/* Phones held sideways: playfield takes the height, controls float over its edges */
@media (orientation: landscape) and (max-height: 600px) {
  body.touch-ui .top-bar {
    flex-wrap: nowrap;
    padding: 4px 10px;
    margin-bottom: 4px;
  }

  body.touch-ui .brand-text,
  body.touch-ui .level-indicator .label {
    display: none;
  }

  body.touch-ui .top-controls .btn {
    padding: 5px 8px;
    font-size: 11px;
  }

  body.touch-ui .icon-btn {
    width: 30px;
    height: 30px;
    font-size: 13px;
  }

  body.touch-ui .mission-banner {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
    padding: 3px 10px;
  }

  body.touch-ui .banner-label {
    display: none;
  }

  body.touch-ui .touch-controls {
    position: absolute;
    inset: 0;
    height: auto;
    pointer-events: none;
    padding: 0 6px 6px;
    align-items: flex-end;
  }

  body.touch-ui .joystick-zone {
    pointer-events: auto;
    flex: 0 0 34%;
    max-width: none;
    height: 72%;
    background: none;
    border: none;
  }

  body.touch-ui .joystick-hint {
    display: none;
  }

  body.touch-ui .touch-buttons {
    pointer-events: auto;
  }

  body.touch-ui .touch-btn {
    background: rgba(18, 22, 34, 0.55);
  }

  body.touch-ui .touch-btn.small {
    width: 54px;
    height: 54px;
  }

  body.touch-ui .touch-btn.swap {
    width: 84px;
    height: 84px;
  }
}

/* ---------------------------------------------------------- settings modal */
.settings-content {
  width: 560px;
}

.settings-group + .settings-group {
  margin-top: 20px;
}

.settings-group h3 {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent-cyan);
  margin-bottom: 8px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.setting-row.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.setting-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.setting-name {
  font-weight: 700;
  font-size: 14px;
}

.setting-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.segmented {
  display: flex;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 3px;
}

.segmented button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-family);
  font-weight: 700;
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--accent-cyan);
  color: #0b0d14;
}

.switch {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  inset: 0;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: background 0.2s;
}

.switch .slider::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.switch input:checked + .slider {
  background: var(--accent-cyan);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.switch input:focus-visible + .slider {
  outline: 2px solid var(--light-color);
  outline-offset: 2px;
}

.touch-help {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.touch-help strong {
  color: var(--text-main);
}

@media (max-width: 520px) {
  .setting-row {
    flex-wrap: wrap;
  }
}

/* Header text buttons collapse to icons on small screens */
.btn-icon {
  display: none;
}

@media (max-width: 900px) {
  .top-controls .btn .btn-icon {
    display: inline;
  }

  .top-controls .btn .btn-text {
    display: none;
  }

  .top-controls .btn {
    width: 34px;
    height: 34px;
    padding: 0 !important;
    justify-content: center;
  }

  .player-badge {
    padding: 4px 10px;
    font-size: 12px;
  }
}

/* Portrait phones: the playfield is width-limited, so its panel only takes the height it needs
   and the thumb controls get the rest of the screen */
@media (orientation: portrait) {
  body.touch-ui .canvas-container {
    flex: 0 1 auto;
    height: calc((100vw - 12px) * 650 / 900 + 8px);
  }

  body.touch-ui .touch-controls {
    flex: 1;
    height: auto;
    min-height: 150px;
    max-height: 280px;
    margin-top: auto;
  }

  body.touch-ui .top-bar {
    justify-content: center;
  }
}

@media (orientation: portrait) and (max-width: 480px) {
  body.touch-ui .player-badge {
    display: none; /* the player's name is shown on the welcome / pause screens */
  }

  body.touch-ui .top-controls {
    gap: 5px;
  }
}

/* Mid-size windows (small laptops, tablets): keep the header on one tidy row */
.pill,
.level-indicator .val,
.brand-text h1 {
  white-space: nowrap;
}

@media (max-width: 1200px) {
  .top-bar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .brand .subtitle {
    display: none;
  }

  .top-controls .btn .btn-icon {
    display: inline;
  }

  .top-controls .btn .btn-text {
    display: none;
  }

  .top-controls .btn {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  body.touch-ui .top-controls .btn {
    width: 30px;
    height: 30px;
  }
}
