@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@500;600;700&family=Cormorant+Garamond:ital,wght@0,500;0,600;1,500&family=Inter:wght@400;500;600;700&family=Noto+Sans+Cuneiform&display=swap');

:root {
  color-scheme: dark;
  --ink: #060507;
  --ink-2: #0d0a10;
  --ink-3: #151019;
  --panel: rgba(19, 15, 23, .91);
  --panel-strong: rgba(13, 10, 16, .97);
  --glass: rgba(28, 22, 32, .72);
  --gold: #c9a65c;
  --gold-2: #ead99f;
  --gold-3: #7e6331;
  --gold-line: rgba(220, 188, 112, .36);
  --gold-line-strong: rgba(231, 201, 128, .72);
  --text: #f5efe3;
  --muted: #aba2ad;
  --muted-2: #7f7682;
  --danger: #e08186;
  --success: #8bcba6;
  --warning: #e3bc70;
  --purple: #8a5aa3;
  --green: #5f9a76;
  --red: #9e4d59;
  --shadow: 0 28px 90px rgba(0, 0, 0, .58);
  --radius: 18px;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --login-bg-url: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: auto; overscroll-behavior-y: auto; }
body {
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(95, 45, 102, .18), transparent 31rem),
    radial-gradient(circle at 95% 15%, rgba(173, 126, 50, .13), transparent 32rem),
    linear-gradient(145deg, #050406, #0d0910 48%, #070609);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  opacity: .17;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black, transparent 80%);
}

body::after {
  content: '𒀭 𒆠 𒂊 𒉺 𒁹';
  position: fixed;
  left: 50%;
  bottom: 10%;
  z-index: -1;
  width: 100%;
  transform: translateX(-50%);
  color: rgba(212, 179, 103, .025);
  text-align: center;
  font: clamp(3.5rem, 15vw, 12rem)/1 'Noto Sans Cuneiform', 'Segoe UI Historic', serif;
  letter-spacing: .12em;
  pointer-events: none;
  white-space: nowrap;
}

