/* Gauragangur - "pappír og vaxlitir" útlit.
   Litir eru skilgreindir efst svo auðvelt sé að breyta. */
:root {
  --ui: 1;          /* stærð leiksins á skjánum (1 = 540px hár) - sett í js/renderer.js */
  --game-top: 0px;  /* hvar leikurinn byrjar á skjánum */
  --paper: #fbf5e6;
  --paper-dark: #efe3c6;
  --ink: #2e2218;
  --ink-soft: #6b5a48;
  --accent: #e8573a;
  --accent-2: #3b82c4;
  --good: #4caf50;
  --bg: #2b2118;
  --touch: 1;
  --font: "Patrick Hand", "Chalkboard SE", "Comic Sans MS", cursive;
}

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

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: var(--bg);
  font-family: var(--font);
  color: var(--ink);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}
button, .slot, .tbtn, canvas { touch-action: manipulation; }
#game-canvas, #touch-controls, #touch-controls * { touch-action: none; }

#app {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
#game-canvas { display: block; background: #fbf6ea; }

.hidden { display: none !important; }

/* ---------- Pappírs-spjöld ---------- */
.paper {
  background: var(--paper);
  background-image:
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(90, 140, 200, 0.12) 31px 32px);
  border: 3px solid var(--ink);
  border-radius: 14px 10px 16px 9px;
  box-shadow: 6px 8px 0 rgba(0, 0, 0, 0.35);
}
.panel {
  padding: 22px 26px;
  max-width: min(560px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; align-items: stretch;
  touch-action: pan-y;
}
.panel > * { flex-shrink: 0; }
.panel.narrow { max-width: min(420px, 94vw); }
.panel.wide { max-width: min(720px, 96vw); width: 720px; }
.panel h1 { margin: 0 0 6px; text-align: center; font-size: 40px; letter-spacing: 1px; }
.panel h2 { margin: 0; font-size: 28px; }
.panel h3 { margin: 12px 0 2px; font-size: 21px; }
.panel h3 small { font-size: 15px; color: var(--ink-soft); }
.tilt-l { transform: rotate(-2deg); }
.tilt-r { transform: rotate(1.2deg); }

.screen {
  position: fixed; inset: 0;
  z-index: 30;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at 50% 40%, rgba(43, 33, 24, 0.15), rgba(43, 33, 24, 0.55));
}
.screen.dim { background: rgba(30, 22, 14, 0.62); }
#screen-loading { background: var(--bg); }

