/* Primal Frontier: the look of the title screen, the HUD and the windows.
   The world itself is drawn on the canvas by js/render.js. */

:root {
  --bg: #16210f;
  --panel: rgba(22, 30, 18, 0.94);
  --panel2: #26341f;
  --line: #4a6034;
  --text: #f2ecd8;
  --muted: #b6b29a;
  --accent: #f0b43a;
  --accent2: #6fbf4a;
  --danger: #d4483a;
  font-family: "Baloo 2", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.warn { color: #ff9a7a; }

.screen { position: fixed; inset: 0; }
.card { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; }

.btn {
  background: var(--accent); color: #2a1a06; border: 0; border-radius: 10px; padding: 8px 16px; font-weight: 800;
  cursor: pointer; box-shadow: 0 3px 0 #9a6a14;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #9a6a14; }
.btn:disabled { opacity: 0.45; cursor: default; filter: grayscale(0.6); }
.btn.alt { background: var(--panel2); color: var(--text); box-shadow: 0 3px 0 #10180c; border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; box-shadow: 0 3px 0 #7a2018; }
.btn.small { padding: 4px 10px; font-size: 0.9rem; border-radius: 8px; }
.btn.tiny { padding: 0 8px; font-size: 0.85rem; border-radius: 6px; box-shadow: none; }

/* ---- Title */

#title { overflow-y: auto; }
#title-art { position: fixed; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.title-box { position: relative; max-width: 640px; margin: 0 auto; padding: 28px 16px 40px; display: flex; flex-direction: column; gap: 12px; }
h1 { margin: 0; font-size: clamp(2.4rem, 9vw, 4.2rem); line-height: 1; letter-spacing: 2px; color: #fff3c8; text-shadow: 0 4px 0 #6a3a10, 0 8px 18px rgba(0,0,0,0.5); text-align: center; }
h1 span { color: var(--accent); }
.tag { text-align: center; margin: 0; font-size: 1.15rem; text-shadow: 0 2px 4px #000; }
.title-box h2 { margin: 6px 0 0; text-shadow: 0 2px 4px #000; }
.who { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.who strong { font-size: 1.3rem; color: var(--accent); }
.worlds { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.world { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.world b { font-size: 1.2rem; display: block; }
.how summary { cursor: pointer; font-weight: 700; }
.how li { margin: 4px 0; }
footer { text-align: center; text-shadow: 0 1px 3px #000; }
footer a { color: #fff3c8; }

/* ---- Game */

#cv { position: absolute; inset: 0; image-rendering: pixelated; cursor: crosshair; touch-action: none; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud .bars, #hud .status, #hud .quest, #hud .toasts, #hud .mountbar, #hud .clock { pointer-events: none; }

.bars { position: absolute; left: 10px; top: 10px; width: 210px; display: flex; flex-direction: column; gap: 3px; }
.bar { position: relative; height: 16px; background: rgba(0,0,0,0.55); border: 1px solid rgba(255,255,255,0.15); border-radius: 5px; overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; transition: width 0.2s; }
.bar span { position: absolute; left: 6px; top: 0; font-size: 0.72rem; line-height: 15px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.bar.low { animation: pulse 0.8s infinite alternate; }
@keyframes pulse { to { border-color: #ff5040; } }
.lvl { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; text-shadow: 0 1px 2px #000; }
.lvl .xp { flex: 1; height: 6px; background: rgba(0,0,0,0.55); border-radius: 3px; overflow: hidden; }
.lvl .xp i { display: block; height: 100%; background: #b080ff; }
.wt { font-size: 0.72rem; text-shadow: 0 1px 2px #000; }
.wt.heavy { color: #ff9a7a; }
.status { position: absolute; left: 10px; top: 140px; font-size: 0.85rem; text-shadow: 0 1px 3px #000; max-width: 260px; }
.quest { position: absolute; left: 10px; top: 166px; width: 230px; background: rgba(0,0,0,0.45); border-radius: 10px; padding: 6px 10px; font-size: 0.85rem; }
.quest:empty { display: none; }
.quest p { margin: 2px 0; }
.quest ul { margin: 2px 0 0; padding-left: 18px; }
.quest li.done, li.done { color: #9ef07a; }
.mountbar { position: absolute; left: 50%; transform: translateX(-50%); bottom: 82px; background: rgba(0,0,0,0.6); border-radius: 8px; padding: 2px 10px; font-size: 0.85rem; white-space: nowrap; }

.corner { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#mini { width: 132px; height: 132px; border: 2px solid var(--line); border-radius: 10px; image-rendering: pixelated; background: #14243a; }
.clock { font-size: 0.78rem; text-shadow: 0 1px 3px #000; text-align: right; max-width: 200px; }
.toolbar { position: absolute; right: 10px; top: 186px; display: flex; flex-direction: column; gap: 4px; }
.toolbar button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 1.15rem; cursor: pointer; }
.toolbar button:hover { background: var(--panel2); }

.hotbar { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 4px; padding: 4px; background: rgba(0,0,0,0.45); border-radius: 12px; }
.buildbar { position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; font-size: 0.85rem; max-width: calc(100vw - 32px); }

.slot {
  position: relative; width: 52px; height: 52px; border-radius: 8px; border: 2px solid #3a4a2c; background-color: rgba(30, 40, 24, 0.9);
  background-repeat: no-repeat; background-position: center; background-size: 40px 40px; image-rendering: pixelated; cursor: pointer; padding: 0;
}
.slot:hover { border-color: #8aa060; }
.slot.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(240,180,58,0.4); }
.slot.picked { border-color: #6fd0ff; box-shadow: 0 0 0 2px rgba(111,208,255,0.5); }
.slot.hb { background-color: rgba(48, 58, 30, 0.95); }
.slot .n { position: absolute; right: 3px; bottom: 0; font-size: 0.8rem; font-weight: 800; text-shadow: 0 1px 2px #000, 0 0 2px #000; }
.slot .key { position: absolute; left: 3px; top: 0; font-size: 0.65rem; color: var(--muted); }
.slot .hint { font-size: 0.65rem; color: var(--muted); }
.slot .dur { position: absolute; left: 4px; bottom: 3px; height: 3px; background: #7ae07a; border-radius: 2px; max-width: calc(100% - 8px); }
.slot .dur.water { background: #4ab0ff; }

.toasts { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; width: min(480px, calc(100vw - 32px)); }
.toast { background: rgba(10, 14, 8, 0.85); border-left: 4px solid #8aa0c0; border-radius: 8px; padding: 4px 12px; font-size: 0.9rem; transition: opacity 0.8s; }
.toast.good { border-color: var(--accent2); }
.toast.warn { border-color: var(--danger); }
.toast.fade { opacity: 0; }
.cards { position: absolute; right: 60px; bottom: 80px; display: flex; flex-direction: column; gap: 6px; width: min(300px, calc(100vw - 32px)); }
.ask p { margin: 0 0 6px; }

/* ---- Windows */

.win { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.35); padding: 12px; }
.win-box { width: min(760px, 100%); max-height: calc(100vh - 24px); display: flex; flex-direction: column; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; }
.win-box header { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.win-box h2 { margin: 0; font-size: 1.2rem; }
.x { background: none; border: 0; font-size: 1.3rem; cursor: pointer; }
.win-body { overflow-y: auto; padding: 10px 14px 14px; }
.win-body h3 { margin: 10px 0 4px; font-size: 1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, 52px); gap: 4px; }
.grid.eq { grid-template-columns: repeat(4, 52px); }
.grid.one { grid-template-columns: 52px; }
.split { display: grid; grid-template-columns: 1fr 230px; gap: 14px; }
.actions { margin-top: 8px; min-height: 40px; }
.actions p { margin: 2px 0 6px; }
.stats { list-style: none; padding: 0; margin: 0; }
.stats li { display: flex; justify-content: space-between; padding: 1px 0; }
.minibars { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.tab { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px; cursor: pointer; }
.tabs.small .tab { font-size: 0.8rem; }
.tab.on { background: var(--accent); color: #2a1a06; font-weight: 800; }
.recipes { display: flex; flex-direction: column; gap: 4px; }
.recipe, .tame { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.04); border-radius: 8px; padding: 4px 8px; }
.recipe .info, .tame .info { flex: 1; display: flex; flex-direction: column; }
.icon { width: 40px; height: 40px; flex: none; background-size: contain; background-repeat: no-repeat; background-position: center; image-rendering: pixelated; }
.cost { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 0.8rem; }
.cost .ok { color: #9ef07a; }
.cost .no { color: #ff9a7a; }
.portrait { display: block; width: 100%; height: 110px; background-size: contain; background-repeat: no-repeat; background-position: center; image-rendering: pixelated; }
.mapwrap { display: flex; justify-content: center; }
.bigmap { width: min(100%, 72vh); aspect-ratio: 1; image-rendering: pixelated; border-radius: 8px; cursor: crosshair; }
.people { list-style: none; padding: 0; margin: 0 0 8px; }
.people li { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.emotes { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; }
.note { white-space: pre-wrap; font-size: 1.05rem; background: #efe2bd; color: #3a2a12; padding: 12px 14px; border-radius: 6px; }
.keys { padding-left: 18px; }

.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(20, 0, 0, 0.55); padding: 16px; }
.overlay .card { max-width: 420px; text-align: center; }
#conn { background: rgba(0, 0, 0, 0.6); }

/* ---- Phone controls */

.touch { position: absolute; inset: 0; pointer-events: none; }
.joy { position: absolute; left: 0; bottom: 0; width: 45%; height: 55%; pointer-events: auto; touch-action: none; }
.knob { position: fixed; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; background: rgba(255,255,255,0.25); border: 2px solid rgba(255,255,255,0.5); display: none; }
.knob.on { display: block; }
.tbtns { position: absolute; right: 12px; bottom: 80px; display: grid; grid-template-columns: repeat(2, 56px); gap: 8px; pointer-events: auto; }
.tb { width: 56px; height: 56px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.4); background: rgba(0,0,0,0.45); font-size: 1.2rem; font-weight: 800; touch-action: none; }
.tb.big { grid-column: span 2; width: 72px; height: 72px; justify-self: center; font-size: 1.6rem; background: rgba(200, 60, 40, 0.55); }
.tb.on { background: rgba(240, 180, 58, 0.6); }

@media (max-width: 700px), (max-height: 500px) {
  .split { grid-template-columns: 1fr; }
  .slot { width: 44px; height: 44px; background-size: 32px 32px; }
  .grid { grid-template-columns: repeat(auto-fill, 44px); }
  .grid.eq { grid-template-columns: repeat(4, 44px); }
  .bars { width: 150px; }
  .quest { width: 170px; font-size: 0.75rem; top: 150px; }
  .quest p { display: none; }
  .status { top: 128px; font-size: 0.75rem; }
  #mini { width: 96px; height: 96px; }
  .toolbar { top: 140px; }
  .toolbar button { width: 36px; height: 36px; font-size: 1rem; }
  .hotbar { gap: 2px; }
  .win { padding: 0; }
  .win-box { max-height: 100vh; height: 100%; border-radius: 0; }
}
body.is-touch .hotbar { bottom: 4px; }
body.is-touch .hotbar .slot { width: 40px; height: 40px; background-size: 28px 28px; }
body.is-touch .buildbar { bottom: 56px; }
body.is-touch .mountbar { bottom: 56px; }
body.is-touch .cards { right: 140px; }
/* On a phone the menu buttons sit in a row along the top, out of the way of
   the action buttons. */
body.is-touch .toolbar { top: 8px; right: 116px; flex-direction: row; }
body.is-touch .toasts { top: 52px; }
@media (max-height: 500px) {
  body.is-touch .tbtns { bottom: 56px; grid-template-columns: repeat(2, 48px); gap: 6px; }
  body.is-touch .tb { width: 48px; height: 48px; }
  body.is-touch .tb.big { width: 60px; height: 60px; }
  body.is-touch .quest ul { display: none; }
  body.is-touch .clock { max-width: 110px; }
}
