:root {
  --bg-dark: #0d0f1a;
  --bg-panel: #1a1d33;
  --text: #e0e8ff;
  --muted: #a0a8c8;
  --accent-blue: #6fa8ff;
  --accent-pink: #ff7ac2;
  --accent-green: #6fe3a2;
  --accent-yellow: #ffd86b;
  --accent-red: #ff6f6f;
  --accent-orange: #ff9b4a;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: auto;
}

body {
  background: radial-gradient(circle at top, #1e2245, var(--bg-dark) 70%);
  color: var(--text);
  font-family: "Lexend", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.app-header {
  padding: 16px 24px;
  border-bottom: 1px solid #303560;
}

.title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.help-btn {
  margin-left: 6px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid #4a4f80;
  background: #2a2d4a;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.help-btn:hover {
  background: #38406c;
  transform: translateY(-1px);
}

.help-btn:active {
  transform: translateY(1px);
}

.limit-badge,
.game-title {
  font-size: 32px;
  font-weight: 900;
  color: var(--accent-orange);
  line-height: 1;
  text-shadow: 0 0 6px #ff6600;
}

.hud {
  display: flex;
  gap: 16px;
  align-items: center;
}

.hud-item {
  background: var(--bg-panel);
  border: 1px solid #303560;
  border-radius: 12px;
  padding: 8px 14px;
  min-width: 110px;
  text-align: center;
  box-shadow: var(--shadow);
}

.hud-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.hud-value {
  font-family: "Space Mono", monospace;
  font-size: 26px;
  font-weight: 700;
  color: var(--accent-yellow);
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 100px);
}

.yard-card {
  background: #000;
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid #303560;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#yardCanvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.countdown-bubble {
  position: absolute;
  top: 18px;
  right: 18px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid var(--accent-yellow);
  color: var(--accent-yellow);
  font-family: "Space Mono", monospace;
  font-size: 28px;
  font-weight: 700;
  border-radius: 999px;
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.2s, transform 0.2s;
}

.countdown-bubble.visible {
  opacity: 1;
  transform: scale(1);
}

.right-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.status-box,
.controls-box,
.pen-box,
.quiz-panel,
.history-box {
  background: var(--bg-panel);
  border: 1px solid #303560;
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.status-box {
  display: flex;
  justify-content: space-around;
  text-align: center;
}

.status-item .label {
  font-size: 14px;
  color: var(--muted);
}

.status-item .value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  font-family: "Space Mono";
  margin-top: 4px;
  color: var(--accent-green);
}

.controls-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.question {
  text-align: center;
  font-weight: 700;
  color: var(--accent-blue);
  font-size: 18px;
}

.control-prompt {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.control-hint {
  text-align: center;
  color: var(--accent-yellow);
  font-size: 12px;
  font-family: "Space Mono";
}

.feedback {
  min-height: 22px;
  text-align: center;
  color: var(--accent-pink);
  font-family: "Space Mono";
  font-size: 13px;
}

.pen-box h3,
.history-box h3 {
  margin: 0 0 12px;
  text-align: center;
  color: var(--accent-blue);
}

.pen-summary {
  text-align: center;
  color: var(--muted);
  margin-bottom: 12px;
}

.pen-icons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  border: 1px dashed #3b4475;
  background: rgba(111, 168, 255, 0.08);
  min-height: 80px;
}

.pen-icon {
  font-size: 20px;
  text-align: center;
}

.history-list {
  margin: 0;
  padding-left: 20px;
  height: 160px;
  max-height: 160px;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: "Space Mono";
  font-size: 12px;
  line-height: 1.6;
}

.history-list li {
  margin: 4px 0;
  padding: 4px 0;
}

button.primary {
  width: 100%;
  background: linear-gradient(45deg, var(--accent-orange), var(--accent-red));
  border: none;
  color: #fff;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  text-shadow: 0 1px 3px #0005;
  transition: transform 0.2s;
}

button.primary:hover {
  transform: scale(1.02);
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: #0d0f1acc;
  backdrop-filter: blur(8px);
  z-index: 100;
}

.overlay.visible {
  display: grid;
}

.overlay .card {
  width: min(900px, 96vw);
  min-height: 40vh;
  max-height: 90vh;
  background: linear-gradient(135deg, #1a1d33 0%, #0d0f1a 100%);
  border: 2px solid #303560;
  border-radius: 20px;
  padding: 32px;
  color: #fff;
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.overlay .card h2 {
  color: var(--accent-orange);
  text-align: center;
  margin-bottom: 20px;
  font-size: 28px;
  text-shadow: 0 0 10px rgba(255, 155, 74, 0.3);
}

.overlay .card.help {
  width: min(1000px, 96vw);
  min-height: 60vh;
}

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

.help-header h2 {
  margin: 0;
}

.close-btn {
  background: #2a2d4a;
  border: 1px solid #4a4f80;
  color: #fff;
  border-radius: 8px;
  font-size: 24px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
  padding: 0;
}

.close-btn:hover {
  background: #38406c;
  transform: scale(1.05);
}

.help-content {
  line-height: 1.7;
  font-size: 15px;
}

.help-content h3 {
  color: var(--accent-yellow);
  margin: 20px 0 10px;
  font-size: 18px;
}

.help-content ul,
.help-content ol {
  padding-left: 24px;
  margin: 12px 0;
}

.help-content li {
  margin: 8px 0;
}

.help-content .tip {
  background: rgba(111, 168, 255, 0.1);
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid var(--accent-blue);
  margin-top: 16px;
}

.instructions-text {
  line-height: 1.7;
  font-size: 15px;
}

.instructions-text .tip {
  background: rgba(111, 168, 255, 0.1);
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid var(--accent-blue);
  margin-top: 16px;
}

.countdown {
  text-align: center;
  font-family: "Space Mono";
  color: var(--accent-yellow);
  font-size: 18px;
  margin-top: 20px;
}

.countdown span {
  font-weight: 700;
  font-size: 24px;
}

.setup label {
  display: block;
  margin: 16px 0;
  font-size: 15px;
}

.setup input,
.setup select {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #4a4f80;
  background: linear-gradient(180deg, #141938 0%, #0d112b 100%);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}

.setup input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.2);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.avatar-option {
  display: grid;
  place-items: center;
  border: 2px solid #4a4f80;
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, background 0.2s;
}

.avatar-option img {
  width: 52px;
  height: 52px;
  display: block;
}

.avatar-option.selected {
  border-color: var(--accent-green);
  background: rgba(111, 227, 162, 0.15);
  transform: translateY(-2px);
}

.quiz-prompt {
  font-size: 18px;
  color: var(--accent-yellow);
  margin-bottom: 16px;
}

.quiz-form {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.quiz-form input {
  width: 140px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #4a4f80;
  background: #0d112b;
  color: var(--text);
  font-size: 18px;
  text-align: center;
  font-family: "Space Mono", monospace;
}

.quiz-feedback {
  min-height: 22px;
  margin-top: 12px;
  color: var(--accent-pink);
  font-family: "Space Mono";
}

.hidden {
  display: none !important;
}

.gameover {
  text-align: center;
}

.gameover-summary {
  font-size: 18px;
  color: var(--accent-yellow);
  margin-bottom: 20px;
}

.chase-scene {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  font-size: 30px;
  margin-bottom: 20px;
  animation: chase 1.2s ease-in-out infinite;
}

.chase-scene img {
  width: 56px;
  height: 56px;
  display: inline-block;
}

@keyframes chase {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(10px);
  }
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .limit-badge,
  .game-title {
    font-size: 24px;
  }

  .hud-value {
    font-size: 22px;
  }
}
