:root {
  color-scheme: light;
  --ink: #14282f;
  --muted: #66777a;
  --paper: #f5f0e4;
  --paper-strong: #fffdf7;
  --deep: #102d38;
  --teal: #146a70;
  --teal-2: #0d5158;
  --copper: #b86132;
  --gold: #d6a843;
  --danger: #a33a35;
  --line: #d7cdb8;
  --shadow: 0 12px 32px rgba(21,42,47,.13);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  min-height: 100vh; margin: 0; color: var(--ink);
  background:
    radial-gradient(circle at 12% 4%, rgba(214,168,67,.18), transparent 25rem),
    linear-gradient(180deg, #f8f4e9 0%, #efe7d5 100%);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(20,106,112,.32); outline-offset: 2px;
}

.app-header {
  position: sticky; top: 0; z-index: 20; height: 72px; padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(16,45,56,.96); color: #fff; box-shadow: 0 4px 20px rgba(5,23,28,.22);
  backdrop-filter: blur(12px);
}
.brand { display: flex; gap: 10px; align-items: center; color: inherit; border: 0; background: none; padding: 0; text-align: left; }
.brand-mark { width: 48px; height: 48px; flex: 0 0 auto; object-fit: contain; filter: drop-shadow(0 3px 5px rgba(0,0,0,.34)); }
.brand strong, .brand small { display: block; }
.brand strong { font: 700 1.05rem Georgia, serif; letter-spacing: .035em; }
.brand small { margin-top: 2px; font-size: .72rem; color: #c7d9d9; letter-spacing: .015em; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-icon-btn { width: 42px; height: 42px; display: grid; place-items: center; padding: 0; border: 1px solid rgba(214,168,67,.8); border-radius: 12px; background: rgba(255,255,255,.06); color: #fff; }
.header-icon-btn:hover { background: rgba(255,255,255,.14); }
.header-icon-btn svg { width: 23px; height: 23px; }
.header-icon-btn .exit-fullscreen-icon { display: none; }
.header-icon-btn.is-fullscreen .enter-fullscreen-icon { display: none; }
.header-icon-btn.is-fullscreen .exit-fullscreen-icon { display: block; }
.install-btn { min-height: 40px; padding: 0 16px; border: 1px solid #d6a843; border-radius: 999px; color: #fff; background: transparent; font-weight: 700; }

#app { width: min(100%, 1080px); margin: 0 auto; padding: 26px 18px 112px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 5px; color: var(--copper); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
h1, h2, h3 { margin-top: 0; font-family: Georgia, "Times New Roman", serif; }
h1 { margin-bottom: 5px; font-size: clamp(1.8rem, 6vw, 2.65rem); line-height: 1.05; }
h2 { margin-bottom: 14px; font-size: 1.38rem; }
h3 { margin-bottom: 6px; }
.subtle { margin: 0; color: var(--muted); line-height: 1.5; }

.primary, .secondary, .ghost, .danger-btn, .icon-btn {
  min-height: 46px; border-radius: 12px; border: 0; padding: 0 18px; font-weight: 800;
}
.ui-icon { width: 1.25em; height: 1.25em; display: inline-block; flex: 0 0 auto; vertical-align: -.2em; }
.primary .ui-icon, .secondary .ui-icon, .danger-btn .ui-icon { margin-right: 5px; }
.primary { background: var(--teal); color: white; box-shadow: 0 6px 16px rgba(20,106,112,.22); }
.primary:hover { background: var(--teal-2); }
.primary:disabled { opacity: .43; cursor: not-allowed; box-shadow: none; }
.secondary { background: #e4d8be; color: var(--ink); }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.danger-btn { background: #f3dddd; color: var(--danger); }
.icon-btn { width: 44px; padding: 0; display: inline-grid; place-items: center; background: transparent; border: 1px solid var(--line); }
.icon-text-btn, .finish-btn { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 13px; border: 1px solid var(--line); border-radius: 11px; background: #fff; color: var(--ink); font-weight: 800; }
.finish-btn { border-color: #c98768; color: #823d2c; background: #f8e9df; }
.battle-head-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.full { width: 100%; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.card {
  background: rgba(255,253,247,.93); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.grid { display: grid; gap: 16px; }
.battle-grid { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
.empty { padding: 42px 22px; text-align: center; }
.empty-mark { width: 74px; height: 74px; margin: 0 auto 18px; display: grid; place-items: center; border-radius: 50%; background: #e4d8be; color: var(--copper); font: 700 2.2rem Georgia, serif; }
.empty p { max-width: 440px; margin: 0 auto 22px; color: var(--muted); line-height: 1.55; }

.battle-card { overflow: hidden; }
.battle-card-top { padding: 18px 18px 13px; display: flex; justify-content: space-between; gap: 12px; }
.battle-card h3 { margin: 0; font-size: 1.3rem; }
.battle-meta { color: var(--muted); font-size: .86rem; margin-top: 5px; }
.battle-card-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; background: #f0e9da; border-top: 1px solid var(--line); }
.battle-card-actions .primary { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.phase-pill, .type-pill, .status-pill, .condition {
  display: inline-flex; align-items: center; min-height: 25px; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 800;
}
.phase-pill { background: #d9e8e6; color: var(--teal-2); white-space: nowrap; }
.type-pill.pj { background: #d9e8e6; color: var(--teal-2); }
.type-pill.npc { background: #eedcc9; color: #87451f; }
.status-pill { background: #ece7dd; color: #536164; }
.condition { background: #eee0ba; color: #6d5120; }

.character-list { display: grid; gap: 12px; }
.character-card { display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 13px; padding: 13px; }
.avatar { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; background: var(--deep); color: var(--gold); display: grid; place-items: center; font: 700 1.25rem Georgia, serif; border: 2px solid #d7c291; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.character-name { margin: 0 0 5px; font-size: 1.05rem; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: .82rem; }
.stat { display: inline-flex; align-items: center; gap: 4px; }
.stat .ui-icon { color: var(--copper); }
.stat b { color: var(--ink); }
.card-actions { display: flex; gap: 6px; }
.card-resource-line { margin-top: 9px; }
.control-label { color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
.critical-control, .energy-control { display: flex; align-items: center; gap: 8px; }
.critical-boxes, .form-critical { display: flex; gap: 5px; }
.critical-box { width: 28px; height: 28px; flex: 0 0 auto; padding: 0; border: 2px solid #9c643e; border-radius: 5px; background: #fffaf0; }
.critical-box.marked { background: #9f2f2b; border-color: #721f1d; box-shadow: inset 0 0 0 3px #d66d57; }
.critical-box:disabled { cursor: not-allowed; opacity: .38; }
.critical-control.compact { flex-wrap: wrap; gap: 5px; }
.critical-control.compact .critical-box { width: 23px; height: 23px; }
.energy-control input { width: 76px; min-height: 38px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); text-align: center; font-weight: 800; }
.energy-control.compact input { width: 62px; min-height: 32px; }
.form-critical { margin-top: 4px; }

.section { margin-top: 24px; }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
.setup-actions { position: sticky; bottom: 80px; z-index: 5; margin-top: 22px; padding: 12px; background: rgba(245,240,228,.94); border-radius: 16px; backdrop-filter: blur(10px); }
.split { display: grid; gap: 18px; }
.notice { padding: 13px 15px; border-left: 4px solid var(--gold); background: #f2e6c9; border-radius: 0 12px 12px 0; color: #5d4b27; line-height: 1.45; }

.initiative-board { display: grid; gap: 10px; counter-reset: order; }
.initiative-row { counter-increment: order; display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 12px; }
.initiative-row::before { content: counter(order); width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--deep); color: white; font-weight: 800; }
.initiative-value { min-width: 48px; text-align: center; font: 800 1.25rem Georgia, serif; color: var(--copper); }
.dice-detail { color: var(--muted); font-size: .78rem; }
.tie-tools { grid-column: 2 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.tie-warning { color: #8b4a23; font-size: .8rem; font-weight: 700; margin-right: auto; }
.mini-btn { min-height: 34px; min-width: 38px; border: 1px solid var(--line); border-radius: 9px; background: #fff; font-weight: 800; }
.initiative-input { width: 76px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 7px; text-align: center; font-weight: 800; }
.unconscious { background: #3b4244 !important; border-color: #2e3436 !important; color: #f3f3f0 !important; box-shadow: none; }
.unconscious .stats, .unconscious .dice-detail, .unconscious small, .unconscious .subtle, .unconscious .control-label { color: #cbd0d1 !important; }
.unconscious .stat b, .unconscious .initiative-value, .unconscious .compact-stats { color: #fff !important; }
.unconscious .avatar { background: #232829; border-color: #747c7e; color: #d9d9d6; filter: grayscale(1); }
.unconscious .type-pill, .unconscious .status-pill { background: #5b6365; color: #fff; }
.dead { background: #090a0a !important; border-color: #000 !important; color: #fff !important; box-shadow: none !important; }
.dead .stats, .dead .dice-detail, .dead small, .dead .subtle, .dead .control-label { color: #c9c9c9 !important; }
.dead .stat b, .dead .initiative-value, .dead .compact-stats { color: #fff !important; }
.dead .avatar { background: #000; border-color: #555; color: #fff; filter: grayscale(1); }
.dead .type-pill, .dead .status-pill, .dead .condition { background: #303030; color: #fff; }

.round-top { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; margin-bottom: 18px; }
.round-count { color: var(--copper); font-weight: 800; }
.turn-progress { height: 7px; overflow: hidden; border-radius: 99px; background: #dbd2c2; }
.turn-progress span { display: block; height: 100%; background: var(--teal); }
.active-card { position: relative; overflow: hidden; padding: 22px; border-top: 6px solid var(--copper); }
.active-card::after { content: "VEZ ATUAL"; position: absolute; top: 16px; right: -31px; width: 120px; padding: 5px 0; transform: rotate(45deg); text-align: center; background: var(--gold); color: #3c2b0f; font-size: .65rem; font-weight: 900; letter-spacing: .08em; }
.active-person { display: flex; align-items: center; gap: 15px; padding-right: 45px; }
.active-person .avatar { width: 76px; height: 76px; flex: 0 0 auto; }
.active-person h1 { font-size: clamp(1.7rem, 7vw, 2.5rem); margin: 0 0 6px; }
.combat-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 20px 0; }
.combat-stat { padding: 12px 8px; text-align: center; background: #f0e9da; border-radius: 12px; }
.combat-stat > .ui-icon { width: 1.55rem; height: 1.55rem; color: var(--copper); }
.combat-stat small { display: block; color: var(--muted); font-size: .71rem; text-transform: uppercase; font-weight: 800; }
.combat-stat strong { display: block; margin-top: 3px; font: 700 1.35rem Georgia, serif; }
.turn-resources { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin: -5px 0 18px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #f8f3e8; }
.resistance-control { display: flex; align-items: center; justify-content: center; gap: 8px; }
.resistance-control button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: white; font-weight: 900; }
.status-title { margin: 18px 0 9px; font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
.status-choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.status-choice button { min-height: 50px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-weight: 800; color: var(--ink); }
.status-choice .ui-icon { width: 1.35rem; height: 1.35rem; }
.status-choice button.selected { border-color: var(--teal); background: #dcebea; color: var(--teal-2); }
.turn-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 18px; }
.turn-actions button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.condition-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.queue { margin-top: 18px; }
.queue-list { display: flex; gap: 8px; overflow-x: auto; padding: 3px 2px 10px; }
.queue-chip { min-width: 120px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,253,247,.86); }
.queue-chip strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-chip small { color: var(--muted); }
.queue-chip.waiting { border-color: #d58e53; background: #f5e2d1; }
.combatant-dashboard { display: grid; gap: 9px; }
.combatant-row { display: grid; grid-template-columns: 50px minmax(130px, 1fr) auto; align-items: center; gap: 11px; padding: 11px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,253,247,.93); }
.combatant-row .avatar { width: 50px; height: 50px; }
.combatant-info { min-width: 0; }
.combatant-info > strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 11px; margin-top: 4px; color: var(--muted); font-size: .82rem; }
.compact-stats > span { display: inline-flex; align-items: center; gap: 3px; }
.quick-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.combatant-controls { grid-column: 2 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 9px 16px; }
.resistance-control.compact { padding: 4px 6px; border-radius: 999px; background: #f0e9da; }
.resistance-control.compact > .ui-icon { color: var(--copper); }
.resistance-control.compact button { width: 30px; height: 30px; }

.dice-panel { max-width: 640px; margin: 0 auto; }
.dice-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; }
.field label, .field-label { font-size: .82rem; font-weight: 800; color: #45575b; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 47px; border: 1px solid var(--line); border-radius: 11px; background: #fffdf8; color: var(--ink); padding: 10px 12px;
}
.field textarea { min-height: 95px; resize: vertical; }
.form-grid { display: grid; gap: 13px; }
.form-grid.two { grid-template-columns: repeat(2, 1fr); }
.form-grid .wide { grid-column: 1 / -1; }
.dice-result { margin: 20px 0; padding: 24px; text-align: center; background: var(--deep); color: white; border-radius: 18px; }
.dice-result strong { display: block; font: 700 3.5rem Georgia, serif; color: var(--gold); }
.dice-faces { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.die { min-width: 42px; min-height: 42px; display: grid; place-items: center; padding: 6px; background: #fff; color: var(--deep); border-radius: 9px; font-weight: 900; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: end center; padding: 20px; background: rgba(6,24,29,.66); backdrop-filter: blur(4px); }
.modal { width: min(100%, 620px); max-height: min(88vh, 760px); overflow-y: auto; padding: 22px; border-radius: 22px; background: var(--paper-strong); box-shadow: 0 24px 70px rgba(0,0,0,.32); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 9px; margin-top: 20px; }
.check-list { display: grid; gap: 8px; margin-top: 8px; }
.check-item { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.check-item input { width: 20px; height: 20px; }
.file-name { color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
.attachment-link { color: var(--teal-2); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 91px; z-index: 80; max-width: calc(100vw - 30px); transform: translate(-50%, 25px); padding: 11px 16px; border-radius: 999px; background: var(--ink); color: white; opacity: 0; pointer-events: none; transition: .2s ease; box-shadow: var(--shadow); text-align: center; font-weight: 700; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.bottom-nav { position: fixed; z-index: 30; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(calc(100% - 24px), 430px); display: grid; grid-template-columns: repeat(3, 1fr); padding: 6px; border: 1px solid rgba(255,255,255,.12); border-radius: 18px; background: rgba(16,45,56,.97); box-shadow: 0 10px 35px rgba(6,24,29,.28); backdrop-filter: blur(12px); }
.bottom-nav button { min-height: 54px; border: 0; border-radius: 13px; background: transparent; color: #c7d7d8; font-size: .74rem; font-weight: 800; }
.bottom-nav button span { display: block; margin-bottom: 2px; color: var(--gold); font-size: 1.15rem; }
.bottom-nav button.active { background: rgba(255,255,255,.11); color: white; }

@media (min-width: 760px) {
  .app-header { padding-inline: max(24px, calc((100vw - 1080px)/2)); }
  #app { padding-top: 38px; }
  .split { grid-template-columns: 1fr 1fr; }
  .modal-backdrop { place-items: center; }
  .modal { border-radius: 22px; }
  .active-card { padding: 30px; }
}

@media (max-width: 560px) {
  .page-head { align-items: flex-start; flex-direction: column; }
  .page-head .primary { width: 100%; }
  .character-card { grid-template-columns: 52px 1fr; }
  .character-card .card-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .form-grid.two { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .combat-stats { grid-template-columns: 1.3fr 1fr 1fr; }
  .status-choice { grid-template-columns: 1fr; }
  .battle-head-actions { width: 100%; flex-direction: row; align-items: center; justify-content: space-between; }
  .combatant-row { grid-template-columns: 44px 1fr; }
  .combatant-row .avatar { width: 44px; height: 44px; }
  .quick-actions { grid-column: 1 / -1; justify-content: space-between; }
  .combatant-controls { grid-column: 1 / -1; }
  .combatant-controls .resistance-control { flex: 1; }
  .turn-resources { align-items: stretch; flex-direction: column; }
  .brand strong { font-size: .96rem; }
  .brand small { max-width: 210px; font-size: .65rem; line-height: 1.15; }
  .header-actions { gap: 5px; }
  .header-icon-btn { width: 40px; height: 40px; }
  .install-btn { padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
