:root {
  --ink: #fff8ee;
  --muted: rgba(255, 248, 238, 0.72);
  --stroke: rgba(255, 255, 255, 0.95);
  --panel: rgba(16, 10, 8, 0.42);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Avenir Next", "SF Pro Rounded", ui-rounded, system-ui, sans-serif;
  color: var(--ink);
  background: #000;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

body.is-playing {
  overflow: hidden;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

.hud {
  position: fixed;
  left: 50%;
  top: max(16px, env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  z-index: 4;
  width: min(720px, calc(100vw - 96px));
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
  align-items: center;
  gap: 6px 18px;
  padding: 12px 20px;
  border-radius: 12px;
  border: 3px solid #fff;
  text-align: center;
  font-weight: 700;
  line-height: 1.2;
  pointer-events: none;
}

.hud div {
  font-size: clamp(16px, 3.4vw, 24px);
  white-space: nowrap;
}

.hud[hidden],
.circle-btn[hidden],
.hint[hidden] {
  display: none !important;
}

.circle-btn {
  appearance: none;
  border: 3px solid #fff;
  background: rgba(240, 79, 28, 0.9);
  color: #fff;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  position: fixed;
  z-index: 5;
  cursor: pointer;
  padding: 0;
}

#pause-btn {
  transform: translate(-50%, -50%);
}

#quit-btn {
  top: max(16px, env(safe-area-inset-top, 0px));
  right: max(14px, env(safe-area-inset-right, 0px));
}

#info-btn {
  top: max(16px, env(safe-area-inset-top, 0px));
  right: max(14px, env(safe-area-inset-right, 0px));
}

.circle-btn svg {
  width: 22px;
  height: 22px;
  display: block;
  margin: 0 auto;
}

#pause-btn .play-icon { display: none; }
#pause-btn.is-paused .pause-icon { display: none; }
#pause-btn.is-paused .play-icon { display: block; }

.home {
  position: relative;
  z-index: 3;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(20px, env(safe-area-inset-top, 0px)) 16px max(28px, env(safe-area-inset-bottom, 0px));
  touch-action: manipulation;
}

.home.hidden { display: none; }

.logo {
  width: min(70vw, 360px);
  height: auto;
  margin: 8px 0 10px;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.45));
}

.home h1 {
  margin: 4px 0 16px;
  font-size: clamp(22px, 6vw, 30px);
  text-shadow: 0 2px 8px rgba(0,0,0,.45);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(280px, 86vw);
}

.play-btn {
  appearance: none;
  border: 3px solid #fff;
  border-radius: 12px;
  background: rgba(255,255,255,.15);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 22px;
  min-height: 48px;
  padding: 10px 16px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.play-btn.ghost {
  background: rgba(0,0,0,.28);
}

.app-store { margin: 18px 0 8px; }
.app-store img { width: 120px; height: 40px; }

.share-puzzle, .share-buttons {
  margin: 8px 0 12px;
  text-align: center;
}

.share-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.share-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.share-btn, .share-btn-small {
  appearance: none;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255,255,255,.16);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.share-btn-small { width: 36px; height: 36px; }

.game-promo {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(420px, 94vw);
  margin: 6px 0;
  padding: 10px 12px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--ink);
  background: rgba(0,0,0,.32);
  border: 1px solid rgba(255,255,255,.16);
}

.game-promo img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.game-promo strong { display: block; }
.game-promo em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-style: normal;
}

.site-footer {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.site-footer a, .footer-btn {
  color: var(--ink);
  background: none;
  border: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 12px 14px;
  min-height: 44px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 12px;
  overflow: auto;
  touch-action: manipulation;
}

.overlay.hidden, .hidden { display: none !important; }

.card {
  background: rgba(131, 87, 208, 0.9);
  color: #fff;
  border-radius: 18px;
  padding: 22px 20px 18px;
  width: min(520px, 100%);
  max-height: min(92vh, 92dvh);
  overflow: auto;
  border: 3px solid #fff;
  display: flex;
  flex-direction: column;
}

.card.narrow { width: min(380px, 100%); }
.card.settings { background: rgba(246, 140, 15, 0.9); }
.card.about { background: rgba(16, 158, 230, 0.9); }
.card.scores { background: rgba(140, 209, 44, 0.9); }
.card.more { background: rgba(89, 89, 242, 0.9); }
.card.confirm { background: rgba(240, 79, 28, 0.9); }
.card.level { background: rgba(255, 210, 0, 0.92); color: #24180a; }
.card.level a, .card.level .play-btn { color: #24180a; }

.card h1, .card h2 {
  margin: 0 0 10px;
  text-align: center;
}

.card p, .card li { line-height: 1.45; }

.card .stack {
  width: 100%;
  margin-top: 16px;
}

.help-list { margin: 8px 0 12px; padding-left: 1.2em; }

.settings-card {
  background: rgba(0,0,0,.12);
  border-radius: 14px;
  padding: 8px 12px;
  margin: 0 0 12px;
}

.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.16);
}

.toggle:last-child { border-bottom: 0; }

.toggle input {
  width: 44px;
  height: 24px;
}

.scores-table {
  width: 100%;
  border-collapse: collapse;
}

.scores-table td {
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,.2);
}

.about-copy a { color: #ffd200; }

#fx {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.fx-msg {
  position: absolute;
  left: 50%;
  top: 28%;
  font-weight: 800;
  font-size: clamp(22px, 6vw, 34px);
  text-shadow: 0 2px 10px rgba(0,0,0,.55);
  white-space: nowrap;
}

.fx-msg.streak { top: 20%; }
.fx-msg.life { top: 16%; }
.fx-msg.paused { top: 28%; }

.hint {
  position: fixed;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom, 0px) + 18px));
  transform: translateX(-50%);
  z-index: 6;
  text-align: center;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0,0,0,.5);
  pointer-events: none;
}

.hint-line {
  width: min(220px, 60vw);
  height: 0;
  border-top: 3px solid #fff;
  margin: 0 auto 8px;
  position: relative;
}

.hint-line::before, .hint-line::after {
  content: "";
  position: absolute;
  top: -8px;
  border: 7px solid transparent;
}

.hint-line::before { left: -4px; border-right-color: #fff; }
.hint-line::after { right: -4px; border-left-color: #fff; }

.toast {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 40;
  background: rgba(20, 18, 28, .92);
  border: 1px solid rgba(255,255,255,.16);
  color: #fff;
  padding: 14px 22px;
  border-radius: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.toast.show { opacity: 1; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000 center / cover no-repeat;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading.hidden { display: none; }
.loading img { width: min(70vw, 280px); }
.loading p { margin: 0; color: var(--muted); }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: #f04f1c;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hp { position: absolute; left: -9999px; }
.form-error { color: #ffe08a; }
.optional { color: var(--muted); }

label { display: block; margin: 10px 0 6px; }

input[type="text"], input[type="email"], textarea {
  width: 100%;
  font: inherit;
  color: #24180a;
  background: rgba(255,255,255,.88);
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
}

.page-static {
  touch-action: manipulation;
  background: #1a0f08 url("../img/background_game.jpg") center / cover no-repeat;
}

.page-static .play {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  min-height: 100vh;
  display: flex;
  align-items: center;
}

@media (max-width: 420px) {
  .circle-btn { width: 46px; height: 46px; }
  .play-btn { font-size: 20px; }
}
