/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0d0a;
  --surface: rgba(30, 22, 14, 0.85);
  --border: rgba(255, 200, 100, 0.12);
  --accent: #e8a020;
  --accent2: #c0392b;
  --text: #f0e8d8;
  --text-dim: rgba(240, 232, 216, 0.55);
  --chip-bg: rgba(255, 200, 100, 0.08);
  --danger: rgba(192, 57, 43, 0.18);
  --danger-border: rgba(192, 57, 43, 0.4);
  --font: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
  --radius: 16px;
  --hud-h: 56px;
  --foot-h: 36px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Layout ── */
.app-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: #050403;
}

.game-wrapper {
  /* iPhone 17 ratio: 393:852 ≈ 9:19.5 */
  --gw: min(100vw, calc(100vh * 9 / 19.5));
  --gh: min(100vh, calc(100vw * 19.5 / 9));
  width: var(--gw);
  height: var(--gh);
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at 50% 30%, #1e1408 0%, #0f0d0a 70%);
  position: relative;
  overflow: hidden;
}

/* ── HUD ── */
.hud {
  flex: 0 0 var(--hud-h);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  padding: 6px 10px 0;
  z-index: 10;
}

.hud-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 6px;
  backdrop-filter: blur(8px);
}

.hud-card-alert { border-color: rgba(192, 57, 43, 0.35); }
.hud-card-alert strong { color: #e74c3c; }

.hud-label {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  line-height: 1;
  margin-bottom: 2px;
}

.hud-card strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

/* ── Canvas Area ── */
.canvas-area {
  flex: 1 1 0;
  position: relative;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* ── Footer ── */
.footer-tip {
  flex: 0 0 var(--foot-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Overlays ── */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 5, 0.82);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 20;
}

.overlay-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  max-width: 320px;
  width: 88%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.overlay-panel-danger {
  border-color: var(--danger-border);
  background: rgba(30, 14, 12, 0.9);
}

.eyebrow {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-transform: uppercase;
}

h1 { font-size: 32px; font-weight: 800; color: var(--accent); line-height: 1.1; }
h2 { font-size: 28px; font-weight: 800; color: #e74c3c; line-height: 1.1; }

.overlay-copy { font-size: 13px; color: var(--text-dim); line-height: 1.6; }

.score-line { font-size: 16px; color: var(--text); }
.score-line strong { color: var(--accent); font-size: 22px; }

.rule-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.rule-chip {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-dim);
}

.primary-button {
  margin-top: 4px;
  padding: 14px 0;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #e8a020, #c0700a);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  width: 100%;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 20px rgba(232, 160, 32, 0.35);
  transition: transform 0.1s, box-shadow 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.primary-button:active {
  transform: scale(0.97);
  box-shadow: 0 2px 10px rgba(232, 160, 32, 0.2);
}
