:root {
  --gold: #e2b766;
  --gold-hi: #fbe3a5;
  --gold-lo: #8c6326;
  --ink: #f3e9d6;
  --ink-dim: #c9b99c;
  --panel: rgba(14, 11, 9, 0.82);
  --panel-2: rgba(30, 22, 16, 0.78);
  --blue: #2b4aa0;
  --red: #b3161d;
  --serif: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --body: 'Cormorant Garamond', Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #050403; color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
/* Ocupa sempre a tela inteira; o HUD se reorganiza conforme a proporção (ver o fim do arquivo) */
#app {
  position: fixed; inset: 0; overflow: hidden;
  background: #0b0908;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
#stage, #stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }

/* ---------- Carregamento ---------- */
#loader {
  position: absolute; inset: 0; z-index: 50;
  display: grid; place-items: end center; padding-bottom: calc(14% + var(--safe-b));
  background: linear-gradient(180deg, rgba(11, 8, 7, 0) 55%, rgba(11, 8, 7, .9) 85%), url(../assets/img/capa-retrato.jpg) center / cover, #0b0807;
  transition: opacity 1s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
#loader .loader-sigil, #loader h1 { display: none; }   /* o título já está na capa */
.loader-inner { text-align: center; width: 84%; }
.loader-sigil {
  font-size: 64px; color: var(--gold);
  text-shadow: 0 0 24px rgba(255, 190, 90, .6);
  animation: breathe 2.4s ease-in-out infinite;
}
#loader h1, .title {
  font-family: var(--serif); font-weight: 900; letter-spacing: .14em; text-transform: uppercase;
  margin: 8px 0 22px; font-size: 36px;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 50%, var(--gold-lo));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .8));
}
#loader h1 span, .title span {
  display: block; font-size: .32em; letter-spacing: .5em; font-weight: 500; margin-top: 6px;
}
.bar { height: 4px; background: rgba(255, 255, 255, .08); border-radius: 2px; overflow: hidden; border: 1px solid rgba(226, 183, 102, .25); }
.bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold-lo), var(--gold-hi)); transition: width .4s ease; }
#loader-text { font-style: italic; color: var(--ink-dim); font-size: 18px; margin-top: 14px; }
@keyframes breathe { 50% { transform: scale(1.06); opacity: .85; } }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; display: flex; flex-direction: column; }
#hud button { pointer-events: auto; }
.player-panel {
  display: flex; align-items: center; gap: 10px;
  margin: 0 8px; padding: 4px 10px 4px 6px; min-height: 48px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid rgba(226, 183, 102, .45);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .5), 0 6px 20px rgba(0, 0, 0, .45);
  transition: box-shadow .4s, border-color .4s;
}
#panel-b { order: 0; margin-top: calc(8px + var(--safe-t)); }
#turn-label { order: 1; }
#panel-w { order: 3; margin-top: auto; }
#actions { order: 4; }
/* quem joga de pretas contra o computador fica embaixo */
#hud.flip #panel-b { order: 3; margin-top: auto; }
#hud.flip #panel-w { order: 0; margin-top: calc(8px + var(--safe-t)); }
.player-panel.active {
  border-color: var(--gold-hi);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .5), inset 0 0 30px rgba(226, 160, 70, .25), 0 0 20px rgba(255, 190, 90, .3);
}
.crest { width: 30px; height: 36px; flex: none; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .7)); }
.pinfo { flex: 1; min-width: 0; }
.pname { font-family: var(--serif); font-size: 15px; font-weight: 700; letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pside { font-family: var(--serif); font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.captured { min-height: 18px; font-size: 16px; line-height: 18px; color: var(--ink); letter-spacing: -1px; white-space: nowrap; overflow: hidden; }
.captured .adv { font-family: var(--serif); font-size: 11px; color: var(--gold); margin-left: 5px; letter-spacing: 0; }
.thinking { display: none; gap: 4px; }
.thinking.show { display: flex; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); animation: dot 1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 100% { opacity: .25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-4px); } }