/* ---------- Takkar ---------- */
button {
  font-family: var(--font);
  font-size: 23px;
  color: var(--ink);
  background: #ffd84a;
  border: 3px solid var(--ink);
  border-radius: 12px 9px 13px 8px;
  padding: 8px 18px;
  cursor: pointer;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.08s;
}
button:hover { transform: rotate(-1deg) scale(1.03); }
button:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }
button.secondary { background: #e9e1cf; }
button.small { font-size: 18px; padding: 5px 12px; }
.row { display: flex; gap: 12px; justify-content: center; }

.img-btn { display: flex; align-items: center; gap: 12px; background: #fffdf6; padding: 4px 12px; }
.img-btn img { height: 54px; border-radius: 6px; }
.img-btn span { font-size: 26px; }

/* ---------- Aðalvalmynd ---------- */
.menu-layout { display: flex; gap: 28px; align-items: center; justify-content: center; flex-wrap: wrap; }
.menu-art img { height: min(58vh, 420px); filter: drop-shadow(6px 8px 0 rgba(0, 0, 0, 0.35)); }
.menu-panel { min-width: 300px; }
.version { text-align: center; color: var(--ink-soft); font-size: 14px; }
.scheme-pick { display: flex; flex-direction: column; gap: 6px; align-items: center; margin-top: 6px; padding-top: 10px; border-top: 2px dashed var(--ink-soft); }
.scheme-pick span { font-size: 19px; color: var(--ink-soft); }
.scheme-pick button { font-size: 19px; padding: 5px 12px; background: #e9e1cf; }
.scheme-pick button.on { background: #ffd84a; outline: 3px solid var(--ink); }
.gold { font-size: 22px; font-weight: bold; color: #8a5a00; }

/* ---------- Kortið ---------- */
.map-screen { background: transparent; pointer-events: none; flex-direction: column; justify-content: space-between; }
.map-screen .paper { pointer-events: auto; }
.map-top { padding: 6px 22px; font-size: 28px; display: flex; gap: 16px; align-items: center; }
.map-bottom { padding: 10px 20px; display: flex; gap: 18px; align-items: center; flex-wrap: wrap; justify-content: center; max-width: 96vw; }
#map-info { font-size: 22px; min-width: 260px; }
#map-info small { display: block; font-size: 17px; color: var(--ink-soft); }
.title { font-size: 46px; color: var(--accent); text-shadow: 2px 2px 0 var(--ink); -webkit-text-stroke: 1px var(--ink); }
@media (max-height: 560px) {
  .menu-art img { height: 46vh; }
  .menu-panel button { font-size: 20px; padding: 5px 14px; }
  .img-btn img { height: 40px; }
  .title { font-size: 36px; }
}
@media (max-width: 760px) { .menu-art { display: none; } }

/* ---------- Hleðslustika ---------- */
.loadbar { height: 22px; border: 3px solid var(--ink); border-radius: 10px; background: #fff; overflow: hidden; }
#load-fill { height: 100%; width: 0; background: repeating-linear-gradient(-45deg, #ffd84a 0 10px, #ffb02e 10px 20px); }

/* ---------- HUD-takkar uppi í horni ---------- */
#hud-buttons {
  position: fixed; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right));
  z-index: 20; display: flex; gap: 10px;
}
.hud-btn {
  width: calc(58px * var(--ui)); height: calc(58px * var(--ui)); padding: 0;
  font-size: calc(30px * var(--ui)); line-height: 1; border-width: calc(3px * var(--ui));
  background: rgba(251, 245, 230, 0.92);
  border-radius: 50% 46% 52% 48%;
}

/* ---------- Snertistýring ---------- */
#touch-controls { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
/* HÆGRI: hopp + árásir */
#touch-actions {
  position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  width: calc(250px * var(--touch)); height: calc(210px * var(--touch));
  pointer-events: none;
}
/* VINSTRI: labba fram og til baka */
#touch-move {
  position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom));
  display: flex; gap: calc(18px * var(--touch));
  pointer-events: none;
}
.tbtn {
  position: absolute; pointer-events: auto;
  width: calc(78px * var(--touch)); height: calc(78px * var(--touch));
  border-radius: 50%; padding: 0;
  background: rgba(251, 245, 230, 0.78);
  overflow: hidden;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.35);
  touch-action: none;
}
.tbtn:hover { transform: none; }
.tbtn.down { transform: scale(0.92); background: rgba(255, 216, 74, 0.95); }
.tbtn img { width: 70%; height: 70%; object-fit: contain; pointer-events: none; }
.tbtn .lbl { position: absolute; right: 8%; bottom: 4%; font-size: calc(18px * var(--touch)); color: var(--ink); }
.tbtn .cd {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(rgba(30, 20, 10, 0.6) var(--cd, 0%), transparent 0);
  pointer-events: none;
}
.tbtn.big { width: calc(100px * var(--touch)); height: calc(100px * var(--touch)); background: rgba(120, 190, 255, 0.82); }
.tbtn.big b { font-size: calc(24px * var(--touch)); }
.tbtn.small { width: calc(60px * var(--touch)); height: calc(60px * var(--touch)); }
#tb-jump { right: 0; bottom: 0; }
#tb-attack1 { right: calc(112px * var(--touch)); bottom: calc(4px * var(--touch)); }
#tb-attack2 { right: calc(40px * var(--touch)); bottom: calc(112px * var(--touch)); }
#tb-shield { right: calc(148px * var(--touch)); bottom: calc(112px * var(--touch)); }

.tbtn.move {
  position: static;
  width: calc(96px * var(--touch)); height: calc(96px * var(--touch));
  border-radius: 22px 18px 24px 16px;
  background: rgba(251, 245, 230, 0.82);
}
.tbtn.move b { font-size: calc(40px * var(--touch)); line-height: 1; }

/* Víxla hliðum (örvhentir) */
#touch-controls.lefty #touch-actions { right: auto; left: max(14px, env(safe-area-inset-left)); transform: scaleX(-1); }
#touch-controls.lefty #touch-actions .tbtn > * { transform: scaleX(-1); }
#touch-controls.lefty #touch-move { left: auto; right: max(14px, env(safe-area-inset-right)); }

