:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #173346;
  --cream: #fffaf0;
  --gold: #d99b2b;
  --gold-dark: #a86517;
  --panel: rgba(255, 250, 240, 0.92);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #102a39;
}

body {
  display: grid;
  place-items: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.game-shell {
  position: relative;
  width: min(100vw, calc(100vh * 390 / 844));
  height: min(100vh, calc(100vw * 844 / 390));
  max-width: 520px;
  overflow: hidden;
  background: #77c8ec;
  box-shadow: 0 0 70px rgba(0, 0, 0, 0.38);
  isolation: isolate;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--ink);
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

.icon-button {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: 20px;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(23, 51, 70, 0.18);
  border-radius: 50%;
  background: rgba(255,255,255,.58);
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(39, 72, 86, 0.12);
  cursor: pointer;
}

.icon-button svg { width: 22px; fill: currentColor; }
.icon-button .sound-off { display: none; }
.icon-button.muted .sound-on { display: none; }
.icon-button.muted .sound-off { display: block; }

.brand { margin-top: clamp(48px, 9vh, 78px); text-align: center; }
.eyebrow {
  margin: 0 0 6px;
  color: #97611a;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .28em;
}

h1, h2 {
  margin: 0;
  color: var(--ink);
  font-weight: 950;
  line-height: .9;
  letter-spacing: .06em;
  text-shadow: 0 3px 0 rgba(255,255,255,.3);
}

h1 { font-size: 54px; }
h1[lang="ar"] { font-family: Tahoma, Arial, sans-serif; font-size: 61px; letter-spacing: 0; }
.arabic-mark { margin: 8px 0 0; color: var(--gold-dark); font-family: Tahoma, Arial, sans-serif; font-size: 17px; font-weight: 700; }
.hero-space { flex: 1; min-height: 260px; }

.home-actions { width: min(100%, 310px); display: grid; gap: 12px; }
.primary-button, .secondary-button {
  min-height: 58px;
  border-radius: 18px;
  font-weight: 900;
  letter-spacing: .11em;
  cursor: pointer;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  border: 1px solid #efc35f;
  color: #fff;
  background: linear-gradient(180deg, #eab84a, #c7851d);
  box-shadow: 0 8px 0 #955b12, 0 14px 25px rgba(91, 54, 13, .24), inset 0 1px rgba(255,255,255,.45);
}

.primary-button:active { transform: translateY(5px); box-shadow: 0 3px 0 #955b12; }
.button-arrow { font-size: 25px; line-height: 0; }
.secondary-button { border: 1px solid rgba(23,51,70,.18); color: var(--ink); background: #eaf2ef; }

.best-card {
  min-height: 57px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border: 1px solid rgba(23,51,70,.12);
  border-radius: 17px;
  background: rgba(255,255,255,.72);
  box-shadow: 0 7px 20px rgba(37,67,80,.11);
}

.best-card span { font-size: 11px; font-weight: 800; letter-spacing: .13em; opacity: .66; }
.best-card strong { font-size: 25px; }
.control-hint { margin: 3px 0 0; text-align: center; font-size: 10px; font-weight: 800; letter-spacing: .22em; opacity: .55; }

.hud {
  position: absolute;
  z-index: 2;
  top: max(17px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}

.health-panel, .score-panel {
  border: 1px solid rgba(255,255,255,.54);
  border-radius: 15px;
  background: rgba(16, 42, 57, .78);
  color: #fff;
  box-shadow: 0 6px 18px rgba(13,38,50,.17);
  backdrop-filter: blur(7px);
}

.health-panel { flex: 1; padding: 9px 11px 10px; }
.health-copy { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 9px; font-weight: 900; letter-spacing: .13em; }
.health-copy strong { color: #b9ec9d; }
.health-track { position: relative; height: 16px; overflow: hidden; border-radius: 9px; background: rgba(255,255,255,.18); }
.health-fill { width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #69bd55, #9bd964); transition: width .16s linear, background .2s; }
.health-track span { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 9px; font-weight: 950; text-shadow: 0 1px 2px #173346; }
.health-panel.critical { animation: criticalPulse .75s ease-in-out infinite alternate; border-color: rgba(255,128,115,.85); }
.health-panel.critical .health-fill { background: linear-gradient(90deg, #d82828, #ff5a46); }
.health-panel.critical .health-copy strong { color: #ff8678; }

@keyframes criticalPulse { to { box-shadow: 0 0 23px rgba(241, 58, 48, .66); } }

.score-panel { min-width: 102px; padding: 9px 12px; text-align: right; }
.score-panel span { display: block; font-size: 9px; font-weight: 800; letter-spacing: .16em; opacity: .7; }
.score-panel strong { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 2px; font-size: 23px; line-height: 1; }
.score-panel strong b { font: inherit; }
.coin-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  border: 2px solid #ffe28a;
  border-radius: 50%;
  background: linear-gradient(135deg, #fff0a5, #e3a62b 67%);
  box-shadow: inset 0 0 0 2px rgba(148,82,9,.22), 0 1px 4px rgba(0,0,0,.22);
}

.tap-prompt {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 61%;
  transform: translate(-50%, -50%);
  padding: 10px 17px;
  border-radius: 30px;
  color: #fff;
  background: rgba(16,42,57,.72);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .17em;
  pointer-events: none;
  animation: promptPulse 1.1s ease-in-out infinite alternate;
}

@keyframes promptPulse { to { transform: translate(-50%, -50%) scale(1.06); opacity: .73; } }

.game-over-screen {
  justify-content: center;
  background: rgba(10, 28, 38, .48);
  backdrop-filter: blur(4px);
}

.result-card {
  width: min(100%, 330px);
  padding: 28px 23px 24px;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 28px;
  text-align: center;
  background: var(--panel);
  box-shadow: 0 24px 55px rgba(8,28,38,.34);
  animation: resultIn .34s cubic-bezier(.2,.85,.25,1.2);
}

@keyframes resultIn { from { opacity: 0; transform: translateY(22px) scale(.94); } }
.result-card h2 { font-size: 34px; }
.total-result { margin: 22px 0 17px; }
.total-result > span { display: block; font-size: 10px; font-weight: 850; letter-spacing: .2em; opacity: .56; }
.total-result > strong { display: block; font-size: 54px; line-height: 1.05; }
.total-result small { font-size: 10px; font-weight: 800; letter-spacing: .13em; color: #8b5b18; }
.score-breakdown { margin: 0 0 20px; padding: 13px 16px; border-radius: 15px; background: #edf0e8; }
.score-breakdown div { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid rgba(23,51,70,.09); }
.score-breakdown div:last-child { border-bottom: 0; }
.score-breakdown dt { font-size: 10px; font-weight: 800; letter-spacing: .08em; opacity: .64; }
.score-breakdown dd { margin: 0; font-size: 13px; font-weight: 900; }
.result-actions { display: grid; grid-template-columns: 1fr .72fr; gap: 10px; }
.result-actions .primary-button, .result-actions .secondary-button { min-height: 54px; }

@media (max-height: 680px) {
  .brand { margin-top: 36px; }
  .hero-space { min-height: 205px; }
  .result-card { padding-top: 22px; padding-bottom: 19px; }
  .total-result { margin: 14px 0 10px; }
  .score-breakdown { margin-bottom: 13px; }
}

@media (max-width: 340px) {
  h1 { font-size: 48px; }
  h1[lang="ar"] { font-size: 55px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