#turn-label {
  align-self: center; margin-top: 6px;
  font-family: var(--serif); letter-spacing: .26em; text-transform: uppercase; font-size: 11px;
  color: var(--gold); text-shadow: 0 2px 8px #000;
  padding: 5px 16px; border-top: 1px solid rgba(226, 183, 102, .4); border-bottom: 1px solid rgba(226, 183, 102, .4);
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .55), transparent);
  white-space: nowrap;
}

#toast {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%) scale(.9);
  font-family: var(--serif); font-weight: 900; text-transform: uppercase; letter-spacing: .14em;
  font-size: 34px; opacity: 0; pointer-events: none; white-space: nowrap;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, var(--gold-lo));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, .9));
}
#toast.show { animation: toast 1.9s ease forwards; }
#toast.check { background: linear-gradient(180deg, #ffd0b0, #ff5a3a 55%, #8a0d0d); -webkit-background-clip: text; background-clip: text; }
#toast.small { font-size: 18px; letter-spacing: .26em; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.25); letter-spacing: .4em; }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); letter-spacing: .14em; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(.98); }
}

/* ---------- Barra de ações ---------- */
#actions {
  display: flex; justify-content: space-around; align-items: stretch; gap: 4px;
  margin-top: 6px; padding: 4px 6px calc(4px + var(--safe-b));
  background: linear-gradient(180deg, rgba(30, 22, 16, .92), rgba(10, 8, 6, .97));
  border-top: 1px solid rgba(226, 183, 102, .45);
  pointer-events: auto; position: relative; z-index: 2;
}
.act {
  flex: 1; min-height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; padding: 4px 0; cursor: pointer; color: var(--ink-dim);
  font-family: var(--serif); font-size: 9px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  border-radius: 12px; transition: color .2s, transform .1s;
}
.act svg {
  width: 34px; height: 34px; padding: 7px; border-radius: 50%;
  fill: none; stroke: var(--gold); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  background: radial-gradient(circle at 35% 30%, rgba(251, 227, 165, .16), rgba(0, 0, 0, .5));
  border: 1px solid rgba(226, 183, 102, .45);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .4);
}
.act:active { transform: scale(.92); }
.act:active svg, .act.on svg { background: linear-gradient(180deg, var(--gold-hi), var(--gold) 60%, #a8772f); stroke: #1b130b; border-color: var(--gold-hi); }
.act.on { color: var(--gold-hi); }
.act:disabled { opacity: .35; }
.act .mute { display: none; }
.act.muted .mute { display: inline; }
.act.muted .wave { display: none; }

/* ---------- Crônica (gaveta) ---------- */
#log {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1;
  max-height: 46%; display: flex; flex-direction: column;
  padding: 6px 16px calc(84px + var(--safe-b));
  background: linear-gradient(180deg, #221912, #0c0907);
  border-top: 1px solid rgba(226, 183, 102, .55); border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .6);
  transform: translateY(100%); transition: transform .4s cubic-bezier(.2, .8, .2, 1); pointer-events: auto;
}
#log.open { transform: translateY(0); }
#log .grip { width: 40px; height: 4px; border-radius: 2px; background: rgba(226, 183, 102, .4); margin: 2px auto 8px; }
#log h3 { font-family: var(--serif); font-size: 12px; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); margin: 0 0 6px; text-align: center; }
#moves { list-style: none; margin: 0; padding: 0; overflow-y: auto; font-size: 18px; touch-action: pan-y; columns: 2; column-gap: 20px; }
#moves li { display: grid; grid-template-columns: 30px 1fr 1fr; padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, .05); break-inside: avoid; }
#moves .n { color: var(--ink-dim); font-size: 15px; }

/* ---------- Sobreposições ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .35), rgba(0, 0, 0, .75));
  animation: fade .35s ease;
}
#menu.overlay { background: linear-gradient(0deg, rgba(0, 0, 0, .85) 0%, rgba(0, 0, 0, .55) 60%, rgba(0, 0, 0, .15) 100%); place-items: end center; }
@keyframes fade { from { opacity: 0; } }
.panel {
  position: relative; width: min(440px, 100%);
  padding: 22px 18px; text-align: center;
  background: linear-gradient(180deg, rgba(34, 25, 18, .92), rgba(12, 9, 7, .94));
  border: 1px solid rgba(226, 183, 102, .6);
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, .55), inset 0 0 0 5px rgba(226, 183, 102, .22), 0 20px 60px rgba(0, 0, 0, .7);
  max-height: 100%; overflow-y: auto; touch-action: pan-y;
}
.panel::before, .panel::after {
  content: '◆'; position: absolute; top: -9px; color: var(--gold); font-size: 14px;
  left: 50%; transform: translateX(-50%); text-shadow: 0 0 8px rgba(255, 190, 90, .8);
}
.panel::after { top: auto; bottom: -9px; }
.menu-panel { width: 100%; }
.menu-crests { display: flex; align-items: center; justify-content: center; gap: 18px; }
.menu-crests img { width: 48px; height: 58px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .8)); }
.menu-crests .vs { font-style: italic; color: var(--ink-dim); font-size: 18px; }
.title { margin: 6px 0 16px; font-size: 32px; }
.panel h2 {
  font-family: var(--serif); text-transform: uppercase; letter-spacing: .16em; margin: 0 0 16px;
  font-size: 22px; color: var(--gold-hi); text-shadow: 0 2px 10px rgba(0, 0, 0, .8);
}
.sub { font-size: 20px; color: var(--ink); margin: -4px 0 14px; line-height: 1.3; }
.meta { font-style: italic; color: var(--ink-dim); margin: 0 0 16px; font-size: 17px; }
.opt { margin: 0 0 14px; text-align: left; }
.opt label { display: block; font-family: var(--serif); font-size: 11px; letter-spacing: .24em; text-transform: uppercase; color: var(--gold); margin: 0 0 6px 2px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 0; min-width: 0; min-height: 44px; padding: 8px 4px; cursor: pointer; font-size: 16px; font-weight: 600;
  background: rgba(0, 0, 0, .35); border: 1px solid rgba(226, 183, 102, .28); color: var(--ink-dim);
  transition: all .2s;
}
.seg.grid2 { display: grid; grid-template-columns: 1fr 1fr; }
.seg button.on {
  color: #1b130b; border-color: var(--gold-hi);
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 60%, #b98a3c);
  box-shadow: 0 0 14px rgba(255, 190, 90, .35);
}
.btn {
  display: block; width: 100%; min-height: 48px; margin: 8px 0 0; padding: 12px 16px; cursor: pointer;
  font-family: var(--serif); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: 14px;
  color: var(--ink); background: linear-gradient(180deg, rgba(60, 44, 30, .9), rgba(28, 20, 14, .95));
  border: 1px solid rgba(226, 183, 102, .5);
  transition: all .2s;
}
.btn:active {
  outline: none; border-color: var(--gold-hi); color: #fff;
  box-shadow: 0 0 0 1px var(--gold-hi), 0 0 18px rgba(255, 190, 90, .4);
}
.btn.primary {
  color: #1b130b; font-size: 16px; padding: 14px 16px; margin-top: 14px;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, #a8772f);
  border-color: var(--gold-hi); text-shadow: 0 1px 0 rgba(255, 255, 255, .4);
}
.btn.primary:active { color: #000; filter: brightness(1.1); }
.btn.ghost { background: transparent; border-color: rgba(226, 183, 102, .25); color: var(--ink-dim); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.small { font-size: 11px; min-height: 44px; padding: 9px 6px; letter-spacing: .08em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn.small { flex: 1 1 40%; }
.row .btn { flex: 1; }
.promo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.promo-btn { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; }
.promo-btn.primary { margin: 0; }
.promo-btn .g { font-size: 44px; line-height: 1; font-family: serif; text-transform: none; }
.help-panel { width: 100%; text-align: left; }
.help-panel h2 { text-align: center; }
.help-cols { display: grid; grid-template-columns: 1fr; gap: 4px; }
.help-cols h4 { font-family: var(--serif); color: var(--gold); letter-spacing: .12em; margin: 8px 0 4px; font-size: 14px; text-transform: uppercase; }
.help-cols p { margin: 0; font-size: 18px; line-height: 1.35; color: var(--ink); }

@media (max-height: 640px) {
  .menu-crests { display: none; }
  .title { font-size: 26px; margin-bottom: 10px; }
  .opt { margin-bottom: 10px; }
}

/* ---------- Capa (?capa) ---------- */
body.capa #hud, body.capa .overlay, body.vitrine #hud, body.vitrine .overlay { display: none !important; }
#capa-title {
  position: absolute; left: 0; right: 0; top: 5%; z-index: 30; text-align: center; pointer-events: none;
  filter: drop-shadow(0 6px 24px rgba(0, 0, 0, .85));
}
#capa-title .menu-crests img { width: 9vmin; height: 10.8vmin; }
#capa-title .menu-crests .vs { font-size: 3vmin; }
#capa-title .title { font-size: 11vmin; margin: 1vmin 0 0; }
#capa-title .title span { font-size: .3em; font-weight: 700; letter-spacing: .6em; background: none; color: var(--gold-hi); -webkit-text-fill-color: var(--gold-hi); text-shadow: 0 2px 10px #000; }
body.capa #app::after {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 46%; z-index: 25; pointer-events: none;
  background: linear-gradient(180deg, rgba(10, 8, 6, .55), rgba(10, 8, 6, 0));
}