::selection { background: rgba(201, 166, 92, .35); color: white; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

h1, h2, h3, h4, .mystic-title {
  margin-top: 0;
  font-family: Cinzel, Georgia, serif;
  font-weight: 600;
  letter-spacing: .025em;
}

p { margin-top: 0; }
.cuneiform { font-family: 'Noto Sans Cuneiform', 'Segoe UI Historic', serif; }
.muted { color: var(--muted); }
.gold { color: var(--gold-2); }
.danger-text { color: var(--danger); }
.success-text { color: var(--success); }

.app-body { padding-bottom: calc(90px + var(--safe-bottom)); }
.app-frame {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
  padding: calc(var(--safe-top) + 76px) 0 36px;
}

.topbar {
  position: fixed;
  top: var(--safe-top);
  left: 50%;
  z-index: 70;
  width: min(1220px, calc(100% - 22px));
  min-height: 64px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid var(--gold-line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(18, 14, 21, .93), rgba(9, 7, 11, .91));
  box-shadow: 0 18px 50px rgba(0,0,0,.42), inset 0 0 28px rgba(201,166,92,.03);
  backdrop-filter: blur(18px);
}

.brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mini-logo { width: 41px; height: 41px; object-fit: contain; filter: drop-shadow(0 0 12px rgba(201,166,92,.18)); }
.brand-lockup span { display: grid; min-width: 0; }
.brand-lockup strong {
  overflow: hidden;
  color: var(--gold-2);
  font-family: Cinzel, serif;
  font-size: .9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-lockup small { color: var(--muted); font-size: .68rem; }

.topbar-user { display: flex; align-items: center; gap: 9px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.avatar-small {
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--gold-line);
  border-radius: 50%;
  color: var(--gold-2);
  background: rgba(201,166,92,.08);
  font: 600 .72rem Cinzel, serif;
  overflow: hidden;
}
.avatar-small img { width: 100%; height: 100%; object-fit: cover; object-position: center; }
.topbar-user-copy { display: none; }
.topbar-user-copy strong, .topbar-user-copy span { display: block; }
.topbar-user-copy strong { color: var(--text); font-size: .75rem; }
.topbar-user-copy span { color: var(--muted); font-size: .66rem; }

.icon-button {
  width: 37px;
  height: 37px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 50%;
  color: var(--gold-2);
  background: rgba(255,255,255,.025);
  font-family: Cinzel, serif;
  font-size: 1rem;
  line-height: 1;
  transition: .2s ease;
}
.icon-button:hover { border-color: var(--gold-line-strong); background: rgba(201,166,92,.08); }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: var(--safe-bottom);
  z-index: 80;
  width: min(700px, calc(100% - 22px));
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  transform: translateX(-50%);
  padding: 7px;
  border: 1px solid var(--gold-line);
  border-radius: 21px;
  background: rgba(10, 8, 12, .94);
  box-shadow: 0 20px 65px rgba(0,0,0,.55);
  backdrop-filter: blur(20px);
}
.bottom-nav-master {
  width: min(1080px, calc(100% - 22px));
  grid-template-columns: repeat(9, minmax(0, 1fr));
  overflow-x: auto;
}
.nav-item {
  min-width: 0;
  min-height: 55px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  padding: 6px 3px;
  border-radius: 14px;
  color: var(--muted);
  font-size: .63rem;
  text-align: center;
  transition: .2s ease;
}
.nav-item:hover, .nav-item.active {
  color: var(--gold-2);
  background: linear-gradient(180deg, rgba(201,166,92,.13), rgba(201,166,92,.045));
}
.nav-item.active { box-shadow: inset 0 0 0 1px rgba(201,166,92,.23); }
.nav-symbol { font: 1rem 'Noto Sans Cuneiform', 'Segoe UI Historic', serif; }

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 14px 0 22px;
}
.page-heading h1 { margin: 0 0 4px; color: var(--gold-2); font-size: clamp(1.5rem, 6vw, 2.5rem); }
.page-heading p { margin: 0; color: var(--muted); max-width: 62ch; }
.heading-sigil { color: rgba(201,166,92,.42); font-size: clamp(2.5rem, 9vw, 5rem); line-height: .8; }

.panel, .card {
  border: 1px solid var(--gold-line);
  border-radius: var(--radius);
  background: linear-gradient(165deg, rgba(26,20,30,.91), rgba(12,10,15,.94));
  box-shadow: 0 20px 65px rgba(0,0,0,.30), inset 0 0 40px rgba(201,166,92,.025);
}
.panel { padding: clamp(16px, 4vw, 24px); }
.card { padding: 16px; }
.panel-header, .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.panel-header h2, .card-header h3 { margin: 0; color: var(--gold-2); font-size: 1rem; }

