:root {
  --bg: #0f1b1f;
  --panel: #172a30;
  --panel-2: #1e3a42;
  --accent: #3be1b4;
  --accent-2: #7bdcff;
  --text: #e8f4f6;
  --muted: #9cb3ba;
  --danger: #ff6b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 800px at 20% -10%, #2b4f59 0%, #0f1b1f 55%);
  color: var(--text);
  font-family: "SF Pro Rounded", "Avenir Next", "Trebuchet MS", sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

body.modal-open {
  overflow: hidden;
}

.app {
  min-height: 100vh;
  position: relative;
}

.game-frame-wrap {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: auto;
  opacity: 0.85;
}

.game-frame {
  width: 100%;
  height: 100%;
  border: 0;
  filter: saturate(1.05) contrast(1.05);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: auto;
  padding: 24px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(520px, 100%);
  background: var(--panel);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.overlay-header {
  display: flex;
  align-items: start;
  gap: 12px;
}

.question {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  flex: 1;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
  width: 44px;
  height: 44px;
}

.answers {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.answer-btn {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid #2f4d56;
  background: var(--panel-2);
  color: var(--text);
  font-size: 1rem;
  text-align: left;
}

.answer-btn:active {
  transform: scale(0.98);
}

.answer-btn.correct {
  animation: answer-correct 700ms ease;
  border-color: #2dd36f;
  box-shadow: 0 0 0 2px rgba(45, 211, 111, 0.25);
}

.answer-btn.wrong {
  animation: answer-wrong 700ms ease;
  border-color: #ff6b6b;
  box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.25);
}

@keyframes answer-correct {
  0% { transform: scale(1); background: var(--panel-2); }
  40% { transform: scale(1.03); background: rgba(45, 211, 111, 0.2); }
  100% { transform: scale(1); background: var(--panel-2); }
}

@keyframes answer-wrong {
  0% { transform: scale(1); background: var(--panel-2); }
  40% { transform: scale(0.98); background: rgba(255, 107, 107, 0.2); }
  100% { transform: scale(1); background: var(--panel-2); }
}

.report-panel {
  margin-top: 10px;
  max-width: 100%;
}

.report-panel details {
  background: rgba(23, 42, 48, 0.9);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
}

.report-panel pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 35vh;
  overflow: auto;
  color: var(--muted);
  margin: 8px 0 0 0;
  font-size: 0.85rem;
}

.next-puzzle-timer {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 12px;
  z-index: 9;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #2a4a52;
  background: rgba(23, 42, 48, 0.9);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  font-weight: 700;
}

.now-playing-pill {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 12px;
  z-index: 9;
  min-width: 44px;
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #2a4a52;
  background: rgba(23, 42, 48, 0.9);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  font-weight: 700;
  pointer-events: auto;
}

.np-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: transparent;
  pointer-events: none;
}

.now-playing-panel {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 12px;
  z-index: 9;
  max-width: min(92vw, 420px);
  display: none;
  pointer-events: none;
}

.now-playing-panel.open {
  display: block;
}

.now-playing {
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(23, 42, 48, 0.95), rgba(12, 20, 23, 0.98));
  border: 1px solid #2a4a52;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.np-title {
  font-weight: 800;
  font-size: 1.05rem;
}

.np-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.np-status {
  margin-top: 6px;
  font-size: 0.95rem;
}

.np-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

.np-btn {
  border: 1px solid #2a4a52;
  border-radius: 12px;
  padding: 10px 14px;
  background: #1b333a;
  color: var(--text);
  font-size: 0.95rem;
}

.np-btn.primary {
  background: var(--accent);
  color: #053327;
  font-weight: 700;
}

.close-np {
  font-size: 24px;
  color: var(--muted);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 11;
  pointer-events: auto;
}

.sheet-backdrop.hidden {
  display: none;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  pointer-events: auto;
  background: #14262b;
  border-radius: 18px 18px 0 0;
  transform: translateY(100%);
  transition: transform 200ms ease;
  box-shadow: var(--shadow);
}

.sheet.open {
  transform: translateY(0%);
}

.sheet-handle {
  width: 44px;
  height: 4px;
  background: #2f4d56;
  border-radius: 999px;
  margin: 10px auto 6px;
}

.sheet-content {
  padding: 12px 18px 24px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field span {
  color: var(--muted);
  font-size: 0.9rem;
}

select,
input {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border-radius: 12px;
  border: 1px solid #2a4a52;
  background: #0f1b1f;
  color: var(--text);
}

.pace-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.pace-btn {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #2a4a52;
  background: #1b333a;
  color: var(--text);
  font-size: 0.95rem;
}

.pace-btn.active {
  background: var(--accent-2);
  color: #04232c;
  font-weight: 700;
}

.pace-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.apply-btn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: 0;
  background: var(--accent);
  color: #053327;
  font-size: 1rem;
  font-weight: 700;
}

.hidden {
  display: none;
}

@media (min-width: 800px) {
  .sheet {
    left: auto;
    right: 12px;
    bottom: 92px;
    width: 380px;
  }
  /* Hide completely unless open (no peeking) */
  .sheet:not(.open) {
    display: none;
  }
  .sheet.open {
    display: block;
  }
  .sheet-backdrop {
    display: none;
  }
}
