:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --glass: rgba(5, 8, 13, .72);
  --line: rgba(255, 255, 255, .18);
  --accent: #ffcf2f;
  --accent2: #34d87a;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #020306; }
body { display: grid; place-items: center; }
button { font: inherit; }

#game-shell {
  position: relative;
  width: min(100vw, calc(100vh * 4 / 3));
  height: min(100vh, calc(100vw * 3 / 4));
  overflow: hidden;
  background: #000;
  user-select: none;
  touch-action: none;
  isolation: isolate;
}

#game, #game canvas, #gesture-overlay {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

#gesture-overlay { z-index: 4; pointer-events: none; }

.hidden-ui { opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.playing .hidden-ui { opacity: 1; }

#hud {
  position: absolute;
  z-index: 10;
  top: clamp(8px, 1.4vw, 16px);
  left: clamp(8px, 1.4vw, 16px);
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.brand, .score-card, .icon-btn, #message, #meters {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: 0 8px 28px rgba(0,0,0,.26);
  backdrop-filter: blur(8px);
}

.brand {
  display: grid;
  align-content: center;
  border-radius: 12px;
  padding: 7px 13px;
  line-height: .95;
  min-width: 112px;
}
.brand b { font-size: clamp(13px, 1.7vw, 20px); letter-spacing: .05em; }
.brand span { color: var(--accent); font-size: clamp(10px, 1.05vw, 13px); font-weight: 900; letter-spacing: .18em; margin-top: 4px; }

.score-card {
  min-width: clamp(65px, 8vw, 90px);
  padding: 7px 10px;
  border-radius: 12px;
  text-align: center;
}
.score-card > span { display: block; font-size: clamp(8px, .9vw, 11px); letter-spacing: .11em; opacity: .72; font-weight: 800; }
.score-card strong { display: block; font-size: clamp(18px, 2.2vw, 27px); line-height: 1.05; margin-top: 3px; }

#top-actions {
  position: absolute;
  z-index: 10;
  top: clamp(8px, 1.4vw, 16px);
  right: clamp(8px, 1.4vw, 16px);
  display: flex;
  gap: 7px;
}
.icon-btn {
  width: clamp(35px, 4vw, 43px);
  height: clamp(35px, 4vw, 43px);
  border-radius: 11px;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
}
.icon-btn:hover { background: rgba(25,28,35,.9); }

#message {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: clamp(10px, 1.5vw, 18px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 74%;
  padding: 9px 15px;
  border-radius: 999px;
  text-align: center;
  font-weight: 800;
  font-size: clamp(11px, 1.45vw, 16px);
  text-shadow: 0 1px 3px #000;
}

#meters {
  position: absolute;
  z-index: 10;
  left: clamp(8px, 1.4vw, 16px);
  bottom: clamp(8px, 1.4vw, 16px);
  width: clamp(180px, 24vw, 300px);
  padding: 9px 11px;
  border-radius: 12px;
  transform: translateY(130%);
  transition: transform .18s ease, opacity .25s ease;
}
#meters.visible { transform: translateY(0); }
.meter-row { display: grid; grid-template-columns: 46px 1fr 38px; gap: 7px; align-items: center; min-height: 21px; }
.meter-row + .meter-row { margin-top: 5px; }
.meter-row > span { font-size: 9px; font-weight: 900; letter-spacing: .08em; opacity: .78; }
.meter-row > b { font-size: 10px; text-align: right; }
.meter, .curve-meter { position: relative; height: 7px; border-radius: 99px; background: rgba(255,255,255,.14); overflow: hidden; }
.meter i { display: block; width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #48e98d, #ffe14e 58%, #ff564f); transition: width .04s linear; }
.curve-meter { overflow: visible; background: linear-gradient(90deg, rgba(59,150,255,.55), rgba(255,255,255,.18), rgba(255,94,94,.55)); }
.curve-meter::after { content: ""; position: absolute; left: 50%; top: -2px; height: 11px; width: 1px; background: rgba(255,255,255,.55); }
.curve-meter i { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: #fff; top: -1px; left: calc(50% - 4px); box-shadow: 0 0 7px rgba(255,255,255,.8); }

.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 35%, rgba(0,0,0,.18), rgba(0,0,0,.75));
  transition: opacity .3s ease;
}
.screen.active { opacity: 1; pointer-events: auto; }

