:root {
  --wood: #3a2616; --wood2: #22140a; --wood3: #5a3b22;
  --gold: #e0b955; --gold2: #8a6a22; --ink: #f6ebce; --dim: #b9a77c;
  --stone: #6a6e74; --good: #5fd06a; --bad: #ee5a4a; --warn: #f0c24a;
  --serif: 'Cinzel', 'Trajan Pro', 'Palatino Linotype', Georgia, serif;
  --bh: 198px;
  --sans: 'Segoe UI', 'Trebuchet MS', Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; background: #05080e; font-family: var(--sans); color: var(--ink); user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; }
#view { position: absolute; left: 0; right: 0; top: 0; bottom: var(--bh); width: 100%; height: calc(100% - var(--bh)); display: block; background: #0a3b66; touch-action: none; }
.hidden { display: none !important; }

/* ---------- barra superior ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 40px; display: flex; align-items: center; gap: 6px; padding: 0 10px;
  background: linear-gradient(180deg, rgba(74,50,30,0.97), rgba(38,24,13,0.97));
  border-bottom: 2px solid var(--gold2); box-shadow: 0 2px 10px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,225,160,0.25);
  z-index: 5; pointer-events: auto;
}
#topbar .spacer { flex: 1; }
.res {
  display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px 0 6px; min-width: 92px;
  background: linear-gradient(180deg, #1d120a, #2d1c0f); border: 1px solid #0e0804; border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(224,185,85,0.35), inset 0 2px 5px rgba(0,0,0,0.6);
  font-weight: 700; font-size: 15px; letter-spacing: 0.3px;
}
.res img { width: 24px; height: 24px; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.7)); }
.res span { min-width: 34px; text-align: left; font-variant-numeric: tabular-nums; }
.res small { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--dim); background: rgba(0,0,0,0.35); padding: 1px 5px; border-radius: 8px; }
.res.pop.warn span { color: var(--bad); animation: pulse 1s infinite; }
.res.clock { min-width: 82px; }
@keyframes pulse { 50% { opacity: 0.55; } }
.tb {
  height: 30px; min-width: 30px; padding: 0 8px; display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
  background: linear-gradient(180deg, #5a3b22, #3a2616); color: var(--ink); font-weight: 700; font-size: 14px; border: 1px solid #0e0804; border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(224,185,85,0.4);
}
.tb img { width: 22px; height: 22px; }
.tb:hover { filter: brightness(1.25); }
.tb.off { opacity: 0.5; text-decoration: line-through; }
#btnIdle.has { animation: glow 1.4s infinite; }
@keyframes glow { 50% { box-shadow: inset 0 0 0 1px rgba(224,185,85,0.4), 0 0 10px 2px rgba(255,220,100,0.8); } }

/* ---------- avisos ---------- */
#toasts { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 6; }
.toast {
  padding: 6px 16px; border-radius: 4px; font-weight: 700; font-size: 14px; letter-spacing: 0.3px;
  background: rgba(24,15,8,0.92); border: 1px solid var(--gold2); box-shadow: 0 3px 10px rgba(0,0,0,0.5);
  animation: toastIn 0.25s ease-out; transition: opacity 0.3s, transform 0.3s;
}
.toast.out { opacity: 0; transform: translateY(-8px); }
.toast.bad { border-color: #b83a2e; color: #ffb4a8; }
.toast.good { border-color: #3a9a4a; color: #b6f3be; }
.toast.warn { border-color: #b8902e; color: #ffe49a; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }

/* ---------- painel inferior ---------- */
#bottom {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--bh); display: flex; align-items: stretch; z-index: 5;
  background: linear-gradient(180deg, #4b3320, #2a1a0e 40%, #1d1209);
  border-top: 3px solid var(--gold2); box-shadow: 0 -3px 14px rgba(0,0,0,0.6), inset 0 2px 0 rgba(255,225,160,0.22);
}
#bottom::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: linear-gradient(90deg, transparent, var(--gold), transparent); opacity: 0.8; }
#cmdWrap, #miniWrap, #infoWrap { padding: 10px; display: flex; align-items: center; justify-content: center; }
#cmdWrap { width: 352px; border-right: 2px solid #120a05; box-shadow: inset -1px 0 0 rgba(224,185,85,0.18); }
#miniWrap { width: 332px; border-left: 2px solid #120a05; box-shadow: inset 1px 0 0 rgba(224,185,85,0.18); }
#infoWrap { flex: 1; min-width: 0; align-items: stretch; }
#cmd { display: grid; grid-template-columns: repeat(5, 62px); grid-template-rows: repeat(3, 62px); gap: 5px; }
#mini {
  border: 3px solid #120a05; outline: 2px solid var(--gold2); background: #05080e; box-shadow: 0 0 14px rgba(0,0,0,0.7), inset 0 0 8px rgba(0,0,0,0.7); cursor: crosshair; border-radius: 2px;
}

.slot {
  position: relative; padding: 0; border: 2px solid #120a05; border-radius: 4px; background: #333; cursor: pointer; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(224,185,85,0.55), 0 2px 4px rgba(0,0,0,0.6);
  transition: transform 0.06s, filter 0.1s;
}
.slot.empty { background: rgba(0,0,0,0.22); box-shadow: inset 0 0 0 1px rgba(224,185,85,0.12); cursor: default; }
.slot.empty .ic { display: none; }
.slot .ic { width: 100%; height: 100%; display: block; image-rendering: auto; }
.slot .hk { position: absolute; left: 3px; top: 1px; font-size: 11px; font-weight: 800; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000, 1px 1px 0 #000; }
.slot .bd { position: absolute; right: 3px; bottom: 1px; font-size: 12px; font-weight: 800; color: #ffe27a; text-shadow: 0 0 3px #000, 1px 1px 0 #000; }
.slot .bd.gain { color: #9dff9d; } .slot .bd.cost { color: #ffd34d; }
.slot:not(.empty):hover { filter: brightness(1.2); box-shadow: inset 0 0 0 2px var(--gold), 0 0 8px rgba(255,220,120,0.6); }
.slot:not(.empty):active { transform: scale(0.95); }
.slot.disabled { filter: grayscale(0.85) brightness(0.65); }
.slot.disabled:hover { filter: grayscale(0.7) brightness(0.8); }

/* ---------- info ---------- */
#info {
  width: 100%; height: 100%; padding: 8px 12px; display: flex; gap: 12px; align-items: flex-start; overflow: hidden;
  background: linear-gradient(180deg, rgba(10,6,3,0.55), rgba(30,19,10,0.55)); border: 2px solid #120a05; border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(224,185,85,0.3), inset 0 4px 12px rgba(0,0,0,0.5);
}
.portrait { flex: 0 0 82px; width: 82px; height: 82px; border: 3px solid #120a05; outline: 2px solid var(--gold2); border-radius: 3px; overflow: hidden; background: #333; box-shadow: 0 2px 6px rgba(0,0,0,0.6); }
.portrait img { width: 100%; height: 100%; display: block; }
.portrait.res { background: linear-gradient(#5a5e66, #34373c); display: flex; align-items: center; justify-content: center; }
.portrait img.big { width: 60px; height: 60px; }
.ibody { flex: 1; min-width: 0; }
.iname { font-family: var(--serif); font-weight: 700; font-size: 20px; color: var(--gold); text-shadow: 0 2px 3px #000; letter-spacing: 0.5px; }
.iname em { font-family: var(--sans); font-style: normal; font-weight: 600; font-size: 12px; color: var(--dim); margin-left: 8px; }
.hpbar { position: relative; height: 16px; margin: 4px 0 6px; background: #120a05; border: 1px solid #000; border-radius: 3px; overflow: hidden; max-width: 340px; }
.hpbar div { height: 100%; transition: width 0.15s; }
.hpbar .g { background: linear-gradient(#7aef86, #2ea63e); } .hpbar .y { background: linear-gradient(#f4dc6a, #c29a1a); } .hpbar .r { background: linear-gradient(#f47a6a, #b02a1e); }
.hpbar span { position: absolute; inset: 0; text-align: center; font-size: 12px; font-weight: 700; line-height: 16px; text-shadow: 0 1px 2px #000; }
.stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--dim); margin: 2px 0; }
.stats b { color: var(--ink); font-weight: 700; }
.stats .mi { width: 15px; height: 15px; vertical-align: -3px; margin: 0 2px 0 6px; }
.task { font-size: 13px; color: #cfe6ff; margin-top: 4px; font-weight: 600; }
.dim { color: var(--dim); font-size: 12px; }
.carry { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; font-weight: 700; background: rgba(0,0,0,0.35); padding: 1px 8px 1px 4px; border-radius: 10px; }
.carry img { width: 18px; height: 18px; }
.pbar { height: 8px; background: #120a05; border-radius: 4px; overflow: hidden; margin-top: 5px; max-width: 340px; border: 1px solid #000; }
.pbar div { height: 100%; background: linear-gradient(#7ac8ff, #2a7ac8); }
.queue { display: flex; gap: 5px; margin-top: 6px; }
.qi { position: relative; width: 44px; height: 44px; border: 2px solid #120a05; outline: 1px solid var(--gold2); border-radius: 3px; overflow: hidden; cursor: pointer; background: #222; }
.qi img { width: 100%; height: 100%; display: block; }
.qi .qp { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(120,200,255,0.45); }
.qi:hover { outline-color: var(--bad); }
.multi { width: 100%; }
.msum { font-size: 13px; color: var(--dim); margin-bottom: 6px; }
.grid { display: flex; flex-wrap: wrap; gap: 4px; max-height: 128px; overflow: hidden; }
.tile { position: relative; width: 44px; height: 44px; border: 2px solid #120a05; outline: 1px solid var(--gold2); border-radius: 3px; overflow: hidden; cursor: pointer; background: #222; }
.tile:hover { outline-color: #fff; }
.tile img { width: 100%; height: 100%; display: block; }
.tile .tb { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 4px; background: #000; border-radius: 2px; overflow: hidden; }
.tile .tb i { display: block; height: 100%; } .tile .tb .g { background: #4fe060; } .tile .tb .y { background: #e8c53a; } .tile .tb .r { background: #e0453a; }
.idle-info { margin: auto; text-align: center; }
.idle-info .logo { font-family: var(--serif); font-weight: 900; font-size: 34px; color: var(--gold); letter-spacing: 6px; text-shadow: 0 3px 6px #000; }
.idle-info .hint { margin-top: 8px; font-size: 13px; line-height: 1.6; color: var(--dim); }

/* ---------- tooltip ---------- */
#tip {
  position: fixed; z-index: 20; max-width: 290px; padding: 8px 12px; pointer-events: none; opacity: 0; transition: opacity 0.1s;
  background: linear-gradient(180deg, rgba(38,24,13,0.98), rgba(18,11,6,0.98)); border: 2px solid var(--gold2); border-radius: 5px; box-shadow: 0 6px 18px rgba(0,0,0,0.7);
}
#tip.on { opacity: 1; }
#tip .tn { font-family: var(--serif); font-weight: 700; font-size: 16px; color: var(--gold); }
#tip .thk { color: var(--dim); font-family: var(--sans); font-size: 12px; }
#tip .tc { display: flex; gap: 12px; margin: 4px 0; font-weight: 700; font-size: 14px; }
#tip .tc img { width: 18px; height: 18px; vertical-align: -4px; margin-right: 3px; }
#tip .tc .lack { color: var(--bad); }
#tip .tc .sz { margin-left: auto; color: var(--dim); font-weight: 600; }
#tip .td { font-size: 13px; line-height: 1.4; color: #e6dbbd; }

/* ---------- telas ---------- */
.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; z-index: 30; background: radial-gradient(ellipse at center, rgba(8,18,34,0.78), rgba(2,6,12,0.94)); backdrop-filter: blur(3px); }
.screen.on { display: flex; }
#start { background: radial-gradient(ellipse at 50% 35%, rgba(24,60,100,0.55), rgba(2,6,14,0.97) 75%), linear-gradient(180deg, #06101e, #02050a); }
.card {
  width: min(520px, 92vw); padding: 28px 34px 26px; text-align: center; border-radius: 8px;
  background: linear-gradient(180deg, rgba(74,50,30,0.96), rgba(32,20,11,0.98)); border: 3px solid var(--gold2);
  box-shadow: 0 10px 40px rgba(0,0,0,0.8), inset 0 0 0 1px rgba(255,225,160,0.25), inset 0 0 40px rgba(0,0,0,0.5);
}
.card.small { width: min(420px, 92vw); } .card.wide { width: min(860px, 94vw); text-align: left; max-height: 92vh; overflow: auto; }
.crest { font-size: 46px; filter: drop-shadow(0 3px 4px #000); }
h1 { margin: 0; font-family: var(--serif); font-weight: 900; font-size: 58px; letter-spacing: 12px; color: var(--gold); text-shadow: 0 4px 0 #5a3a10, 0 8px 14px rgba(0,0,0,0.8); }
.sub { font-family: var(--serif); letter-spacing: 8px; color: var(--dim); margin: 2px 0 20px; text-transform: uppercase; font-size: 14px; }
h2 { font-family: var(--serif); color: var(--gold); margin: 0 0 12px; font-size: 28px; text-align: center; }
h3 { font-family: var(--serif); color: var(--gold); margin: 14px 0 4px; font-size: 16px; }
.card.wide h2 { text-align: center; }
#loadWrap { margin: 10px 0; }
#loadBar { height: 14px; background: #120a05; border: 2px solid #000; border-radius: 8px; overflow: hidden; box-shadow: inset 0 2px 6px rgba(0,0,0,0.7); }
#loadFill { height: 100%; width: 0%; background: linear-gradient(#ffe08a, #c9902a); box-shadow: 0 0 12px rgba(255,200,80,0.7); transition: width 0.15s; }
#loadText { margin-top: 8px; font-size: 13px; color: var(--dim); }
.opt { display: block; margin: 10px 0; font-size: 15px; cursor: pointer; }
.opt input { transform: scale(1.3); margin-right: 8px; accent-color: #d6aa4a; }
.seedrow { margin: 8px 0 16px; font-size: 14px; color: var(--dim); }
.seedrow input { width: 90px; padding: 4px 8px; background: #120a05; color: var(--ink); border: 1px solid var(--gold2); border-radius: 4px; font-size: 14px; text-align: center; }
button.big {
  display: block; width: 100%; margin: 8px 0 0; padding: 12px 18px; cursor: pointer; font-family: var(--serif); font-weight: 700; font-size: 20px; letter-spacing: 2px; color: #2a1a08;
  background: linear-gradient(180deg, #f6d683, #c9902a); border: 2px solid #5a3a0a; border-radius: 6px; box-shadow: 0 4px 0 #6a4a10, 0 6px 12px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.5);
  transition: transform 0.08s, filter 0.1s;
}
button.big:hover { filter: brightness(1.1); } button.big:active { transform: translateY(2px); box-shadow: 0 2px 0 #6a4a10; }
button.big.sec { background: linear-gradient(180deg, #7a5a3a, #4a3220); color: var(--ink); border-color: #1a0f06; box-shadow: 0 4px 0 #1a0f06, 0 6px 12px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.2); font-size: 17px; }
button.mini { padding: 2px 8px; cursor: pointer; background: #3a2616; color: var(--ink); border: 1px solid var(--gold2); border-radius: 4px; font-size: 15px; }
.tips { margin-top: 16px; font-size: 13px; color: var(--dim); line-height: 1.6; } .tips span { color: var(--gold); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 30px; }
.card ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.55; color: #e6dbbd; } .card li b { color: var(--gold); }
#end h1.win { color: #7dff8a; text-shadow: 0 4px 0 #1a5a22, 0 8px 14px rgba(0,0,0,0.8); } #end h1.lose { color: #ff7a6a; text-shadow: 0 4px 0 #5a1a12, 0 8px 14px rgba(0,0,0,0.8); }
#end h1 { font-size: 48px; letter-spacing: 8px; }
#end p { font-size: 16px; } #endStats { margin: 10px 0 14px; color: var(--dim); font-size: 14px; line-height: 1.7; } #endStats b { color: var(--ink); }

@media (max-width: 1100px) {
  #cmdWrap { width: 320px; } #cmd { grid-template-columns: repeat(5, 56px); grid-template-rows: repeat(3, 56px); }
  #miniWrap { width: 300px; } #mini { width: 270px !important; height: 135px !important; }
}

/* ---------- botões flutuantes (toque) ---------- */
.floatbtn { display: none; position: absolute; left: 8px; bottom: calc(var(--bh) + 8px); z-index: 6; padding: 8px 14px; font: 700 14px var(--sans); color: var(--ink); background: rgba(40,26,14,0.92); border: 2px solid var(--gold2); border-radius: 8px; box-shadow: 0 3px 10px rgba(0,0,0,0.5); }
body.touch.hassel .floatbtn { display: block; }
#placeBar { display: none; position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--bh) + 14px); z-index: 7; gap: 12px; }
#placeBar.on { display: flex; }
.pb { padding: 14px 22px; font: 800 18px var(--sans); border-radius: 10px; border: 2px solid #1a0f06; box-shadow: 0 4px 12px rgba(0,0,0,0.6); color: #fff; }
.pb.ok { background: linear-gradient(#5fd06a, #2e8a3a); } .pb.no { background: linear-gradient(#ee6a5a, #a8301e); }
body:not(.canfs) #btnFull { display: none; }
#mini { touch-action: none; }

/* ---------- celular: paisagem ---------- */
@media (pointer: coarse), (max-height: 560px) {
  :root { --bh: 112px; }
  #topbar { height: 36px; gap: 4px; padding: 0 max(8px, env(safe-area-inset-left)); }
  .res { height: 28px; min-width: 0; padding: 0 8px 0 4px; font-size: 14px; gap: 4px; }
  .res img { width: 20px; height: 20px; } .res span { min-width: 0; } .res small, .res.clock { display: none; }
  .tb { height: 28px; min-width: 32px; } #btnSound, #btnHelp { display: none; }
  #toasts { top: 42px; } .toast { font-size: 13px; padding: 4px 12px; }
  #bottom { padding-bottom: env(safe-area-inset-bottom); }
  #cmdWrap, #miniWrap, #infoWrap { padding: 4px; }
  #cmdWrap { width: auto; } #cmd { grid-template-columns: repeat(8, 44px); grid-template-rows: repeat(2, 44px); gap: 3px; }
  .slot .hk { display: none; } .slot .bd { font-size: 11px; }
  #miniWrap { width: auto; } #mini { width: 176px !important; height: 88px !important; border-width: 2px; }
  #info { padding: 4px 8px; gap: 8px; } .portrait { flex-basis: 52px; width: 52px; height: 52px; }
  .iname { font-size: 15px; } .iname em { display: none; } .hpbar { height: 13px; margin: 2px 0; } .hpbar span { font-size: 10px; line-height: 13px; }
  .stats { font-size: 11px; gap: 2px 8px; } .task { font-size: 11px; margin-top: 2px; } .stats span:nth-child(n+3) { display: none; }
  .qi, .tile { width: 34px; height: 34px; } .grid { max-height: 78px; } .msum { font-size: 11px; margin-bottom: 2px; }
  .idle-info .logo { font-size: 22px; letter-spacing: 4px; } .idle-info .hint { display: none; }
  .carry { font-size: 11px; }
  .card { padding: 16px 20px; } h1 { font-size: 40px; letter-spacing: 8px; } .sub { margin-bottom: 10px; }
  .card.wide { max-height: 88vh; } .cols { grid-template-columns: 1fr 1fr; } .card ul { font-size: 12px; line-height: 1.4; }
  button.big { padding: 10px 14px; font-size: 17px; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 430px) { #cmd { grid-template-columns: repeat(8, 40px); grid-template-rows: repeat(2, 40px); } :root { --bh: 104px; } #mini { width: 160px !important; height: 80px !important; } }

/* ---------- celular: retrato ---------- */
@media (pointer: coarse) and (orientation: portrait), (max-width: 640px) {
  :root { --bh: 196px; }
  #bottom { display: grid; grid-template-columns: 1fr auto; grid-template-rows: 84px auto; grid-template-areas: "info mini" "cmd cmd"; }
  #infoWrap { grid-area: info; } #miniWrap { grid-area: mini; } #cmdWrap { grid-area: cmd; border: 0; justify-content: center; }
  #cmd { grid-template-columns: repeat(8, calc((100vw - 16px - 21px) / 8)); grid-template-rows: repeat(2, 42px); }
  #cmd .slot { height: 42px; }
  #mini { width: 150px !important; height: 75px !important; }
  .res { padding: 0 5px 0 3px; font-size: 13px; } .res img { width: 17px; height: 17px; }
  .portrait { flex-basis: 46px; width: 46px; height: 46px; } .stats { display: none; }
  #placeBar { bottom: calc(var(--bh) + 10px); }
}
