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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d0906;
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
}

#scene {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#hud {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  padding: 18px 24px;
  pointer-events: none;
  color: #f3e6d3;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
  z-index: 10;
}

#title {
  font-size: 22px;
  letter-spacing: 2px;
  font-weight: 600;
}

#hint {
  margin-top: 4px;
  font-size: 13px;
  opacity: 0.75;
}

#loading {
  position: fixed;
  inset: 0;
  background-color: #0d0906;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.6s ease;
  overflow: hidden; /* la pagina non scrolla mai: al massimo scrolla solo il testo dentro #welcome */
}

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

#loading-text {
  color: #f3e6d3;
  font-size: 16px;
  letter-spacing: 3px;
  text-transform: uppercase;
  opacity: 0.8;
}

#level-progress { margin-top: 12px; font-size: 22px; font-weight: 700; }
#level-rules { margin-top: 5px; max-width: 650px; font-size: 13px; line-height: 1.5; }
#level-overlay { position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; background: rgba(13, 9, 6, .65); color: #fff0d6; text-align: center; pointer-events: auto; }
#level-overlay.hidden { display: none; }
#level-heading { font-size: clamp(48px, 10vw, 112px); font-weight: 800; text-shadow: 0 4px 24px #000; }
#level-subtitle { font-size: clamp(16px, 3vw, 24px); }
@media (max-width: 600px) { #hud { padding: 12px; } #hint, #level-rules { font-size: 11px; } #level-progress { font-size: 18px; } }

#pose-editor { position:fixed; right:16px; top:16px; z-index:100; width:310px; max-width:calc(100vw - 64px); padding:16px; background:#181d27f5; color:#eef5ff; border:1px solid #35d8ff; border-radius:12px; font:14px/1.5 sans-serif; }
#pose-editor[hidden] { display:none; }
#pose-editor select { width:100%; padding:6px; }
#pose-editor button { margin:4px 0; padding:8px; cursor:pointer; }

body.pose-debug #level-overlay { display:none; }

#level-overlay.level-intro { background: none; cursor: pointer; touch-action: none; }
#level-overlay.level-intro::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: var(--level-pic-url);
  background-size: cover;
  background-position: var(--level-pic-x, 50%) 50%;
}
#level-overlay.level-intro #level-heading,
#level-overlay.level-intro #level-subtitle {
  background: none;
  padding: 0;
  border-radius: 0;
  text-shadow: 0 2px 8px #000, 0 1px 3px rgba(0,0,0,.8);
  transform: translateY(16.6667vh);
}
#level-overlay.level-intro #level-heading { font-size: clamp(22px, 4vw, 36px); }
#level-overlay.level-intro #level-subtitle { font-size: clamp(13px, 2vw, 18px); }

#level-overlay.level-lost { background: #000; }

