*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:#0a0a0a;
  --surface:#111;
  --surface2:#151515;
  --border:#1e1e1e;
  --accent:#c8f530;
  --accent-dim:rgba(200,245,48,.12);
  --accent-glow:rgba(200,245,48,.35);
  --text:#f0f0f0;
  --muted:#555;
  --danger:#ff4d4d;

  /* Ajuste automático conforme a tela do celular */
  --game-size: min(340px, calc(100vw - 28px), calc(100svh - 318px));
  --dpad-btn: clamp(42px, 7.4svh, 56px);
}

html{
  min-height:100%;
  background:var(--bg);
}

body{
  background:var(--bg);
  color:var(--text);
  font-family:'DM Mono', monospace;
  min-height:100svh;
  display:flex;
  justify-content:center;
  align-items:flex-start;
  overflow:auto;
  padding:
    max(10px, env(safe-area-inset-top))
    12px
    max(14px, env(safe-area-inset-bottom));
  -webkit-text-size-adjust:100%;
  touch-action:manipulation;
}

body::before{
  content:'';
  position:fixed;
  inset:0;
  background-image:
    linear-gradient(rgba(200,245,48,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200,245,48,.03) 1px, transparent 1px);
  background-size:40px 40px;
  pointer-events:none;
}

#welcomeScreen{
  position:fixed;
  inset:0;
  background:var(--bg);
  display:flex;
  justify-content:center;
  align-items:center;
  z-index:100;
  transition:opacity .4s;
}

#welcomeScreen.fade-out{
  opacity:0;
  pointer-events:none;
}

.welcome-box{
  width:min(340px, calc(100vw - 28px));
  display:flex;
  flex-direction:column;
  align-items:center;
}

.welcome-logo{
  font-family:'Bebas Neue', sans-serif;
  font-size:64px;
  letter-spacing:.08em;
  color:var(--accent);
  text-shadow:0 0 60px var(--accent-glow);
  line-height:1;
  margin-bottom:6px;
  text-align:center;
}

.welcome-tag{
  font-size:10px;
  letter-spacing:.22em;
  color:var(--muted);
  text-transform:uppercase;
  margin-bottom:34px;
  text-align:center;
}

.welcome-field-label{
  font-size:9px;
  letter-spacing:.22em;
  color:var(--muted);
  text-transform:uppercase;
  align-self:flex-start;
  margin-bottom:6px;
}

.welcome-input{
  width:100%;
  height:48px;
  background:var(--surface);
  border:1px solid var(--border);
  color:var(--text);
  font-family:'DM Mono', monospace;
  font-size:15px;
  padding:0 14px;
  outline:none;
  transition:border-color .2s;
  margin-bottom:16px;
  letter-spacing:.04em;
}

.welcome-input:focus{ border-color:var(--accent); }
.welcome-input::placeholder{ color:var(--muted); font-size:12px; }

.error-box{
  width:100%;
  min-height:20px;
  color:var(--danger);
  font-size:11px;
  line-height:1.5;
  margin-bottom:14px;
  text-align:left;
}

.welcome-play-btn, .btn-start, .share-btn{
  width:100%;
  height:52px;
  background:var(--accent);
  border:none;
  color:#0a0a0a;
  font-family:'Bebas Neue', sans-serif;
  font-size:24px;
  letter-spacing:.18em;
  cursor:pointer;
  transition:opacity .15s, transform .1s;
}

.welcome-play-btn:hover, .btn-start:hover, .share-btn:hover{ opacity:.88; }
.welcome-play-btn:active, .btn-start:active, .share-btn:active{ transform:scale(.98); }
.welcome-play-btn:disabled{ opacity:.35; cursor:wait; }

.wrapper{
  display:flex;
  flex-direction:column;
  align-items:center;
  position:relative;
  z-index:1;
}

.header{
  width:var(--game-size);
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  padding:0 0 clamp(8px, 1.8svh, 14px) 0;
  border-bottom:1px solid var(--border);
}

.logo{
  font-family:'Bebas Neue', sans-serif;
  font-size:clamp(34px, 6svh, 42px);
  letter-spacing:.08em;
  color:var(--accent);
  line-height:1;
  text-shadow:0 0 40px var(--accent-glow);
}

.header-right{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:2px;
  padding-bottom:4px;
  max-width:170px;
}

.player-name{
  font-size:10px;
  color:var(--text);
  letter-spacing:.06em;
  text-align:right;
  word-break:break-word;
}

.version{
  font-size:9px;
  color:var(--muted);
  letter-spacing:.15em;
  text-transform:uppercase;
}

.canvas-wrap{
  position:relative;
  width:var(--game-size);
  height:var(--game-size);
  border-left:1px solid var(--border);
  border-right:1px solid var(--border);
}

canvas{
  display:block;
  width:var(--game-size);
  height:var(--game-size);
}

.overlay{
  position:absolute;
  inset:0;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:10px;
  background:rgba(10,10,10,.90);
  backdrop-filter:blur(4px);
  transition:opacity .3s;
  text-align:center;
  padding:20px;
}