/* ---------- Responsivo ---------- */
/* Telas largas em pé (tablet) e PC: HUD com largura máxima, centralizado */
@media (min-width: 640px) {
  .player-panel, #actions { align-self: center; width: min(600px, calc(100% - 16px)); }
  #actions { border: 1px solid rgba(226, 183, 102, .45); border-bottom: 0; border-radius: 14px 14px 0 0; }
  #log { left: 50%; right: auto; width: min(600px, 100%); transform: translate(-50%, 100%); }
  #log.open { transform: translate(-50%, 0); }
  .pname { font-size: 17px; }
  .crest { width: 36px; height: 43px; }
}
@media (min-width: 1000px) and (min-height: 700px) {
  .act svg { width: 40px; height: 40px; padding: 9px; }
  .act { font-size: 10px; }
  #turn-label { font-size: 13px; }
}
/* Deitado e baixo (celular na horizontal): jogadores à esquerda, botões à direita, tabuleiro no meio */
@media (orientation: landscape) and (max-height: 560px) {
  #hud { display: block; }
  .player-panel { position: absolute; left: calc(8px + env(safe-area-inset-left, 0px)); width: min(230px, 28vw); margin: 0; min-height: 44px; }
  #panel-b, #hud.flip #panel-w { top: calc(8px + var(--safe-t)); bottom: auto; margin: 0; }
  #panel-w, #hud.flip #panel-b { bottom: calc(8px + var(--safe-b)); top: auto; margin: 0; }
  .pside { display: none; }
  #turn-label { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); margin: 0; }
  #actions {
    position: absolute; right: 0; top: 0; bottom: 0; width: calc(66px + env(safe-area-inset-right, 0px)); margin: 0;
    flex-direction: column; justify-content: center; gap: 2px;
    padding: 6px env(safe-area-inset-right, 0px) 6px 0; border-top: 0; border-left: 1px solid rgba(226, 183, 102, .45);
    background: linear-gradient(90deg, rgba(30, 22, 16, .9), rgba(10, 8, 6, .97));
  }
  .act { flex: 0 1 auto; min-height: 0; padding: 3px 0; }
  .act svg { width: 30px; height: 30px; padding: 6px; }
  #log {
    left: auto; right: calc(66px + env(safe-area-inset-right, 0px)); top: 0; bottom: 0; width: min(300px, 45vw); max-height: none;
    padding: 10px 14px; border-radius: 0; border-top: 0; border-left: 1px solid rgba(226, 183, 102, .55);
    transform: translateX(110%);
  }
  #log.open { transform: translateX(0); }
  #log .grip { display: none; }
  #moves { columns: 1; }
  .overlay { padding: 8px; }
  #menu.overlay { place-items: center; }
  .panel { padding: 14px 16px; }
  .menu-crests { display: none; }
  .title { font-size: 24px; margin: 0 0 8px; }
  .opt { margin-bottom: 8px; }
  .btn { min-height: 40px; padding: 8px 12px; }
  .btn.primary { margin-top: 8px; padding: 10px 12px; }
  #toast { font-size: 28px; }
}
