@font-face {
  font-family: "Noto Naskh Arabic";
  src: url("../assets/fonts/NotoNaskhArabic-Regular.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --ink: #2a241c;
  --paper: #fffaf3;
  --accent: #e07a4a;
  --chip: rgba(255, 250, 240, 0.88);
  --shadow: 0 4px 16px rgba(40, 30, 10, 0.15);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #1c2430;
  color: var(--ink);
  font-family: "Noto Naskh Arabic", "Noto Naskh Arabic Regular", serif;
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  background: #7ec8e8;
  touch-action: none;
}

@media (min-width: 520px) {
  #stage {
    width: min(420px, 100vw);
    height: min(844px, 100vh);
    border-radius: 28px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4), inset 0 0 0 8px #2a241c;
    overflow: hidden;
  }
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud-top, .needs, .hud-bottom, .dawn-btn, .winter-hay, .toast, .debug, .modal-layer {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}
.hud-top, .hud-bottom, .dawn-btn, .icon-btn, .modal-layer, .debug, .modal button, .modal input {
  pointer-events: auto;
}

.hud-top {
  top: calc(var(--safe-t) + 8px);
  inset-inline: 8px;
  display: flex;
  gap: 6px;
  justify-content: space-between;
  align-items: center;
}
.chip {
  background: var(--chip);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.chip.coins { font-weight: 700; }

.needs {
  top: calc(var(--safe-t) + 42px);
  inset-inline: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  pointer-events: none;
}
.need {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}
.need .bar {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.45);
  border-radius: 99px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}
.need .bar i, .need .bar .mid, .need .bar .low {
  display: block;
  height: 100%;
  width: 50%;
  background: #6bbf4a;
  border-radius: 99px;
}
.need .bar i.mid { background: #e0b03a; }
.need .bar i.low { background: #e07a4a; }

.winter-hay {
  top: calc(var(--safe-t) + 92px);
  inset-inline-start: 10px;
  background: var(--chip);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  box-shadow: var(--shadow);
}

.dawn-btn {
  bottom: calc(var(--safe-b) + 86px);
  inset-inline-end: 12px;
  min-height: 48px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: #2a3a6a;
  color: #fff;
  font: inherit;
  box-shadow: var(--shadow);
}

.hud-bottom {
  bottom: calc(var(--safe-b) + 10px);
  inset-inline: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.icon-btn {
  position: relative;
  min-width: 52px;
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  background: var(--chip);
  font-size: 22px;
  box-shadow: var(--shadow);
  font-family: inherit;
}
.icon-btn .badge {
  position: absolute;
  top: -4px;
  inset-inline-start: -4px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  min-width: 18px;
  height: 18px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.toast {
  top: 45%;
  inset-inline: 24px;
  text-align: center;
  background: rgba(42, 36, 28, 0.88);
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px;
  pointer-events: none;
  z-index: 8;
}

.modal-layer {
  inset: 0;
  background: rgba(20, 16, 12, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
  padding: 16px 16px calc(var(--safe-b) + 16px);
}
.modal-layer[hidden] { display: none !important; }
.modal {
  width: min(420px, 100%);
  max-height: 82%;
  overflow: auto;
  background: var(--paper);
  border-radius: 20px 20px 16px 16px;
  padding: 16px 18px 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
  pointer-events: auto;
}
.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.modal h2 { margin: 0 0 8px; font-size: 1.2rem; }
.modal .lead { margin: 0 0 12px; }
.modal .x, .modal button, .dawn-btn {
  font-family: inherit;
  font-size: 15px;
}
.modal button, .modal .x {
  min-height: 48px;
  padding: 8px 14px;
  border: 0;
  border-radius: 12px;
  background: #efe4d4;
  color: var(--ink);
}
.modal button.primary {
  background: #e07a4a;
  color: #fff;
  width: 100%;
}
.modal .ghost { background: transparent; }
.modal .row { display: flex; gap: 8px; justify-content: space-between; }
.modal .muted { opacity: 0.7; font-size: 13px; }
.modal input[type="text"] {
  width: 100%;
  min-height: 48px;
  font: inherit;
  font-size: 1.2rem;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid #d8c8b0;
  margin: 8px 0 16px;
  background: #fff;
}
.toggle {
  display: block;
  padding: 10px 0;
}
.toggle small { display: block; opacity: 0.7; font-size: 12px; }
.j-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.j-card {
  background: #f3e8d8;
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
  min-height: 64px;
}
.j-card.locked { opacity: 0.45; }
.letter {
  background: #f7efe2;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.shop-item, .sell-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #eee0d0;
}
.tasks { padding: 0; list-style: none; }
.tasks li { padding: 8px 0; }
.tasks li.done { opacity: 0.55; text-decoration: line-through; }

.debug {
  top: auto;
  bottom: calc(var(--safe-b) + 80px);
  inset-inline-start: 6px;
  background: rgba(20,20,20,0.82);
  color: #efe8d8;
  font-size: 11px;
  padding: 8px;
  border-radius: 10px;
  max-width: 70%;
  z-index: 9;
  pointer-events: auto;
  font-family: ui-monospace, monospace;
}
.debug button {
  font-size: 11px;
  min-height: 28px;
  margin: 2px;
  padding: 2px 6px;
  border: 0;
  border-radius: 6px;
  font-family: inherit;
}
.dbg-row { margin-top: 4px; }
.dbg-info { margin-top: 4px; opacity: 0.85; }

[hidden] { display: none !important; }