.panel {
  width: min(92%, 540px);
  max-height: 94%;
  overflow: auto;
  padding: clamp(19px, 3vw, 34px);
  border-radius: 24px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(6, 8, 12, .86);
  box-shadow: 0 24px 80px rgba(0,0,0,.52);
  backdrop-filter: blur(13px);
  text-align: center;
}
.kicker { color: var(--accent); font-size: 11px; font-weight: 900; letter-spacing: .23em; }
.hero-panel h1 { margin: 6px 0 8px; font-size: clamp(37px, 7vw, 73px); line-height: .82; letter-spacing: -.055em; }
.hero-panel h1 span { color: var(--accent); }
.panel > p { margin: 14px auto 18px; max-width: 410px; color: rgba(255,255,255,.73); line-height: 1.4; font-size: clamp(12px, 1.5vw, 15px); }
.difficulty-title { margin: 17px 0 8px; font-size: 10px; font-weight: 900; letter-spacing: .17em; opacity: .65; }
.difficulty-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.difficulty {
  min-height: 62px;
  padding: 9px 6px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  background: rgba(255,255,255,.06);
  color: #fff;
  cursor: pointer;
}
.difficulty b { display: block; font-size: 12px; }
.difficulty small { display: block; margin-top: 4px; opacity: .55; font-size: 9px; line-height: 1.2; }
.difficulty:hover, .difficulty.selected { border-color: var(--accent); background: rgba(255,207,47,.12); }

.primary, .secondary {
  width: 100%;
  min-height: 48px;
  border-radius: 13px;
  font-weight: 950;
  letter-spacing: .04em;
  cursor: pointer;
}
.primary { margin-top: 14px; border: 0; background: var(--accent); color: #111; }
.primary:hover { filter: brightness(1.06); }
.secondary { margin-top: 8px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.06); color: #fff; }

.howto { margin-top: 16px; padding-top: 13px; border-top: 1px solid rgba(255,255,255,.1); display: grid; gap: 3px; font-size: 10px; color: rgba(255,255,255,.6); }
.howto b { color: #fff; font-size: 9px; letter-spacing: .14em; margin-bottom: 2px; }

.result-panel h2 { font-size: clamp(28px, 5vw, 48px); margin: 8px 0 2px; }
.big-score { display: flex; align-items: baseline; justify-content: center; line-height: .9; margin: 9px 0; }
.big-score strong { font-size: clamp(62px, 12vw, 112px); color: var(--accent); letter-spacing: -.08em; }
.big-score span { font-size: clamp(21px, 4vw, 38px); font-weight: 900; opacity: .65; margin-left: 10px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 18px 0 5px; }
.result-stats div { background: rgba(255,255,255,.055); border: 1px solid rgba(255,255,255,.1); border-radius: 11px; padding: 10px 5px; }
.result-stats span { display: block; font-size: 8px; letter-spacing: .1em; opacity: .55; font-weight: 900; }
.result-stats b { display: block; margin-top: 3px; font-size: 19px; }

#flash { position: absolute; inset: 0; z-index: 15; pointer-events: none; opacity: 0; background: rgba(255,255,255,.22); }
#flash.go { animation: flash .28s ease; }
@keyframes flash { 0% { opacity: .55 } 100% { opacity: 0 } }

@media (max-width: 620px), (max-height: 520px) {
  .brand { display: none; }
  .score-card { min-width: 58px; padding: 5px 7px; }
  .panel { border-radius: 18px; }
  .howto { display: none; }
  .difficulty small { display: none; }
  #meters { width: 175px; }
}

/* ---------- Disputa completa ---------- */
.playing #top-actions { pointer-events: auto; }

.score-card.player strong { color: #ffffff; }
.score-card.cpu strong { color: #ffcf2f; }

#turn-indicator {
  position: absolute;
  z-index: 10;
  top: clamp(62px, 8vw, 88px);
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(5,8,13,.78);
  box-shadow: 0 8px 28px rgba(0,0,0,.24);
  backdrop-filter: blur(8px);
  font-size: clamp(9px, 1vw, 12px);
  font-weight: 950;
  letter-spacing: .12em;
  white-space: nowrap;
}
#turn-indicator.defend { color: #ffcf2f; }
#turn-indicator.sudden { color: #ff7c72; }

#defense-controls {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: clamp(48px, 6vw, 64px);
  transform: translate(-50%, 18px);
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 7px;
  width: min(72%, 390px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
#defense-controls.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}
#defense-controls button {
  min-height: 48px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 12px;
  background: rgba(5,8,13,.82);
  color: #fff;
  box-shadow: 0 8px 28px rgba(0,0,0,.24);
  backdrop-filter: blur(8px);
  cursor: pointer;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
}
#defense-controls button:hover,
#defense-controls button:active {
  border-color: var(--accent);
  background: rgba(255,207,47,.14);
}
#defense-controls button span { font-size: 18px; line-height: 1; }
#defense-controls button b { font-size: 9px; letter-spacing: .08em; }

.versus-score {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 16px;
  margin: 12px auto 10px;
  max-width: 330px;
}
.versus-score > div { display: grid; gap: 2px; }
.versus-score span {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .14em;
  opacity: .62;
}
.versus-score strong {
  font-size: clamp(56px, 11vw, 96px);
  line-height: .88;
  color: var(--accent);
}
.versus-score > b {
  font-size: clamp(22px, 4vw, 36px);
  opacity: .6;
  padding-bottom: 8px;
}

@media (max-width: 620px), (max-height: 520px) {
  #turn-indicator { top: 56px; }
  #defense-controls { width: min(86%, 380px); bottom: 46px; }
  #defense-controls button { min-height: 42px; }
  #defense-controls button span { font-size: 15px; }
}

/* ---------- V8: PC + Android + iPhone ---------- */
html {
  width: 100%;
  height: 100%;
  background: #020306;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

#game-shell {
  width: min(100vw, calc(100vh * 4 / 3));
  height: min(100vh, calc(100vw * 3 / 4));
  width: min(100dvw, calc(100dvh * 4 / 3));
  height: min(100dvh, calc(100dvw * 3 / 4));
  max-width: 100vw;
  max-height: 100vh;
  max-width: 100dvw;
  max-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

button, .difficulty, #defense-controls button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Mantém HUD/botões fora do notch e da Dynamic Island. */
#hud {
  left: max(clamp(8px, 1.4vw, 16px), env(safe-area-inset-left));
  top: max(clamp(8px, 1.4vw, 16px), env(safe-area-inset-top));
}

#top-actions {
  right: max(clamp(8px, 1.4vw, 16px), env(safe-area-inset-right));
  top: max(clamp(8px, 1.4vw, 16px), env(safe-area-inset-top));
}

#meters {
  left: max(clamp(8px, 1.4vw, 16px), env(safe-area-inset-left));
  bottom: max(clamp(8px, 1.4vw, 16px), env(safe-area-inset-bottom));
}

