/* ICOR — tema base. Escuro, sujo, legível. Retrato, toque, áreas seguras do iPhone. */
:root {
  --bg: #0b0908;
  --bg2: #14100e;
  --panel: #1b1613;
  --panel2: #241c17;
  --line: #3a2d24;
  --line2: #54402f;
  --ink: #e8dfd2;        /* osso */
  --ink2: #b9ab98;
  --muted: #847665;
  --blood: #a3121b;
  --blood2: #d42a2a;
  --rust: #b0592a;
  --gold: #c9a24a;
  --ichor: #d8b23a;      /* icor: dourado doentio */
  --rot: #7d9a3a;        /* chaga */
  --bile: #9fb53a;
  --bone: #e9e1cf;
  --cold: #6f8fa6;
  --good: #8fb36b;
  --warn: #d9a23a;
  --bad: #e0483c;
  --dread: #7a5fa8;
  --corr: #b04fb0;
  --stam: #c9a24a;
  --hp: #b8231f;
  --light: #e8a83a;

  --r: 10px;
  --r2: 14px;
  --gap: 10px;
  --pad: 14px;
  --tap: 46px;
  --fs: 16px;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --vh: 1vh;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: var(--fs); line-height: 1.4;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
body { position: fixed; inset: 0; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
textarea, input { -webkit-user-select: text; user-select: text; }

#app {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto;
  background:
    radial-gradient(120% 60% at 50% -10%, #2a120f 0%, transparent 60%),
    radial-gradient(100% 50% at 50% 120%, #1a1406 0%, transparent 70%),
    var(--bg);
  box-shadow: 0 0 0 1px #000, 0 0 60px #000;
}

/* ---------------- HUD ---------------- */
.hud {
  flex: 0 0 auto;
  padding: calc(var(--sat) + 6px) calc(var(--sar) + 10px) 6px calc(var(--sal) + 10px);
  background: linear-gradient(#0d0a09f2, #0d0a09d9);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.hud[hidden] { display: none; }
#app.no-hud .screen { padding-top: calc(var(--sat) + 12px); }

/* ---------------- tela ---------------- */
.screen {
  flex: 1 1 auto;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px calc(var(--sar) + 12px) 16px calc(var(--sal) + 12px);
  outline: none;
}
#app:not(.has-dock) .screen { padding-bottom: calc(var(--sab) + 16px); }

/* ---------------- dock (ações do polegar) ---------------- */
.dock {
  flex: 0 0 auto;
  padding: 8px calc(var(--sar) + 10px) calc(var(--sab) + 8px) calc(var(--sal) + 10px);
  background: linear-gradient(#0d0a09d9, #0d0a09);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 5;
}
.dock[hidden] { display: none; }
.dock-row { display: flex; gap: 8px; }
.dock-row > .btn { flex: 1 1 0; }

/* ---------------- botões ---------------- */
.btn {
  appearance: none; -webkit-appearance: none;
  min-height: var(--tap); padding: 8px 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--r);
  border: 1px solid var(--line2);
  background: linear-gradient(#2a211b, #1d1713);
  color: var(--ink);
  text-align: center; cursor: pointer;
  touch-action: manipulation;
  transition: transform .06s ease, filter .1s;
  position: relative;
  min-width: 0;
}
.btn:active { transform: translateY(1px) scale(.985); filter: brightness(1.25); }
.btn-body { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.btn-label { font-weight: 600; letter-spacing: .01em; overflow-wrap: anywhere; }
.btn-sub { font-size: 12px; color: var(--ink2); font-family: var(--mono); line-height: 1.2; margin-top: 2px; overflow-wrap: anywhere; }
.btn-icon { font-size: 18px; line-height: 1; }
.btn-badge { position: absolute; top: -6px; right: -6px; background: var(--blood); color: #fff; font-size: 11px; border-radius: 9px; padding: 1px 6px; font-family: var(--mono); }
.btn-primary { background: linear-gradient(#5a1a14, #3d100c); border-color: #8a2a1f; }
.btn-blood { background: linear-gradient(#7a0f15, #4f080d); border-color: var(--blood2); }
.btn-danger { background: linear-gradient(#4a0c0c, #2a0606); border-color: #8f1d1d; color: #ffd5cf; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.btn-icon.btn, .btn-ghost.btn-icon { min-width: var(--tap); }
.btn-wide { width: 100%; }
.btn-left { justify-content: flex-start; text-align: left; }
.btn-left .btn-body { align-items: flex-start; }
.btn.is-disabled { opacity: .42; filter: grayscale(.6); }
.btn.is-selected { border-color: var(--ichor); box-shadow: inset 0 0 0 1px var(--ichor); }

/* ---------------- barras ---------------- */
.bar { position: relative; height: 16px; background: #0a0807; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--hp); transition: width .25s ease; }
.bar-text { position: relative; font: 11px/14px var(--mono); text-align: center; color: #fff; text-shadow: 0 1px 2px #000; }
.bar-hp .bar-fill { background: linear-gradient(90deg, #6d0f0c, var(--hp)); }
.bar-stam .bar-fill { background: linear-gradient(90deg, #6e5420, var(--stam)); }
.bar-dread .bar-fill { background: linear-gradient(90deg, #3d2c5c, var(--dread)); }
.bar-corr .bar-fill { background: linear-gradient(90deg, #5a2059, var(--corr)); }
.bar-light .bar-fill { background: linear-gradient(90deg, #6b3d0e, var(--light)); }
.bar-chaga .bar-fill { background: linear-gradient(90deg, #3c4a14, var(--rot)); }
.bar-xp .bar-fill { background: linear-gradient(90deg, #5e4a12, var(--ichor)); }
.bar-part .bar-fill { background: #8a6a4a; }

/* ---------------- chips ---------------- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line2); background: #1a1411; color: var(--ink2); margin: 2px 4px 2px 0; white-space: nowrap; }
.chip-bad { border-color: #7a1d1d; color: #ffb4aa; background: #2a0d0b; }
.chip-good { border-color: #4d6a32; color: #cfe8b0; background: #141c0e; }
.chip-warn { border-color: #7a5a1d; color: #f3d48e; background: #241a0b; }
.chip-info { border-color: #3d5566; color: #bcd6e8; background: #0f171d; }
.chip-rot { border-color: #55691f; color: #d2e48a; background: #161c09; }
.chip-blood { border-color: var(--blood); color: #ffc9c4; background: #2a0507; }
.chip-corr { border-color: #6a2a69; color: #f0c2ef; background: #1f0b1f; }

/* ---------------- painéis / texto ---------------- */
.panel { background: linear-gradient(#1b1613, #161210); border: 1px solid var(--line); border-radius: var(--r2); padding: 12px; margin: 0 0 12px; }
.panel-title { margin: 0 0 8px; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
h1, h2, h3 { font-weight: 700; margin: 0 0 8px; }
h1 { font-size: 28px; letter-spacing: .08em; }
h2 { font-size: 20px; }
.prose p { margin: 0 0 10px; color: var(--ink); }
.prose p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.t-good { color: var(--good); } .t-bad { color: var(--bad); } .t-warn { color: var(--warn); }
.t-ichor { color: var(--ichor); } .t-rot { color: var(--rot); } .t-blood { color: var(--blood2); }
.t-dread { color: #a78ad6; } .t-corr { color: #dc8cdc; } .t-info { color: #9cc2dc; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dashed #2a221c; font-size: 15px; }
.kv:last-child { border-bottom: 0; }
.kv-k { color: var(--ink2); }
.kv-v { font-family: var(--mono); text-align: right; }
.row { display: flex; gap: 8px; align-items: center; }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.center { text-align: center; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

/* ---------------- grade / abas ---------------- */
.grid { display: grid; gap: 8px; }
.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 0 0 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; min-height: 40px; padding: 6px 12px; background: #15110e; border: 1px solid var(--line); border-radius: 8px; color: var(--ink2); position: relative; }
.tab.is-active { color: var(--ink); border-color: var(--rust); background: #2a1a12; }
.tab-badge { margin-left: 6px; font-size: 11px; background: var(--blood); color: #fff; border-radius: 8px; padding: 0 5px; }

/* ---------------- modal / folha ---------------- */
.layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.modal-back {
  position: absolute; inset: 0; pointer-events: auto;
  background: #000000b8; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 12px) calc(var(--sab) + 12px) calc(var(--sal) + 12px);
  animation: fadein .14s ease;
}
.modal-back.is-closing { animation: fadeout .14s ease forwards; }
.modal {
  width: 100%; max-width: 520px; max-height: 100%;
  display: flex; flex-direction: column;
  background: linear-gradient(#211915, #17120f); border: 1px solid var(--line2); border-radius: var(--r2);
  box-shadow: 0 10px 40px #000;
}
.modal-back:has(.is-sheet) { align-items: flex-end; padding-bottom: 0; }
.modal.is-sheet { border-radius: 16px 16px 0 0; padding-bottom: var(--sab); max-height: 88%; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 4px 14px; }
.modal-title { flex: 1; font-size: 18px; margin: 0; }
.modal-body { padding: 8px 14px 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px 14px; border-top: 1px solid var(--line); }
.modal-actions > .btn { flex: 1 1 40%; }

/* ---------------- toasts ---------------- */
.toasts { position: fixed; left: 0; right: 0; top: calc(var(--sat) + 8px); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 80; padding: 0 12px; }
.toast { max-width: 520px; background: #1f1813ee; border: 1px solid var(--line2); color: var(--ink); padding: 8px 14px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 18px #000; animation: slidein .18s ease; transition: opacity .35s, transform .35s; }
.toast.is-out { opacity: 0; transform: translateY(-8px); }
.toast-good { border-color: #4d6a32; } .toast-bad { border-color: var(--blood2); color: #ffd2cc; } .toast-warn { border-color: #8a6a22; }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeout { to { opacity: 0; } }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%,100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes flashred { 0% { box-shadow: inset 0 0 0 999px #a3121b55; } 100% { box-shadow: inset 0 0 0 999px transparent; } }
.fx-shake { animation: shake .3s ease; }
.fx-hit { animation: flashred .35s ease; }

/* ---------------- boot / orientação ---------------- */
.boot { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.boot-title { font-size: 42px; letter-spacing: .4em; color: var(--ichor); padding-left: .4em; }
.boot-sub { color: var(--muted); font-size: 14px; }
.rotate-msg { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  .rotate-msg {
    display: flex; position: fixed; inset: 0; z-index: 999; background: var(--bg);
    flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px;
  }
  .rotate-msg div { font-size: 40px; }
}
