/* ─── Reset ───────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  font-family: system-ui, sans-serif;
  color: var(--fg);
}

/* ─── Game chrome ─────────────────────────────────────────────────────── */

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 16px 32px;
}

.game-title {
  margin: 0 0 6px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  color: var(--fg);
}

.game-statusbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0;
  min-height: 1.2em;
}

.game-stats {
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.game-energy {
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.game-area {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

/* ─── D-pad ───────────────────────────────────────────────────────────── */

.game-dpad {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.game-dpad-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.game-dpad-btn {
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  padding: 0;
}

.game-dpad-btn:active {
  background: #eddec4;
  transform: scale(0.92);
}

/* ─── Canvas ──────────────────────────────────────────────────────────── */

.game-canvas-wrapper {
  position: relative;
  line-height: 0;
}

.game-canvas {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  box-shadow: 0 2px 16px var(--shadow);
}

.game-canvas:focus {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ─── Rest overlay ────────────────────────────────────────────────────── */

.rest-overlay {
  position: absolute;
  inset: 0;
  border-radius: 8px; /* match .game-canvas */
  pointer-events: none;
  background: rgba(10, 18, 48, 0);
  transition: background 0.45s ease-out;
  overflow: hidden;
  z-index: 5;
}

.rest-overlay.is-sleeping {
  background: rgba(10, 18, 48, 0.52);
}

/* Pixel 'z' particles drifting upward */
.rest-z {
  position: absolute;
  font-family: 'Press Start 2P', monospace;
  font-size: var(--size, 10px);
  color: rgba(160, 200, 245, 0.85);
  bottom: var(--y, 54%);
  left: var(--x, 50%);
  animation: rest-z-float var(--dur, 3s) var(--delay, 0s) ease-in-out infinite;
  line-height: 1;
}

@keyframes rest-z-float {
  0%   { transform: translateY(0)     scale(1);    opacity: 0;   }
  12%  { opacity: 0.9; }
  75%  { opacity: 0.35; }
  100% { transform: translateY(-64px) scale(0.55); opacity: 0; }
}

/* Wake-up bloom flash */
.rest-bloom {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: radial-gradient(circle at 50% 50%, rgba(180, 210, 255, 0.45) 0%, transparent 65%);
  animation: rest-bloom-flash 0.65s ease-out forwards;
}

@keyframes rest-bloom-flash {
  0%   { opacity: 0; transform: scale(0.55); }
  28%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1.25); }
}

@media (prefers-reduced-motion: reduce) {
  .rest-z    { animation: none; opacity: 0; }
  .rest-bloom { animation: none; }
  .rest-overlay, .rest-overlay.is-sleeping { transition: none; background: transparent; }
}

/* ─── Shared bubble chrome ────────────────────────────────────────────── */
/* Used by .action-panel and .chat-input-wrapper                           */

.game-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 4px 16px var(--shadow);
}

/* Tail — outer border triangle */
.game-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 7px solid var(--border);
}

/* Tail — inner fill triangle (hides the border behind it) */
.game-bubble::before {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 8px;
  background: var(--bg);
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  z-index: 1;
}

/* ─── Chat input ──────────────────────────────────────────────────────── */

.chat-input-wrapper {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  visibility: hidden;
  white-space: nowrap;
}

.chat-input-wrapper.active {
  visibility: visible;
}

.chat-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 0;
  min-width: 60px;
  border: none;
  background: transparent;
  color: var(--fg);
  outline: none;
  display: block;
}

.chat-input::placeholder {
  color: var(--dim);
}