#message {
  bottom: max(clamp(10px, 1.5vw, 18px), calc(env(safe-area-inset-bottom) + 4px));
}

#defense-controls {
  bottom: max(clamp(48px, 6vw, 64px), calc(env(safe-area-inset-bottom) + 44px));
}

.screen {
  padding-top: max(18px, env(safe-area-inset-top));
  padding-right: max(18px, env(safe-area-inset-right));
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  padding-left: max(18px, env(safe-area-inset-left));
}

/* Aviso automático somente em celular/tablet touch na vertical. */
#orientation-gate {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 100;
  place-items: center;
  align-content: center;
  gap: 9px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  text-align: center;
  background: radial-gradient(circle at 50% 42%, rgba(30,34,42,.97), rgba(3,4,7,.995));
  color: #fff;
}

#orientation-gate .rotate-phone {
  font-size: clamp(48px, 17vw, 76px);
  line-height: 1;
  animation: phoneHint 1.8s ease-in-out infinite;
}

#orientation-gate strong {
  font-size: clamp(20px, 7vw, 32px);
  letter-spacing: .08em;
}

#orientation-gate span {
  max-width: 310px;
  color: rgba(255,255,255,.7);
  font-size: clamp(12px, 4vw, 16px);
  line-height: 1.35;
}

@keyframes phoneHint {
  0%, 100% { transform: rotate(0deg); }
  45%, 55% { transform: rotate(90deg); }
}

/* "coarse" evita bloquear um PC apenas porque a janela está estreita. */
@media (orientation: portrait) and (pointer: coarse) and (max-width: 900px) {
  #orientation-gate { display: grid; }
}

