/* ============================================================
   HUD — clock, location, coins, toolbar, side buttons,
   dialogue box, toasts and tooltips.
   ============================================================ */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start;
  padding: calc(8px + env(safe-area-inset-top)) 12px 0; pointer-events: none;
}
#hud > * { pointer-events: auto; }
.hud-card {
  background: rgba(255, 253, 247, 0.92); border-radius: 14px; padding: 6px 12px;
  box-shadow: var(--shadow); font-weight: 700; font-size: 0.9rem;
}
#hud-time { font-size: 1.2rem; }
.hud-card.coins { font-size: 1.1rem; align-self: stretch; display: flex; align-items: center; }
#hud-flags { display: flex; flex-wrap: wrap; gap: 6px; max-width: 46vw; }
.flag { background: rgba(255, 253, 247, 0.85); border-radius: 999px; padding: 4px 10px; font-size: 0.8rem; font-weight: 700; box-shadow: var(--shadow); }
.flag.warn { background: #ffe0d8; color: #a04030; }
.flag.buff { background: #f0e6ff; }
.hud-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

#objective {
  position: fixed; top: calc(76px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 9;
  background: #fff3c4; border: 2px solid var(--gold); border-radius: 999px; padding: 8px 18px;
  font-weight: 700; box-shadow: var(--shadow); max-width: 92vw; text-align: center; font-size: 0.9rem;
}
#mode-banner {
  position: fixed; bottom: calc(100px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 11;
  background: rgba(61, 53, 80, 0.9); color: #fff; border-radius: 999px; padding: 6px 8px 6px 18px;
  display: flex; gap: 8px; align-items: center; font-weight: 700; box-shadow: var(--shadow); max-width: 94vw;
}

/* ---- toolbar ---- */
#toolbar {
  position: fixed; bottom: calc(10px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 10;
  display: flex; gap: 6px; padding: 8px; background: rgba(255, 248, 236, 0.94);
  border-radius: 22px; box-shadow: var(--shadow); border: 3px solid #f0e2c8;
}
.tool, .side {
  font: inherit; font-size: 0.72rem; font-weight: 700; color: var(--ink); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  width: 64px; height: 64px; border-radius: 16px; border: 2px solid transparent; background: #fff; position: relative;
}
.tool span, .side span { font-size: 1.5rem; line-height: 1.1; }
.tool.active { border-color: var(--wood); background: #fff3dc; box-shadow: inset 0 -3px 0 var(--wood); }
.tool img { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; background: #fff; border-radius: 50%; box-shadow: var(--shadow); }

#sidebar {
  position: fixed; right: calc(10px + env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); z-index: 10;
  display: flex; flex-direction: column; gap: 6px; padding: 6px; background: rgba(255, 248, 236, 0.9);
  border-radius: 20px; box-shadow: var(--shadow); max-height: calc(100vh - 200px); overflow-y: auto;
}
.side { width: 60px; height: 56px; }
.side.glow { box-shadow: 0 0 0 3px var(--gold); }
.side.festival { background: #ffe8f3; }

/* ---- dialogue ---- */
#dialog {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  width: min(640px, 94vw); display: flex; gap: 12px; align-items: center;
  background: var(--paper); border: 3px solid #f0e2c8; border-radius: 22px; padding: 12px 16px;
  box-shadow: 0 10px 34px rgba(40, 40, 80, 0.3); cursor: pointer; animation: rise 0.25s ease-out;
}
#dialog-portrait { width: 72px; height: 72px; flex: none; border-radius: 50%; }
.dialog-body { flex: 1; min-width: 0; }
#dialog-name { font-weight: 800; color: var(--wood-dark); font-size: 0.9rem; }
#dialog-text { font-size: 1.02rem; line-height: 1.45; margin-top: 2px; }
#dialog-choices { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
#dialog-next { color: var(--wood); animation: bob 1s ease-in-out infinite; }

/* ---- toasts & tooltip ---- */
#toasts { position: fixed; left: 12px; bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 50; display: flex; flex-direction: column; gap: 6px; pointer-events: none; max-width: min(380px, 70vw); }
.toast { background: rgba(61, 53, 80, 0.92); color: #fff; padding: 8px 14px; border-radius: 14px; font-weight: 600; font-size: 0.88rem; box-shadow: var(--shadow); animation: slidein 0.25s ease-out; transition: opacity 0.5s, transform 0.5s; }
.toast.discover { background: linear-gradient(135deg, #8a6ad8, #d86aa8); }
.toast.warn { background: #c0584a; }
.toast.out { opacity: 0; transform: translateX(-20px); }
#tooltip { position: fixed; z-index: 100; max-width: 280px; background: var(--paper); border: 2px solid #eadfcc; border-radius: 12px; padding: 8px 10px; box-shadow: var(--shadow); font-size: 0.85rem; pointer-events: none; }

#fade { position: fixed; inset: 0; z-index: 60; background: #1a1a3a; opacity: 0; pointer-events: none; transition: opacity 0.8s; }
#fade.on { opacity: 1; }

/* ---- phones ---- */
@media (max-width: 720px) {
  #hud { padding: calc(6px + env(safe-area-inset-top)) 8px 0; gap: 6px; }
  .hud-card { padding: 4px 8px; font-size: 0.78rem; }
  #hud-time { font-size: 1rem; }
  #hud-flags { order: 10; max-width: 100%; }
  #hud-flags .flag { font-size: 0.72rem; }
  #objective { top: auto; bottom: calc(150px + env(safe-area-inset-bottom)); font-size: 0.8rem; }
  #sidebar { top: auto; transform: none; bottom: calc(86px + env(safe-area-inset-bottom)); right: 8px; left: 8px; flex-direction: row; overflow-x: auto; max-height: none; padding: 4px; }
  .side { width: 52px; height: 48px; flex: none; font-size: 0.62rem; }
  .side span { font-size: 1.2rem; }
  #toolbar { gap: 4px; padding: 5px; left: 8px; right: 8px; transform: none; justify-content: space-between; }
  .tool { width: auto; flex: 1; height: 56px; font-size: 0.62rem; }
  .tool span { font-size: 1.3rem; }
  #dialog { bottom: calc(150px + env(safe-area-inset-bottom)); }
  #dialog-portrait { width: 56px; height: 56px; }
  #toasts { bottom: calc(210px + env(safe-area-inset-bottom)); }
  #mode-banner { bottom: calc(150px + env(safe-area-inset-bottom)); font-size: 0.8rem; }
}

/* Hide the interface during the storm and the wake-up scene. */
body.cinematic #hud, body.cinematic #sidebar, body.cinematic #toolbar, body.cinematic #objective { opacity: 0; pointer-events: none; transition: opacity 0.6s; }
