:root {
  --sand: #efe1c4;
  --sand-dark: #e2cfa8;
  --card: #f8efdc;
  --ink: #1e2b3a;
  --muted: #6b6250;
  --sea: #1d7f86;
  --coral: #e2553f;
  --sun: #f2b632;
  --radius: 6px;
  /* Vertical space reserved for header + footer around the game frame */
  --chrome: 200px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: var(--sand);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

.page {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  --stage-w: min(100vw - 32px, (100vh - var(--chrome)) * 16 / 9, 1600px);
}

/* ── Header ─────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: var(--stage-w);
}

.brand-ball {
  width: 34px;
  height: 34px;
  flex: none;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.brand h1 span { color: var(--coral); }

.brand p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.header-actions { margin-left: auto; display: flex; gap: 8px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--ink); color: var(--sand); }
.icon-btn:disabled { opacity: 0.4; cursor: default; background: var(--card); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

/* ── Game frame ─────────────────────────────────────────── */

.stage {
  position: relative;
  width: var(--stage-w);
  aspect-ratio: 16 / 9;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--ink);
}

#unity-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--ink);
  outline: none;
}

/* ── Loading overlay ────────────────────────────────────── */

.loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: var(--sea);
  color: var(--card);
  transition: opacity 0.4s ease;
}

.loader.hidden { opacity: 0; pointer-events: none; }

.loader-ball {
  width: 72px;
  height: 72px;
  animation: bounce 0.9s cubic-bezier(0.3, 0, 0.7, 1) infinite alternate;
}

.loader-shadow {
  width: 56px;
  height: 8px;
  margin-top: -14px;
  border-radius: 50%;
  background: rgba(30, 43, 58, 0.35);
  animation: shadow 0.9s cubic-bezier(0.3, 0, 0.7, 1) infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(-40px) rotate(0deg); }
  to   { transform: translateY(0) rotate(200deg); }
}

@keyframes shadow {
  from { transform: scaleX(0.55); opacity: 0.4; }
  to   { transform: scaleX(1); opacity: 1; }
}

.loader-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.progress {
  width: min(360px, 70%);
  height: 10px;
  border: 2px solid var(--card);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--sun);
  transition: width 0.2s ease;
}

.loader-status { font-size: 13px; opacity: 0.85; font-variant-numeric: tabular-nums; }

/* ── Click-to-focus hint ────────────────────────────────── */

.focus-hint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--sand);
  font-size: 13px;
  pointer-events: none;
  transition: opacity 0.3s;
}

.focus-hint.hidden { opacity: 0; }

/* ── Error / warning messages ───────────────────────────── */

.banners {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, 90%);
  z-index: 5;
}

.banner {
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 14px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-left-width: 6px;
}

.banner.warning { border-left-color: var(--sun); }
.banner.error { border-left-color: var(--coral); }

.error-screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: var(--sand);
  z-index: 6;
}

.error-screen.visible { display: flex; }
.error-screen h2 { margin: 0; color: var(--coral); font-size: 22px; }
.error-screen p { margin: 0; max-width: 520px; color: var(--muted); font-size: 14px; line-height: 1.5; }

/* ── Controls footer ────────────────────────────────────── */

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  width: var(--stage-w);
}

.control-card {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--card);
  border: 2px solid var(--sand-dark);
}

.control-card h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink);
}

.control-card h3 .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: 1px;
}

.control-card ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 13px;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  margin-right: 2px;
  border-radius: 3px;
  border: 1px solid var(--ink);
  border-bottom-width: 2px;
  background: #fffaf0;
  font: 600 12px/18px ui-monospace, Consolas, monospace;
  text-align: center;
  color: var(--ink);
}

/* ── Small screens / touch devices ──────────────────────── */

@media (max-width: 760px), (max-height: 520px) {
  .page { --chrome: 70px; --stage-w: min(100vw - 16px, (100vh - var(--chrome)) * 16 / 9); padding: 8px; gap: 8px; }
  .controls, .brand p, .icon-btn .label { display: none; }
  .brand h1 { font-size: 18px; }
  .brand-ball { width: 28px; height: 28px; }
}

.touch-note {
  display: none;
  width: var(--stage-w);
  padding: 8px 12px;
  border-radius: 4px;
  background: var(--card);
  border: 2px solid var(--sun);
  font-size: 13px;
  text-align: center;
}

.is-touch .touch-note { display: block; }