.ornament-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 14px;
  color: var(--gold);
  font-family: 'Noto Sans Cuneiform', 'Segoe UI Historic', serif;
  opacity: .72;
}
.ornament-line::before, .ornament-line::after { content: ''; height: 1px; flex: 1; background: linear-gradient(90deg, transparent, var(--gold-line-strong), transparent); }

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--gold-line-strong);
  border-radius: 12px;
  color: #160f13;
  background: linear-gradient(135deg, #bd9650, #f0dca6);
  box-shadow: 0 10px 25px rgba(201,166,92,.13);
  font-weight: 800;
  transition: transform .16s ease, filter .16s ease, opacity .16s ease;
}
.button:hover { filter: brightness(1.08); }
.button:active { transform: scale(.985); }
.button:disabled { cursor: wait; opacity: .5; }
.button.secondary { color: var(--gold-2); background: rgba(201,166,92,.075); box-shadow: none; }
.button.ghost { color: var(--muted); border-color: rgba(255,255,255,.12); background: transparent; box-shadow: none; }
.button.danger { color: white; border-color: rgba(224,129,134,.52); background: linear-gradient(135deg, #79343c, #bc5d67); }
.button.small { min-height: 36px; padding: 7px 11px; font-size: .78rem; }
.button.full { width: 100%; }

.field { display: grid; gap: 7px; }
.field label, .field-label {
  color: var(--gold-2);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  outline: none;
  color: var(--text);
  background: rgba(0,0,0,.24);
  padding: 11px 13px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.textarea { min-height: 116px; resize: vertical; }
.select { color-scheme: dark; }
.select option, select option {
  color: #f5efe3;
  background: #0d0a10;
}
.select option:checked, select option:checked {
  color: #1a1210;
  background: #d7b86f;
}
.autosave-state {
  color: var(--muted);
  font-size: .68rem;
}
.file-button { position: relative; overflow: hidden; }
.image-upload-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.upload-preview {
  width: 70px; height: 70px; display: grid; place-items: center; overflow: hidden;
  border: 1px solid var(--gold-line); border-radius: 14px; color: var(--gold-2); background: rgba(0,0,0,.24);
  font: 700 .9rem Cinzel, serif;
}
.upload-preview img { width: 100%; height: 100%; object-fit: cover; }
.upload-preview.wide { width: 120px; height: 84px; }
.owner-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -6px 0 15px; flex-wrap: wrap; }
.small-copy { font-size: .72rem; }

.input:focus, .select:focus, .textarea:focus { border-color: var(--gold-line-strong); box-shadow: 0 0 0 3px rgba(201,166,92,.10); }
.input[readonly] { color: var(--muted); background: rgba(255,255,255,.02); }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: 1fr; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 25px;
  padding: 4px 9px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.035);
  font-size: .69rem;
}
.badge.gold { color: var(--gold-2); border-color: var(--gold-line); background: rgba(201,166,92,.06); }
.badge.success { color: var(--success); border-color: rgba(139,203,166,.3); }
.badge.danger { color: var(--danger); border-color: rgba(224,129,134,.3); }
.badge.warning { color: var(--warning); border-color: rgba(227,188,112,.3); }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1fr; }
.grid.three { grid-template-columns: 1fr; }
.stack { display: grid; gap: 16px; }
.inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 28px;
  border: 1px dashed var(--gold-line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  background: rgba(255,255,255,.015);
}
.empty-state h3 { margin: 8px 0 6px; color: var(--gold-2); }
.empty-state p { max-width: 45ch; margin: 0; }
.empty-symbol { color: rgba(201,166,92,.55); font: 2.5rem 'Noto Sans Cuneiform', 'Segoe UI Historic', serif; }

.skeleton {
  min-height: 90px;
  border-radius: 14px;
  background: linear-gradient(100deg, rgba(255,255,255,.035) 20%, rgba(255,255,255,.08) 40%, rgba(255,255,255,.035) 60%);
  background-size: 220% 100%;
  animation: skeleton 1.3s linear infinite;
}
@keyframes skeleton { to { background-position-x: -220%; } }