#welcome { position:relative; width:min(640px,100%); padding:28px; color:#f3e6d3; }
#ecchi-home-link { position:absolute; top:220px; right:28px; z-index:2; display:block; }
#ecchi-home-logo { display:block; height:50px; width:auto; object-fit:contain; }
#sushi-counter { display:block; margin:12px auto 0; opacity:.7; }
#welcome-textbox {
  background: rgba(0, 0, 0, .5);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
  padding: 1px 10px;
}
#loading { overflow-y:auto; padding:24px 0; }
#welcome h1 { margin-bottom:20px; font-size:32px; }
#welcome p { margin:12px 0; line-height:1.55; }
#welcome #loading-text { letter-spacing:1px; font-size:14px; }
#start-game { padding:14px 26px; border:0; border-radius:8px; background:#efd2a1; color:#24190f; font-family:inherit; font-size:18px; font-weight:600; cursor:pointer; }
#start-game[hidden], #hud[hidden] { display:none; }
#welcome-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; margin-inline:auto; }
#welcome-actions #how-to-play-btn { grid-column:1; grid-row:1; }
#welcome-actions #ranking-btn { grid-column:2; grid-row:1; }
#welcome-actions #loading-text, #welcome-actions #start-game { grid-column:1 / -1; }
#welcome-actions :is(#how-to-play-btn, #ranking-btn) { min-width:0; padding-inline:8px; text-align:center; }
#welcome-actions :is(#how-to-play-btn, #ranking-btn), #welcome-actions #loading-text, #welcome-actions #start-game { margin:0; width:100%; }
:is(#how-to-play-btn, #ranking-btn) { padding:14px 26px; border:0; border-radius:8px; background:rgba(52,52,52,0.6); color:#f3e6d3; font-family:inherit; font-size:16px; font-weight:600; cursor:pointer; }
:is(#how-to-play-btn, #ranking-btn):hover { background:rgba(69,69,69,0.6); }
:is(#how-to-play-modal, #ranking-modal) { position:fixed; inset:0; z-index:120; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,.75); padding:24px; }
:is(#how-to-play-modal, #ranking-modal)[hidden] { display:none; }
:is(#how-to-play-content, #ranking-content) { position:relative; max-width:560px; width:100%; max-height:80vh; overflow-y:auto; background:rgba(13,9,6,.95); border-radius:16px; padding:28px; color:#f3e6d3; box-shadow:0 10px 40px rgba(0,0,0,.6); }
:is(#how-to-play-content, #ranking-content) h2 { margin-bottom:16px; font-size:22px; }
:is(#how-to-play-content, #ranking-content) p { margin:12px 0; line-height:1.55; font-size:14px; }
:is(#how-to-play-close, #ranking-close) { position:absolute; top:10px; right:10px; width:36px; height:36px; border:0; border-radius:8px; background:rgba(255,255,255,.15); color:#f3e6d3; font-size:22px; line-height:1; cursor:pointer; }
:is(#how-to-play-close, #ranking-close):hover { background:rgba(255,255,255,.3); }
#pose-editor { max-height:calc(100dvh - 32px); overflow-y:auto; padding-top:46px; }
#pose-editor #pose-close { position:absolute; top:6px; right:8px; width:34px; height:34px; margin:0; padding:0; font-size:25px; border:0; border-radius:6px; background:#ffffff18; color:white; }
#level-progress { margin-top:0; }
@media(max-height:650px) { #loading { align-items:flex-start; } }

#sushi-progress { position:fixed; right:max(24px, env(safe-area-inset-right)); bottom:max(18px, env(safe-area-inset-bottom)); font-size:22px; font-weight:700; }
@media(max-width:600px) { #sushi-progress { right:max(12px, env(safe-area-inset-right)); bottom:max(12px, env(safe-area-inset-bottom)); font-size:18px; } }

#welcome #loading-text { text-align:center; }
#start-game { display:block; }
#start-game[hidden] { display:none; }

#welcome-logo { display:block; width:min(390px, 80%); max-height:234px; object-fit:contain; object-position:left center; margin:0; }
#game-logo { display:block; width:120px; height:auto; max-height:80px; object-fit:contain; object-position:left top; pointer-events:auto; cursor:pointer; }
#level-progress { position:fixed; left:max(24px, env(safe-area-inset-left)); bottom:max(18px, env(safe-area-inset-bottom)); margin:0; }
@media(max-width:600px) { #game-logo { width:90px; max-height:60px; } #level-progress { left:max(12px, env(safe-area-inset-left)); bottom:max(12px, env(safe-area-inset-bottom)); } }

#welcome #loading-text { display:block; padding:14px 26px; border:0; border-radius:8px; background:#efd2a1; color:#24190f; font-family:inherit; font-size:18px; font-weight:600; letter-spacing:normal; text-transform:none; opacity:0.65; cursor:default; text-align:center; }
#welcome #loading-text[hidden] { display:none; }

#welcome { width:min(980px,100%); }
#welcome-columns { display:flex; align-items:flex-end; justify-content:space-between; gap:16px; font-size:13px; }
#welcome-columns #welcome-actions { flex:0 0 auto; }
#welcome-columns #welcome-ranking { flex:0 1 420px; min-width:0; }
@media(max-width:650px) { #welcome-columns { flex-direction:column; align-items:stretch; } }
#welcome-columns p { font-size:13px; }
#welcome-ranking { padding:12px 0; }
#welcome-ranking h2 { font-size:18px; margin-bottom:14px; }
.ranking-table,.score-table { width:100%; border-collapse:collapse; text-align:left; font-size:14px; }
.ranking-table td,.ranking-table th,.score-table td,.score-table th { padding:8px 10px; border-bottom:1px solid #ffffff25; overflow-wrap:anywhere; }
.ranking-table td:not(:first-child),.ranking-table th:not(:first-child),.score-table td:not(:first-child) { text-align:right; }
.own-score { font-weight:800; background:#efd2a119; }
#level-clock { position:fixed; top:20px; right:24px; font-size:26px; font-weight:700; }
#game-score { position:fixed; top:58px; right:24px; font-size:18px; font-weight:600; }
#level-details { width:min(560px,100%); }
#level-overlay { overflow-y:auto; }
#level-details p { margin:12px 0; }
#level-details button { margin:14px 6px 0; padding:12px 20px; border:0; border-radius:8px; background:#efd2a1; color:#24190f; font:inherit; cursor:pointer; }
#level-details input { padding:12px; max-width:100%; font:inherit; border-radius:6px; border:1px solid #bbb; }
@media(max-width:650px) { #level-clock { right:12px; top:12px; font-size:22px; } #game-score { right:12px; top:42px; font-size:16px; } #level-heading { font-size:42px; } }
@media(max-height:650px) { #level-overlay.level-intro { justify-content:flex-start; } }

#welcome-columns { justify-content:center; margin-top:20px; }
#welcome-columns #welcome-actions { width:min(360px,100%); }

@media (max-width:650px) {
  #welcome-logo { margin-inline:auto; object-position:center; }
  #welcome-title { text-align:center; }
  #ecchi-home-link { position:static; width:fit-content; margin:20px auto 0; }
  #ecchi-home-logo { max-width:100%; }
}

#pose-editor .pose-camera-row { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:6px; align-items:stretch; }

/* ============================================================
   Schermata iniziale: mai testo che esce sotto lo schermo (su
   schermi bassi il blocco testo scrolla internamente, mai la
   pagina), pulsanti sempre fissi al centro in basso. Blocco messo
   in fondo al file apposta, cosi' vince sulle regole sparse sopra
   a parita' di specificita' (compresa quella dentro il media query
   piu' in alto che rendeva #ecchi-home-link statico sotto i 650px).
   ============================================================ */
#loading { padding: 0; align-items: stretch; }
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(640px, 100%);
  height: 100%;
  margin: 0 auto;
  padding: clamp(10px, 2.5dvh, 28px) 20px calc(clamp(64px, 16dvh, 120px) + env(safe-area-inset-bottom));
  overflow-y: auto;
}
#welcome-title { flex: 0 0 auto; margin-bottom: clamp(8px, 2dvh, 20px); text-align: center; }
#welcome-logo { display: block; width: min(460px, 80vw); max-height: min(280px, 30dvh); margin-inline: auto; object-position: center; }
#welcome-textbox { flex: 0 1 auto; }
#welcome-textbox p { font-size: clamp(12px, 1.8dvh, 16px); line-height: 1.4; margin: clamp(6px, 1dvh, 12px) 0; }
#welcome-columns {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(340px, calc(100% - 32px));
  margin: 0;
  justify-content: center;
  z-index: 5;
}
#welcome-columns #welcome-actions { width: 100%; }
#lang-toggle {
  position: fixed;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  z-index: 6;
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  background: rgba(0,0,0,.45);
  color: #f3e6d3;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  cursor: pointer;
}
#lang-toggle:hover { background: rgba(0,0,0,.65); }
#ecchi-home-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  margin: 0;
  z-index: 5;
}
#ecchi-home-logo { height: clamp(28px, 5dvh, 50px); width: auto; max-width: none; }
#sushi-counter {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  margin: 0;
  z-index: 5;
}