/* Mobile deitado: preserva a quadra inteira e compacta só a interface. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  #hud {
    gap: 5px;
  }

  .brand {
    min-width: 86px;
    padding: 5px 9px;
    border-radius: 10px;
  }
  .brand b { font-size: 12px; }
  .brand span { font-size: 8px; }

  .score-card {
    min-width: 55px;
    padding: 5px 7px;
    border-radius: 10px;
  }
  .score-card > span { font-size: 7px; }
  .score-card strong { font-size: 18px; }

  #turn-indicator {
    top: max(50px, calc(env(safe-area-inset-top) + 45px));
    padding: 5px 9px;
    font-size: 8px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    font-size: 16px;
  }

  #message {
    max-width: 64%;
    padding: 6px 10px;
    font-size: 10px;
  }

  #meters {
    width: 168px;
    padding: 6px 8px;
  }

  #defense-controls {
    width: min(72%, 355px);
    grid-template-columns: repeat(3, minmax(74px, 1fr));
    gap: 5px;
  }
  #defense-controls button {
    min-height: 44px;
  }

  .panel {
    width: min(88%, 490px);
    max-height: calc(100dvh - 16px);
    padding: 15px 18px;
    border-radius: 16px;
  }
  .hero-panel h1 {
    margin: 4px 0 5px;
    font-size: clamp(32px, 9vh, 54px);
  }
  .panel > p {
    margin: 7px auto 9px;
    font-size: 11px;
  }
  .difficulty-title { margin: 8px 0 5px; }
  .difficulty { min-height: 46px; }
  .primary, .secondary { min-height: 42px; }
  .howto { display: none; }
  .result-stats { margin-top: 9px; }
}

/* Hover só em equipamento que realmente possui mouse/trackpad. */
@media (hover: none) {
  .icon-btn:hover,
  .primary:hover,
  .difficulty:hover,
  #defense-controls button:hover {
    filter: none;
  }
}

/* Botão some quando o navegador não oferece uma API de tela cheia utilizável. */
#fullscreen.fullscreen-unsupported {
  display: none;
}


/* ---------- V9: celular em tela cheia, inclusive modo retrato ---------- */
#orientation-gate { display: none !important; }

/* No celular/tablet touch o jogo ocupa a viewport inteira. A câmera faz o recorte
   necessário sem deformar a quadra. No PC continua no enquadramento 4:3 original. */
@media (pointer: coarse) and (max-width: 900px),
       (pointer: coarse) and (max-height: 900px) {
  html, body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    overflow: hidden;
  }

  body {
    display: block;
  }

  #game-shell {
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
  }
}

/* Layout específico para celular em pé. */
@media (pointer: coarse) and (orientation: portrait) and (max-width: 900px) {
  #hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(7px, env(safe-area-inset-left));
    gap: 5px;
  }

  .brand { display: none; }

  .score-card {
    min-width: 64px;
    padding: 6px 8px;
    border-radius: 11px;
  }
  .score-card > span { font-size: 8px; }
  .score-card strong { font-size: 21px; }

  #top-actions {
    top: max(8px, env(safe-area-inset-top));
    right: max(7px, env(safe-area-inset-right));
    gap: 5px;
  }
  .icon-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 10px;
    font-size: 16px;
  }

  #turn-indicator {
    top: max(60px, calc(env(safe-area-inset-top) + 54px));
    max-width: calc(100% - 20px);
    padding: 6px 10px;
    font-size: 9px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #message {
    bottom: max(12px, calc(env(safe-area-inset-bottom) + 6px));
    max-width: calc(100% - 24px);
    padding: 9px 13px;
    font-size: 12px;
    white-space: normal;
  }

  #meters {
    left: 8px;
    right: 8px;
    bottom: max(58px, calc(env(safe-area-inset-bottom) + 54px));
    width: auto;
    padding: 8px 10px;
  }

  #defense-controls {
    left: 8px;
    right: 8px;
    bottom: max(58px, calc(env(safe-area-inset-bottom) + 54px));
    width: auto;
    transform: translateY(18px);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  #defense-controls.visible {
    transform: translateY(0);
  }
  #defense-controls button {
    min-width: 0;
    min-height: 56px;
    padding: 7px 4px;
  }
  #defense-controls button span { font-size: 20px; }
  #defense-controls button b { font-size: 9px; }

  .screen {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
  }

  .panel {
    width: min(94%, 480px);
    max-height: calc(100dvh - 24px);
    padding: 22px 18px;
    border-radius: 20px;
  }

  .hero-panel h1 {
    font-size: clamp(46px, 14vw, 66px);
    margin: 7px 0 10px;
  }

  .panel > p {
    margin: 11px auto 14px;
    font-size: 13px;
  }

  .difficulty-grid { gap: 6px; }
  .difficulty {
    min-height: 58px;
    padding: 8px 4px;
  }
  .difficulty b { font-size: 11px; }
  .difficulty small { display: none; }

  .primary, .secondary { min-height: 50px; }
  .howto { display: none; }

  .versus-score strong { font-size: clamp(62px, 20vw, 88px); }
  .result-stats { gap: 5px; }
  .result-stats div { padding: 9px 3px; }
}