.spinner {
  width: 16px;
  height: 16px;
  display: inline-block;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-region {
  position: fixed;
  top: calc(var(--safe-top) + 72px);
  left: 50%;
  z-index: 200;
  width: min(480px, calc(100% - 28px));
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 13px 15px;
  border: 1px solid rgba(139,203,166,.36);
  border-radius: 13px;
  color: #dff7e8;
  background: rgba(18,54,38,.96);
  box-shadow: var(--shadow);
  animation: toastIn .25s ease both;
}
.toast-error { color: #ffe6e8; border-color: rgba(224,129,134,.43); background: rgba(73,25,31,.97); }
.toast-warning { color: #fff2d7; border-color: rgba(227,188,112,.43); background: rgba(75,52,18,.97); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }

.modal {
  width: min(560px, calc(100% - 24px));
  max-height: min(86dvh, 760px);
  padding: 0;
  border: 1px solid var(--gold-line-strong);
  border-radius: 20px;
  color: var(--text);
  background: linear-gradient(160deg, #1c1520, #09070b);
  box-shadow: 0 35px 110px rgba(0,0,0,.75);
  overflow: auto;
}
.modal::backdrop { background: rgba(0,0,0,.78); backdrop-filter: blur(7px); }
.modal-card { padding: 22px; }
.modal-card h2 { margin: 0 0 10px; color: var(--gold-2); font-size: 1.25rem; text-align: center; }
.modal-copy { color: var(--muted); line-height: 1.65; white-space: pre-line; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-close { position: sticky; top: 8px; float: right; z-index: 2; }

.table-wrap { overflow: auto; border: 1px solid var(--gold-line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 12px 13px; border-bottom: 1px solid rgba(255,255,255,.07); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; color: var(--gold-2); background: #151019; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; }
td { color: #ddd4df; font-size: .84rem; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: rgba(201,166,92,.025); }

@media (min-width: 640px) {
  .topbar-user-copy { display: block; }
  .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  .app-frame { padding-top: calc(var(--safe-top) + 88px); }
  .bottom-nav { bottom: 18px; }
  .nav-item { font-size: .69rem; }
}

@media (max-width: 520px) {
  .page-heading { align-items: flex-start; }
  .heading-sigil { display: none; }
  .bottom-nav-master { justify-content: flex-start; grid-template-columns: repeat(9, 78px); }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

.save-indicator {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(92px + var(--safe-bottom));
  z-index: 150;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 9px 13px;
  border: 1px solid var(--gold-line-strong);
  border-radius: 999px;
  color: var(--gold-2);
  background: rgba(8, 6, 10, .94);
  box-shadow: 0 14px 45px rgba(0,0,0,.58);
  backdrop-filter: blur(14px);
  font-size: .75rem;
  transition: opacity .18s ease, transform .18s ease;
}
.save-indicator.saved { color: var(--success); border-color: rgba(139,203,166,.55); }
.save-indicator.error { color: var(--danger); border-color: rgba(224,129,134,.55); }
.save-indicator.hidden { opacity: 0; transform: translateY(8px); pointer-events: none; }
.save-check { width: 20px; height: 20px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-weight: 700; }
@media (min-width: 700px) { .save-indicator { bottom: 24px; } }


/* V3.7 · rolagem móvel contínua e sem áreas mortas */
html,
body {
  touch-action: pan-y pinch-zoom;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
}

.app-frame,
main,
section,
article,
.panel,
.card,
details,
summary,
[role="button"],
.stat-card,
.attribute-card,
.skill-card,
.ritual-row-card,
.special-ability-card {
  touch-action: pan-y;
}

button,
a,
input,
select,
textarea,
label {
  touch-action: manipulation;
}

/* Permite que o gesto continue na página quando uma área interna chega ao
   início ou ao fim. Antes, "contain" prendia o dedo dentro de vários cards. */
.special-ability-scroll,
.special-ability-description,
.special-ability-detail-description,
.level-summary-note,
.ritual-card-description,
.ritual-detail-description,
.ascent-history-note,
.ascent-history-actions,
.activity-list,
.admin-list,
.multi-picker-options,
.condition-target-list,
.special-ability-target-list,
.special-ability-assignment-list,
.ritual-proficiency-grid,
.table-wrap,
.modal,
.modal-card {
  overscroll-behavior-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 820px), (pointer: coarse) {
  /* Na tela móvel, cards de leitura deixam a página ser o principal eixo de
     rolagem. Os diálogos e listas administrativas continuam roláveis. */
  .special-ability-scroll {
    max-height: none !important;
    overflow-y: visible !important;
    scrollbar-gutter: auto !important;
  }

  /* Esses textos vivem dentro de cards clicáveis. No celular o gesto passa
     para o card/página, e a leitura completa continua disponível no modal. */
  .special-ability-description,
  .ritual-card-description {
    pointer-events: none;
    touch-action: pan-y;
  }

  .app-frame,
  .panel,
  .card,
  .character-hero,
  .attributes-orbit,
  .skill-section-grid,
  .skill-group-card,
  .skill-group-list,
  .special-ability-grid,
  .ritual-grid {
    overscroll-behavior: auto !important;
  }
}
