/* Living City: one warm dark palette, large touch targets, nothing under 13px. */
:root {
  --bg: #17140f;
  --panel: #262019;
  --panel2: #342b21;
  --line: #4d4030;
  --text: #f3e9d5;
  --muted: #b5a88f;
  --accent: #e0a93b;
  --accent-ink: #261a05;
  --good: #8fbd72;
  --bad: #e0705a;
  --blue: #6fb0e0;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --kb: 0px;
  --vvh: 100dvh;
  --touch: 48px;
  --banner-h: 0px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

#app { position: fixed; inset: 0; height: 100vh; height: 100dvh; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
input { font: inherit; font-size: 16px; color: var(--text); -webkit-user-select: text; user-select: text; }

/* ---- HUD ---- */
#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10; pointer-events: none;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 12px) 0 calc(var(--safe-left) + 12px);
}
.hud-row { display: flex; justify-content: space-between; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 14px;
  background: rgba(23, 20, 15, .78); border: 1px solid var(--line); border-radius: 22px;
  font-size: 16px; font-weight: 600; white-space: nowrap; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#coins b { color: var(--accent); font-size: 18px; }
#energy {
  position: relative; margin-top: 8px; height: 20px; border-radius: 10px; overflow: hidden;
  background: rgba(23, 20, 15, .78); border: 1px solid var(--line);
}
#energy-fill { position: absolute; inset: 0 auto 0 0; width: 100%; background: var(--good); transition: width .3s, background .3s; }
#energy.low #energy-fill { background: var(--bad); }
#energy-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; text-shadow: 0 1px 2px #000; }

/* ---- controls ---- */
#menu {
  position: absolute; z-index: 10; right: calc(var(--safe-right) + 10px); bottom: calc(var(--safe-bottom) + 22px);
  display: flex; flex-direction: column; gap: 8px;
}
.menu-btn {
  position: relative; width: 62px; min-height: 58px; border-radius: 16px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; background: rgba(38, 32, 25, .9);
  border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}
.menu-btn i { font-style: normal; font-size: 22px; line-height: 1.1; }
.menu-btn span { font-size: 13px; font-weight: 600; }
.menu-btn:active, .round:active { background: var(--panel2); }
.menu-btn em { position: absolute; top: 6px; right: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }

#zoom { position: absolute; z-index: 10; right: calc(var(--safe-right) + 12px); top: calc(var(--safe-top) + 172px); display: flex; flex-direction: column; gap: 8px; }
.round {
  width: 48px; height: 48px; border-radius: 50%; font-size: 24px; font-weight: 700; line-height: 1;
  background: rgba(38, 32, 25, .9); border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}

#joy {
  position: absolute; z-index: 10; left: calc(var(--safe-left) + 18px); bottom: calc(var(--safe-bottom) + 24px);
  width: 136px; height: 136px; border-radius: 50%; touch-action: none;
  background: rgba(243, 233, 213, .1); border: 2px solid rgba(243, 233, 213, .35);
}
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%;
  background: rgba(224, 169, 59, .85); border: 2px solid #fff3d2; box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
  will-change: transform; pointer-events: none;
}

#chips {
  position: absolute; z-index: 11; left: calc(var(--safe-left) + 12px); right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bottom) + 172px); display: flex; flex-wrap: wrap-reverse; justify-content: center; gap: 8px;
  pointer-events: none;
}
.chip {
  pointer-events: auto; min-height: 46px; max-width: 100%; padding: 8px 16px; border-radius: 24px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .5); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- buttons ---- */
.btn {
  min-height: 46px; padding: 10px 16px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line);
  font-weight: 600; font-size: 16px; text-align: center;
}
.btn:active { filter: brightness(1.25); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { min-height: 44px; padding: 8px 14px; }
.btn:disabled, .btn.off { opacity: .45; pointer-events: none; }
.btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.btns .btn { flex: 1 1 140px; }

/* ---- sheets ---- */
.sheet {
  position: absolute; z-index: 20; left: 0; right: 0; bottom: var(--kb); margin: 0 auto; width: min(100%, 560px);
  max-height: min(80dvh, calc(var(--vvh) - var(--safe-top) - 12px)); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .55); padding-bottom: calc(var(--safe-bottom) + 6px);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px 8px 18px; }