/* ---------- Skilaboð ---------- */
#toasts {
  position: fixed; top: calc(var(--game-top) + 74px * var(--ui)); left: 50%; transform: translateX(-50%);
  z-index: 25; display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none; width: min(820px, 94vw);
}
/* Stærðir fylgja skjánum: litlar í síma, stórar á tölvu (clamp = min, æskilegt, max) */
.toast {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 12px 8px 14px 9px;
  padding: calc(8px * var(--ui)) calc(20px * var(--ui));
  font-size: calc(26px * var(--ui)); border-width: calc(3px * var(--ui));
  box-shadow: 4px 5px 0 rgba(0, 0, 0, 0.3);
  display: flex; align-items: center; gap: 14px; text-align: center;
  animation: toastIn 0.25s ease-out;
}
.toast img { height: calc(42px * var(--ui)); }
.toast.out { opacity: 0; transform: translateY(-10px); transition: all 0.4s; }
@keyframes toastIn { from { transform: translateY(-16px) scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }

#banner {
  position: fixed; top: 22%; left: 50%; transform: translateX(-50%) rotate(-2deg);
  z-index: 24; text-align: center; pointer-events: none;
  animation: bannerIn 3s ease-out forwards;
}
#banner .b-title { font-size: calc(52px * var(--ui)); color: #fff; -webkit-text-stroke: 2px var(--ink); text-shadow: 3px 4px 0 var(--ink); }
#banner .b-sub { font-size: calc(24px * var(--ui)); color: #ffe066; text-shadow: 2px 2px 0 var(--ink); }
@keyframes bannerIn {
  0% { opacity: 0; transform: translateX(-50%) rotate(-2deg) scale(0.6); }
  12% { opacity: 1; transform: translateX(-50%) rotate(-2deg) scale(1.05); }
  20% { transform: translateX(-50%) rotate(-2deg) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

#dialog {
  position: fixed; left: 0; right: 0; bottom: 6%;
  z-index: 26; display: flex; justify-content: center; padding: 0 16px;
}
.d-box { max-width: min(calc(680px * var(--ui)), 94vw); width: 100%; padding: calc(14px * var(--ui)) calc(20px * var(--ui)); display: flex; flex-direction: column; gap: calc(8px * var(--ui)); border-width: calc(3px * var(--ui)); }
.d-text { font-size: calc(24px * var(--ui)); line-height: 1.25; min-height: calc(56px * var(--ui)); }
.d-next { font-size: calc(21px * var(--ui)); padding: calc(6px * var(--ui)) calc(16px * var(--ui)); border-width: calc(3px * var(--ui)); }
.d-next { align-self: flex-end; }

/* ---------- Stillingar ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.tab { font-size: 19px; padding: 4px 14px; background: #e9e1cf; }
.tab.active { background: #ffd84a; }
.tab-page { display: flex; flex-direction: column; gap: 10px; padding: 8px 2px; min-height: 220px; }
.tab-page label { display: flex; justify-content: space-between; align-items: center; gap: 14px; font-size: 21px; }
.tab-page label.check { justify-content: flex-start; }
.tab-page select, .tab-page input[type=range] { font-family: var(--font); font-size: 19px; min-width: 220px; }
.tab-page input[type=checkbox] { width: 24px; height: 24px; }
#keybinds { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; font-size: 20px; }
#keybinds button { font-size: 18px; padding: 3px 12px; min-width: 90px; background: #fff; }
#keybinds button.waiting { background: #ffd84a; }

/* ---------- Vistunarhólf ---------- */
#slots-list { display: flex; flex-direction: column; gap: 8px; }
.slot-row { display: flex; align-items: center; gap: 12px; text-align: left; background: #fff; font-size: 19px; }
.slot-row .s-name { font-weight: bold; min-width: 120px; }
.slot-row .s-info { color: var(--ink-soft); flex: 1; }

/* ---------- Bakpoki / persóna ---------- */
.inv-panel { max-width: min(980px, 98vw); width: 980px; }
.inv-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.inv-tabs { display: flex; gap: 8px; }
.inv-tabs .tab { font-size: 22px; padding: 4px 16px; }
.nero-info { width: 200px; font-size: 17px; line-height: 1.25; }
.slot.action::after { content: attr(data-key); position: absolute; left: 3px; top: 1px; font-size: 13px; font-weight: bold; color: var(--ink); }
.x { width: 46px; height: 46px; padding: 0; font-size: 24px; }
.inv-body { display: flex; gap: 18px; flex-wrap: wrap; }
.char-col { display: flex; flex-direction: column; gap: 8px; width: 330px; max-width: 100%; }
.char-col .equip { min-height: 260px; }
.equip { display: flex; gap: 8px; align-items: center; }
.eq-col { display: flex; flex-direction: column; gap: 8px; }
#doll-canvas { width: 180px; height: 245px; background: #fffdf6; border: 2px dashed var(--ink-soft); border-radius: 10px; }
.slot {
  width: 62px; height: 62px; position: relative;
  border: 3px solid var(--ink); border-radius: 10px 7px 11px 8px;
  background: #e8dcc0; display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 12px; color: var(--ink-soft); text-align: center; line-height: 1;
}
.slot img { max-width: 84%; max-height: 84%; pointer-events: none; }
.slot.filled { background: #fffdf6; }
.slot.selected { outline: 4px solid var(--accent); outline-offset: 1px; }
.slot .ph { opacity: 0.55; font-size: 12px; hyphens: manual; overflow-wrap: break-word; padding: 2px; }
#inv-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; font-size: 19px; padding: 6px 10px; background: rgba(255, 255, 255, 0.6); border-radius: 10px; border: 2px solid var(--ink-soft); }
#inv-stats b { float: right; }
.bag-col { flex: 1; min-width: 280px; display: flex; flex-direction: column; gap: 10px; }
#bag-grid { display: grid; grid-template-columns: repeat(auto-fill, 58px); gap: 6px; }
#bag-grid .slot { width: 58px; height: 58px; }
.tooltip { min-height: 128px; background: #fffdf6; border: 2px solid var(--ink); border-radius: 10px; padding: 8px 12px; font-size: 19px; }
.tooltip h4 { margin: 0 0 4px; font-size: 23px; }
.tooltip .tier { font-size: 16px; }
.tooltip ul { margin: 4px 0; padding-left: 18px; }
.tooltip .better { color: #2e9e3a; }
.tooltip .worse { color: #c0392b; }
.tooltip .hint { color: var(--ink-soft); margin: 0; }
.tooltip .row { justify-content: flex-start; margin-top: 6px; }
.tooltip button { font-size: 19px; padding: 4px 14px; }

#bc-stats { font-size: 21px; text-align: center; }
#bc-next { text-align: center; font-size: 21px; margin: 4px 0; }

@media (max-height: 600px) {
  .panel { padding: 12px 16px; }
  .panel h1 { font-size: 32px; }
  .slot { width: 52px; height: 52px; }
  #bag-grid .slot { width: 50px; height: 50px; }
  #bag-grid { grid-template-columns: repeat(auto-fill, 50px); }
  #doll-canvas { width: 140px; height: 190px; }
  .tooltip { min-height: 100px; font-size: 17px; }
}

/* ---------- Sími / lítill skjár: allt minnkar með skjánum ---------- */
@media (max-height: 500px), (max-width: 700px) {
  button { font-size: clamp(14px, 4.2vh, 20px); padding: 4px 12px; }
  .panel { padding: 8px 12px; gap: 6px; max-height: 96vh; }
  .panel h1 { font-size: clamp(20px, 7vh, 30px); margin: 0; }
  .panel h2 { font-size: clamp(17px, 5vh, 24px); }
  .title { font-size: clamp(24px, 8vh, 36px); }
  .tab-page label, #map-info, .slot-row { font-size: clamp(14px, 4vh, 19px); }
  .tooltip { font-size: clamp(13px, 3.8vh, 17px); min-height: 70px; }
  .tooltip h4 { font-size: clamp(15px, 4.4vh, 20px); }
  .map-top { font-size: clamp(16px, 5vh, 24px); padding: 3px 12px; }
  .map-bottom { padding: 5px 10px; gap: 8px; }
  #bc-stats, #bc-next, #confirm-text { font-size: clamp(14px, 4vh, 19px); }
  .scheme-pick span { font-size: 14px; }
}
/* ---------- Fjársjóðskortið ---------- */
.treasure-panel { max-width: min(1060px, 97vw); width: 1060px; align-items: center; }
#treasure-canvas { width: auto; height: auto; max-width: 100%; max-height: 60vh; border-radius: 10px; }
#treasure-info { font-size: clamp(14px, min(3.6vh, 2.4vw), 21px); text-align: center; margin: 2px 0; }
/* GODMODE-takkinn (bara á meðan leikurinn er í smíðum) */
.godmode-btn { background: #2e2218; color: #ffd84a; font-size: 18px; padding: 4px 12px; }
