/* Cozy Campfire theme — warm umbers, ember amber, cream. No blue, no gradients. */
:root {
  --bg: #1a1108;
  --bg-2: #221609;
  --surface: #2b1d10;
  --surface-2: #3a2818;
  --border: #5c3d24;
  --border-soft: #4a3020;
  --text: #f3e3c3;
  --muted: #b89678;
  --ember: #ff8c42;
  --ember-deep: #e5701f;
  --gold: #f5c26b;
  --moss: #8fa96b;
  --rose: #d4756b;
  --danger: #c94a4a;
  --shadow: 0 6px 18px rgba(0,0,0,.45), 0 0 0 1px rgba(255,140,66,.04);
  --shadow-warm: 0 8px 30px rgba(255,140,66,.15);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  background:
    radial-gradient(1000px 700px at 50% 100%, #3a1e0a 0%, transparent 60%),
    radial-gradient(600px 400px at 15% -10%, #2a1a0a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
  letter-spacing: .01em;
}
button, input { font: inherit; color: inherit; }
h1,h2,h3 { margin: 0; font-weight: 600; letter-spacing: .02em; }

/* --- Topbar --- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; position: sticky; top: 0; z-index: 20;
  background: rgba(26,17,8,.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand svg { width: 30px; height: 30px; }
.actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border-soft);
  color: var(--text); border-radius: 10px; padding: 8px; cursor: pointer;
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.icon-btn:hover { border-color: var(--ember); background: var(--surface-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 20px; height: 20px; }

/* --- Views --- */
.view { display: none; padding: 16px 16px 100px; max-width: 1100px; margin: 0 auto; }
.view.active { display: block; }
.page-title {
  font-size: 26px; margin: 8px 4px 20px;
  display: flex; align-items: center; gap: 12px;
}
.page-title::before {
  content: ""; width: 6px; height: 24px; background: var(--ember);
  border-radius: 3px; box-shadow: 0 0 12px var(--ember);
}

/* --- Grid of games --- */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.tile {
  position: relative; text-align: left;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px 14px 16px;
  cursor: pointer; overflow: hidden;
  display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
  animation: rise .5s ease both;
}
.tile:hover { border-color: var(--ember); background: var(--surface-2); transform: translateY(-2px); }
.tile:active { transform: scale(.98); }
.tile .num {
  font-size: 11px; color: var(--muted); letter-spacing: .1em; text-transform: uppercase;
}
.tile .icon {
  width: 56px; height: 56px; border-radius: 12px;
  background: rgba(255,140,66,.08);
  border: 1px solid rgba(255,140,66,.18);
  display: flex; align-items: center; justify-content: center;
}
.tile .icon svg { width: 36px; height: 36px; }
.tile .title { font-size: 15px; font-weight: 700; line-height: 1.2; }
.tile .desc { font-size: 12px; color: var(--muted); line-height: 1.35; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- Game view --- */
.game-header {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 4px 14px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 14px;
}
.game-header h2 { flex: 1; font-size: 18px; }
.timer {
  font-variant-numeric: tabular-nums;
  padding: 4px 10px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border-soft);
  color: var(--gold); font-size: 14px;
}
.game-container {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px; min-height: 60vh;
}

/* --- Buttons --- */
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px; cursor: pointer;
  font-size: 14px; font-weight: 600;
  transition: transform .1s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { border-color: var(--ember); }
.btn:active { transform: scale(.96); }
.btn-primary {
  background: var(--ember); border-color: var(--ember-deep);
  color: #2a1608; box-shadow: 0 4px 14px rgba(255,140,66,.35);
}
.btn-primary:hover { background: var(--gold); border-color: var(--gold); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface); border-color: var(--border-soft); }
.btn-danger { background: var(--danger); border-color: #a13636; color: #fff; }

/* --- HUD (used inside games) --- */
.hud {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 10px 12px; margin-bottom: 12px;
  background: var(--bg-2); border-radius: 10px; border: 1px solid var(--border-soft);
  font-size: 14px;
}
.hud > * { display: inline-flex; align-items: center; gap: 6px; }
.hud b { color: var(--gold); }

/* --- Messages / center --- */
.center-msg {
  text-align: center; padding: 20px; color: var(--muted);
}
.center-msg h3 { color: var(--text); margin-bottom: 6px; }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--ember); box-shadow: var(--shadow-warm);
  padding: 10px 16px; border-radius: 10px; z-index: 200; font-size: 14px;
  animation: rise .3s ease;
}

/* --- Update banner --- */
.update-banner {
  position: fixed; left: 12px; right: 12px; bottom: 12px;
  background: var(--surface-2); border: 1px solid var(--ember);
  padding: 12px 14px; border-radius: 12px; z-index: 100;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-warm);
}

/* --- Install banner --- */
.install-banner {
  margin: 12px 16px 0; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border-soft);
  border-left: 4px solid var(--ember);
  border-radius: 12px;
}
.install-content { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.install-content h2 { font-size: 16px; }
.install-content p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.install-actions { display: flex; gap: 8px; }

/* --- Settings --- */
.settings { display: flex; flex-direction: column; gap: 10px; max-width: 500px; margin: 0 auto; }
.settings .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: 10px;
}
.settings .hint { color: var(--muted); font-size: 12px; text-align: center; }

/* Touch pad (for maze etc.) */
.pad {
  position: fixed; bottom: 20px; left: 12px; z-index: 50;
  display: grid; grid-template-columns: repeat(3, 46px); gap: 4px;
}
.pad button {
  background: var(--surface-2); color: var(--gold); font-size: 20px;
  border: 1px solid var(--border); border-radius: 10px;
  width: 46px; height: 46px; cursor: pointer;
}

/* --- Start / Campfire welcome screen --- */
#welcome {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background:
    radial-gradient(600px 400px at 50% 62%, rgba(255,140,66,.28) 0%, transparent 60%),
    radial-gradient(900px 600px at 50% 62%, rgba(255,140,66,.10) 0%, transparent 70%),
    var(--bg);
  padding: 30px 24px;
  transition: opacity .5s ease;
}
#welcome.hidden { opacity: 0; pointer-events: none; }
.welcome-inner { text-align: center; max-width: 480px; }
.welcome-inner h1 {
  font-size: 34px; margin-bottom: 8px;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(255,201,113,.4);
}
.welcome-inner p { color: var(--muted); font-size: 15px; margin-bottom: 22px; line-height: 1.5; }
.campfire-scene {
  width: 260px; height: 220px; margin: 0 auto 18px;
  position: relative;
}
.campfire-scene svg { width: 100%; height: 100%; }
.welcome-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.welcome-actions .btn { min-width: 200px; padding: 12px 20px; font-size: 15px; }

/* Flicker animation for embers */
@keyframes flicker {
  0%,100% { opacity: .9; transform: translateY(0) scale(1); }
  50%     { opacity: 1;  transform: translateY(-1px) scale(1.04); }
}
.flame { transform-origin: 50% 100%; animation: flicker 1.2s ease-in-out infinite; }
.flame.f2 { animation-duration: .9s; animation-delay: .2s; }
.flame.f3 { animation-duration: 1.4s; animation-delay: .4s; }

/* Utility */
canvas { display: block; margin: 0 auto; border-radius: 8px; background: #0e0904; touch-action: none; }
input[type="checkbox"] { accent-color: var(--ember); width: 20px; height: 20px; }

/* Mobile */
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { padding: 12px; }
  .tile .icon { width: 48px; height: 48px; }
  .tile .icon svg { width: 30px; height: 30px; }
  .page-title { font-size: 22px; }
}