.sheet-head h2 { margin: 0; font-size: 20px; line-height: 1.2; }
.close { width: 48px; height: 48px; border-radius: 50%; font-size: 20px; background: var(--panel2); }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; padding: 4px 18px 14px; }

.hint { color: var(--muted); margin: 8px 0 0; font-size: 15px; }
.sub { color: var(--muted); font-size: 15px; }
.section { margin: 16px 0 6px; font-size: 14px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.item.tap { cursor: pointer; }
.item .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.item .name { font-weight: 700; font-size: 17px; }
.item .meta { color: var(--muted); font-size: 15px; margin-top: 2px; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.price { color: var(--accent); font-weight: 700; white-space: nowrap; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 46px; height: 46px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); font-size: 22px; font-weight: 700; }
.stepper output { min-width: 34px; text-align: center; font-weight: 700; font-size: 18px; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.news-line { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.news-line time { display: block; color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* ---- dialogue ---- */
#dlg { z-index: 21; }
.dlg-title { min-width: 0; }
.dlg-title h2 { margin: 0; }
#dlg-sub { color: var(--muted); font-size: 15px; }
#dlg-log { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; padding: 4px 14px; flex: 1 1 auto; min-height: 90px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 17px; line-height: 1.38; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.msg.npc { align-self: flex-start; background: var(--panel2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: 15px; text-align: center; padding: 4px 8px; }
.msg .flag { display: inline-block; margin-left: 8px; min-width: 36px; min-height: 30px; padding: 0 6px; vertical-align: middle; color: var(--muted); font-size: 16px; opacity: .8; }
.typing span { display: inline-block; width: 8px; height: 8px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.1s infinite; }
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
#dlg-cards { padding: 0 14px; display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--bg); border: 2px solid var(--accent); border-radius: 14px; padding: 10px 12px; }
.card p { margin: 0 0 8px; font-size: 16px; }
.card .btns { margin-top: 0; }
#dlg-chips { display: flex; gap: 8px; padding: 8px 14px 0; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; touch-action: pan-x; }
#dlg-chips .btn { flex: 0 0 auto; border-radius: 22px; min-height: 44px; padding: 8px 16px; font-weight: 500; white-space: nowrap; }
#dlg-form { display: flex; gap: 8px; padding: 10px 14px 4px; }
#dlg-input { flex: 1 1 auto; min-width: 0; height: 48px; padding: 0 14px; border-radius: 24px; border: 1px solid var(--line); background: var(--bg); outline: none; }
#dlg-input:focus { border-color: var(--accent); }
#dlg-send { width: 56px; padding: 0; border-radius: 24px; }
#dlg.closed #dlg-form, #dlg.closed #dlg-chips { display: none; }

/* ---- goals, tabs, qualities ---- */
.tabs { display: flex; gap: 8px; margin: 4px 0 6px; }
.tab { flex: 1 1 0; min-height: 46px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); font-weight: 700; font-size: 16px; color: var(--muted); }
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.bar { height: 12px; margin-top: 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.bar.full i { background: var(--good); }
.item.dim { opacity: .6; }
.meta.dim { opacity: .75; font-size: 14px; }
.item.check { display: flex; gap: 10px; align-items: flex-start; }
.item.check .box { font-size: 20px; line-height: 1.2; color: var(--accent); }
.tag.good { color: var(--good); border-color: var(--good); }
.tag.bad { color: var(--bad); border-color: var(--bad); }
.tag.q-poor { color: var(--bad); }
.tag.q-good { color: var(--good); }
.tag.q-fine { color: var(--accent); border-color: var(--accent); }

/* ---- banners (invitation and hints): above the controls, never over the map centre ---- */
#banners {
  position: absolute; z-index: 15; left: calc(var(--safe-left) + 10px); right: calc(var(--safe-right) + 10px);
  top: calc(var(--safe-top) + 84px); display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.banner {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: 560px; width: 100%; margin: 0 auto;
  padding: 8px 8px 8px 14px; border-radius: 16px; background: rgba(38, 32, 25, .96); border: 1px solid var(--accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
}
.banner.hint-banner { border-color: var(--line); }
.bn-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 15px; line-height: 1.3; }
.bn-text b { font-size: 16px; color: var(--accent); }
.bn-btns { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

/* ---- crafting timing task ---- */
#timing { z-index: 22; }
#timing-body { padding: 4px 18px 10px; display: flex; flex-direction: column; gap: 12px; }
#timing-note { margin: 0; min-height: 22px; text-align: center; }
#timing-bar { position: relative; height: 44px; border-radius: 22px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; touch-action: none; }
#timing-zone { position: absolute; top: 0; bottom: 0; left: 40%; width: 20%; background: rgba(143, 189, 114, .28); border-left: 2px solid var(--good); border-right: 2px solid var(--good); }
#timing-marker { position: absolute; top: 3px; bottom: 3px; left: 0; width: 8px; margin-left: -4px; border-radius: 4px; background: var(--accent); box-shadow: 0 0 8px rgba(224, 169, 59, .8); }
#timing-marks i { position: absolute; top: 14px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; border: 2px solid var(--bg); }
#timing-marks i.good { background: var(--good); }
#timing-marks i.mid { background: var(--accent); }
#timing-marks i.bad { background: var(--bad); }
#timing-rounds { display: flex; justify-content: center; gap: 12px; }
#timing-rounds .dot { width: 16px; height: 16px; border-radius: 50%; background: var(--bg); border: 2px solid var(--line); }
#timing-rounds .dot.now { border-color: var(--accent); }
#timing-rounds .dot.good { background: var(--good); border-color: var(--good); }
#timing-rounds .dot.mid { background: var(--accent); border-color: var(--accent); }
#timing-rounds .dot.bad { background: var(--bad); border-color: var(--bad); }
#timing-tap { min-height: 88px; font-size: 22px; border-radius: 18px; touch-action: manipulation; }

/* ---- overlays ---- */
#night {
  position: absolute; inset: 0; z-index: 30; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(circle at 50% 20%, #1d2547, #0b0e1d 70%); color: #eef0ff;
  padding: calc(var(--safe-top) + 34px) 22px calc(var(--safe-bottom) + 28px); text-align: center;
}
#night > div { max-width: 520px; margin: 0 auto; }
#night h2 { font-size: 28px; margin: 6px 0 10px; }
#night p { color: #b8bfe6; font-size: 17px; margin: 0 0 18px; }
#night h3 { margin: 26px 0 4px; font-size: 15px; letter-spacing: .06em; text-transform: uppercase; color: #8f98cf; text-align: left; }
#night ul { list-style: none; margin: 0 0 24px; padding: 0; text-align: left; }
#night li { padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, .12); font-size: 16px; }
#night li time { color: #8f98cf; font-size: 13px; display: block; }
#night .moon { font-size: 64px; }
#night .btn { min-width: 220px; }
.spinner { width: 40px; height: 40px; margin: 24px auto; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .2); border-top-color: #fff; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toasts {
  position: absolute; z-index: 40; left: 12px; right: 12px; top: calc(var(--safe-top) + 112px + var(--banner-h));
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  max-width: 520px; padding: 10px 16px; border-radius: 14px; font-size: 16px; font-weight: 600; text-align: center;
  background: rgba(38, 32, 25, .95); border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
  animation: toast-in .2s ease-out;
}
.toast.error { border-color: var(--bad); }
.toast.ok { border-color: var(--good); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

#banner {
  position: absolute; z-index: 50; left: 0; right: 0; top: 0; padding: calc(var(--safe-top) + 10px) 16px 10px;
  text-align: center; background: var(--bad); color: #fff; font-weight: 700; font-size: 16px;
}

@media (min-width: 700px) {
  .sheet { border-radius: 20px; bottom: calc(var(--kb) + 12px); border-bottom: 1px solid var(--line); }
  #chips { bottom: 190px; }
}
@media (max-height: 480px) {
  #zoom { top: calc(var(--safe-top) + 64px); right: calc(var(--safe-right) + 84px); flex-direction: row; }
  #joy { width: 112px; height: 112px; }
  #chips { bottom: 140px; }
  .menu-btn { min-height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