.overlay.hidden{ opacity:0; pointer-events:none; }

.overlay-title{
  font-family:'Bebas Neue', sans-serif;
  font-size:44px;
  letter-spacing:.08em;
  color:var(--accent);
  text-shadow:0 0 60px var(--accent-glow);
  line-height:1;
}

.overlay-sub{
  font-size:11px;
  letter-spacing:.08em;
  color:#aaa;
  text-transform:uppercase;
  line-height:1.6;
}

.final-score{
  font-size:11px;
  letter-spacing:.06em;
  color:var(--text);
  text-transform:uppercase;
  margin-top:6px;
  line-height:1.7;
}

.share-small-btn{
  margin-top:8px;
  width:auto;
  min-width:220px;
  height:40px;
  padding:0 16px;
  background:var(--accent);
  border:none;
  color:#0a0a0a;
  font-family:'Bebas Neue', sans-serif;
  font-size:18px;
  letter-spacing:.14em;
  cursor:pointer;
}

.pause-banner{
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%, -50%);
  font-family:'Bebas Neue', sans-serif;
  font-size:36px;
  letter-spacing:.15em;
  color:var(--text);
  opacity:0;
  pointer-events:none;
  transition:opacity .2s;
}

.pause-banner.visible{ opacity:1; }

.stats{
  width:var(--game-size);
  display:grid;
  grid-template-columns:1fr 1px 1fr 1px 1fr;
  border:1px solid var(--border);
  border-top:none;
}

.stat{
  padding:clamp(7px, 1.6svh, 12px) 12px;
  display:flex;
  flex-direction:column;
  gap:2px;
}

.stat-divider{ background:var(--border); }

.stat-label{
  font-size:9px;
  letter-spacing:.2em;
  color:var(--muted);
  text-transform:uppercase;
}

.stat-value{
  font-size:clamp(16px, 3svh, 20px);
  font-weight:500;
  color:var(--text);
  letter-spacing:.05em;
}

.stat-value.accent{ color:var(--accent); }

.controls-area{
  width:var(--game-size);
  margin-top:clamp(8px, 1.8svh, 18px);
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:8px;
}

.btn-start{
  height:clamp(40px, 6.8svh, 48px);
  font-size:clamp(18px, 3svh, 22px);
}

.dpad{
  display:grid;
  grid-template-columns:var(--dpad-btn) var(--dpad-btn) var(--dpad-btn);
  grid-template-rows:var(--dpad-btn) var(--dpad-btn) var(--dpad-btn);
  gap:6px;
}

.dpad-btn{
  background:var(--surface);
  border:1px solid var(--border);
  color:var(--text);
  font-size:18px;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:background .1s, border-color .1s, color .1s;
  user-select:none;
  -webkit-tap-highlight-color:transparent;
}

.dpad-btn:active, .dpad-btn.pressed{
  background:var(--accent-dim);
  border-color:var(--accent);
  color:var(--accent);
}

.dpad-center{
  background:var(--surface);
  border:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition:background .1s, border-color .1s;
}

.dpad-center:active{
  background:var(--accent-dim);
  border-color:var(--accent);
}

.pause-icon{
  width:18px;
  height:18px;
  display:flex;
  gap:5px;
  align-items:center;
  justify-content:center;
}

.pause-icon span{
  display:block;
  width:4px;
  height:16px;
  background:var(--muted);
}

.share-card{
  position:fixed;
  left:-9999px;
  top:0;
  width:1080px;
  height:1080px;
  background:#0a0a0a;
  color:#f0f0f0;
  font-family:Arial, sans-serif;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  text-align:center;
  padding:80px;
}

.share-card .big{
  font-family:'Bebas Neue', Arial, sans-serif;
  font-size:112px;
  letter-spacing:.08em;
  color:#c8f530;
}

.share-card .score{
  font-size:74px;
  margin-top:34px;
  font-weight:700;
}

.share-card .text{
  margin-top:24px;
  font-size:34px;
  color:#cfcfcf;
  line-height:1.35;
}

.share-card .link{
  margin-top:52px;
  font-size:28px;
  color:#c8f530;
}

@media(max-height:700px){
  :root{
    --game-size: min(320px, calc(100vw - 28px), calc(100svh - 270px));
    --dpad-btn: clamp(38px, 7svh, 50px);
  }
  .controls-area{ gap:6px; }
  .dpad{ gap:5px; }
  .overlay-title{ font-size:38px; }
  .overlay-sub, .final-score{ font-size:10px; }
}

@media(max-height:610px){
  :root{
    --game-size: min(300px, calc(100vw - 28px), calc(100svh - 235px));
    --dpad-btn: clamp(34px, 6.6svh, 44px);
  }
  .header-right{ display:none; }
  .btn-start{ height:38px; }
  .stat-label{ font-size:8px; }
}

@media(max-width:360px){
  :root{
    --game-size: min(320px, calc(100vw - 22px), calc(100svh - 300px));
  }
  body{ padding-left:10px; padding-right:10px; }
}
