* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #0d1b2a; color: #fff;
  font-family: "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }

button {
  font: inherit; color: #fff; cursor: pointer; border: none; border-radius: 10px;
  background: linear-gradient(#3b4a63, #263247); padding: 10px 16px;
  box-shadow: 0 3px 0 #151c29, 0 4px 12px rgba(0,0,0,.35);
  transition: transform .08s, filter .15s;
}
button:hover { filter: brightness(1.15); }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 #151c29; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.panel-s {
  background: rgba(10, 16, 28, .55); border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
#hudLeft { position: absolute; left: 14px; top: 14px; padding: 10px 14px 12px; width: 250px; }
#scoreLabel { font-size: 11px; letter-spacing: 3px; opacity: .65; }
#score {
  font-size: 34px; font-weight: 800; line-height: 1.05; color: #ffe066;
  text-shadow: 0 2px 0 #8a5a00, 0 0 16px rgba(255,200,40,.35);
  font-variant-numeric: tabular-nums;
}
#comboWrap { height: 22px; margin: 2px 0 6px; }
#combo { font-size: 13px; font-weight: 700; color: #80deea; height: 16px; }
.cbar { height: 3px; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; }
#comboBar { height: 100%; width: 0; background: #80deea; }
.bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.bar .ico { width: 20px; text-align: center; font-size: 15px; }
.bar .key { font-size: 10px; opacity: .55; border: 1px solid rgba(255,255,255,.3); border-radius: 4px; padding: 0 4px; }
.track { flex: 1; height: 12px; background: rgba(0,0,0,.45); border-radius: 6px; overflow: hidden; border: 1px solid rgba(255,255,255,.15); }
#fuelFill { height: 100%; width: 100%; background: linear-gradient(90deg, #e53935, #ffb300 40%, #7cb342); transition: width .1s; }
#nitroFill { height: 100%; width: 0; background: linear-gradient(90deg, #1e88e5, #80d8ff); box-shadow: 0 0 8px #40c4ff; }
#fuelBox.low .track { animation: blink .5s infinite alternate; }
@keyframes blink { from { box-shadow: 0 0 0 rgba(255,0,0,0); } to { box-shadow: 0 0 12px #ff1744; border-color: #ff1744; } }
#effects { margin-top: 6px; }
.effect { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-top: 5px; }
.effect img { width: 18px; height: 18px; }
.effect span { width: 92px; white-space: nowrap; }
.effect i { flex: 1; height: 6px; background: rgba(0,0,0,.4); border-radius: 3px; overflow: hidden; }
.effect b { display: block; height: 100%; }

#hudRight { position: absolute; right: 14px; top: 14px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
#hudRight .btns { align-self: flex-end; display: flex; gap: 6px; pointer-events: auto; }
#hudRight .btns button { padding: 4px 9px; font-size: 15px; border-radius: 8px; }
#minimap {
  width: 176px; height: 176px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.75); box-shadow: 0 6px 18px rgba(0,0,0,.45), inset 0 0 0 2px #000;
  background: #111;
}
#clock, #biome {
  font-size: 13px; font-weight: 700; background: rgba(10,16,28,.55); padding: 3px 10px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12); font-variant-numeric: tabular-nums;
}
#biome { font-weight: 500; opacity: .85; min-height: 22px; }

#speedo { position: absolute; left: 14px; bottom: 14px; padding: 8px 16px; text-align: left; }
#speed { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
#speedo small { font-size: 12px; opacity: .7; margin-left: 4px; }
#dist { font-size: 12px; opacity: .75; }

#toasts { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast {
  background: rgba(10,16,28,.8); border: 1px solid rgba(255,255,255,.18); padding: 7px 16px; border-radius: 20px;
  font-weight: 700; font-size: 15px; white-space: nowrap;
  animation: toastIn .25s ease-out, toastOut .4s ease-in 2.2s forwards;
}
.toast.good { border-color: #69f0ae; color: #b9f6ca; }
.toast.bad { border-color: #ff5252; color: #ffcdd2; }
.toast.gold { border-color: #ffd54f; color: #ffe082; font-size: 18px; }
.toast.info { border-color: #40c4ff; color: #b3e5fc; }
.toast.dim { opacity: .8; font-weight: 500; font-size: 13px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }
#debug { position: absolute; bottom: 4px; right: 8px; font: 11px monospace; background: rgba(0,0,0,.6); padding: 2px 6px; }

/* ---------- Touch ---------- */
#touch { position: fixed; left: 0; right: 0; bottom: 0; height: 0; pointer-events: none; }
.tgroup { position: absolute; bottom: 20px; display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
.tgroup.left { left: 20px; bottom: 90px; }
.tgroup.right { right: 20px; flex-wrap: wrap; justify-content: flex-end; width: 240px; }
#touch button {
  width: 74px; height: 74px; border-radius: 50%; font-size: 26px; background: rgba(255,255,255,.14);
  border: 2px solid rgba(255,255,255,.35); box-shadow: none; touch-action: none;
}
#touch button.small { width: 64px; height: 44px; border-radius: 12px; font-size: 12px; font-weight: 800; }
#touch button.nitro { background: rgba(30,136,229,.35); }
#touch button.gas { background: rgba(105,240,174,.25); width: 84px; height: 84px; }
#touch button.on { background: rgba(255,255,255,.4); }
#touch.tilt .keysonly, #touch:not(.tilt) .tiltonly { display: none !important; }
.tgroup.left { left: calc(20px + env(safe-area-inset-left)); }
.tgroup.right { right: calc(20px + env(safe-area-inset-right)); }
#touch.tilt .tgroup.left { bottom: 20px; flex-direction: column; align-items: flex-start; }
#touch.tilt .tgroup.right { flex-direction: column; align-items: flex-end; width: auto; }
#touch.tilt button.gas { width: 96px; height: 96px; }
#tiltBar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; pointer-events: auto;
}
.tb-track { position: relative; width: 150px; height: 10px; border-radius: 5px; background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.3); }
.tb-mid { position: absolute; left: 50%; top: -3px; width: 2px; height: 16px; background: rgba(255,255,255,.5); }
#tiltMark { position: absolute; top: -4px; left: 50%; width: 12px; height: 18px; margin-left: -6px; border-radius: 4px; background: #ffd54f; box-shadow: 0 0 6px #ffb300; }
#tiltDbg {
  position: absolute; bottom: 38px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font: 11px monospace; background: rgba(0,0,0,.7); color: #b2ff59; padding: 3px 8px; border-radius: 6px;
}
#touch #tiltCal { width: auto; height: 30px; border-radius: 15px; font-size: 12px; font-weight: 700; padding: 0 12px; }

/* Hochformat-Hinweis (nur Touch-Geräte im Spiel) */
#rotate {
  display: none; position: fixed; inset: 0; z-index: 50; background: rgba(8,14,26,.94);
  flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 30px;
}
#rotate .rot-icon { font-size: 56px; animation: rot 1.6s ease-in-out infinite; }
#rotate p { font-size: 20px; font-weight: 700; margin: 0; }
@keyframes rot { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) {
  body.mobile.ingame #rotate { display: flex; }
}

#mobileHint {
  margin: 0 auto 12px; max-width: 560px; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5;
  background: rgba(255,179,0,.12); border: 1px solid #ffb300; color: #ffe0b2;
}
#mobileHint hr { border: 0; border-top: 1px solid rgba(255,179,0,.4); margin: 8px 0; }
#mobileHint button { margin-top: 6px; background: linear-gradient(#ffca28, #ff8f00); color: #3e2000; font-weight: 800; }

/* Menü: Neige-Einstellungen */
.tiltopts { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.tiltopts .chk { display: flex; gap: 5px; align-items: center; width: auto; text-align: left; opacity: 1; cursor: pointer; }
.tiltopts select { font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 8px; background: rgba(0,0,0,.35); color: #fff; border: 1px solid rgba(255,255,255,.25); }
#tiltState { font-size: 12px; opacity: .75; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(5,10,20,.25), rgba(5,10,20,.7));
  overflow-y: auto; padding: 20px;
}
.panel {
  background: rgba(12, 20, 34, .82); border: 1px solid rgba(255,255,255,.14);
  border-radius: 22px; padding: 26px 32px; width: min(720px, 100%); max-height: calc(100vh - 40px); overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  text-align: center;
}
.panel.narrow { width: min(420px, 100%); }
.title { margin: 0; font-size: clamp(38px, 8vw, 66px); font-style: italic; font-weight: 900; letter-spacing: 2px; line-height: 1; }
.title .t1 {
  background: linear-gradient(180deg, #fff59d, #ffb300 55%, #e65100); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #5d2b00);
}
.title .t2 { display: block; font-size: .62em; letter-spacing: 14px; color: #80deea; text-shadow: 0 3px 0 #004d61, 0 0 22px rgba(128,222,234,.5); }
.subtitle { opacity: .8; margin: 12px 0 18px; }
.row { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.row label { width: 90px; text-align: right; opacity: .8; font-size: 14px; }
#seed {
  font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.35); color: #fff; width: 230px; user-select: text; -webkit-user-select: text;
}
button.icon { padding: 7px 11px; font-size: 18px; }
#colors { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.swatch { padding: 4px 6px; background: rgba(255,255,255,.08); border: 2px solid transparent; box-shadow: none; }
.swatch img { width: 48px; height: 29px; display: block; }
.swatch.sel { border-color: #ffd54f; background: rgba(255,213,79,.15); }
button.big {
  font-size: 22px; font-weight: 900; letter-spacing: 1px; padding: 13px 40px; margin: 14px 0 6px;
  background: linear-gradient(#ffca28, #ff8f00); color: #3e2000; box-shadow: 0 4px 0 #9a4d00, 0 8px 20px rgba(255,143,0,.35);
}
button.secondary { margin: 6px; }
#again { font-size: 19px; padding: 12px 26px; white-space: nowrap; }
.btnrow { display: flex; justify-content: center; }
#best { min-height: 22px; font-size: 14px; color: #ffe082; }
.help { text-align: left; margin-top: 12px; background: rgba(0,0,0,.2); border-radius: 12px; padding: 8px 14px; }
.help summary { cursor: pointer; font-weight: 700; opacity: .85; padding: 4px 0; }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px 14px; font-size: 13px; margin: 8px 0 12px; }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; margin-right: 3px; border-radius: 5px; text-align: center;
  background: #e0e0e0; color: #222; font: 700 11px/18px "Segoe UI", sans-serif; box-shadow: 0 2px 0 #888;
}
#legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px 14px; }
.li { display: flex; gap: 10px; align-items: center; font-size: 12px; }
.li img { width: 28px; height: 28px; object-fit: contain; flex: none; }
.li img.wide { width: 34px; height: 21px; }
.li b { display: block; font-size: 13px; }
.li span { opacity: .75; }
.tips { font-size: 12px; opacity: .75; margin: 12px 0 4px; line-height: 1.5; }
h2 { margin: 0 0 12px; font-size: 40px; font-style: italic; font-weight: 900; color: #ff8a65; text-shadow: 0 3px 0 #5d1a00; }
#pause h2 { color: #80deea; text-shadow: 0 3px 0 #004d61; }
#newbest { font-size: 20px; font-weight: 800; color: #ffd54f; margin-bottom: 10px; animation: pulse .6s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
#stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; text-align: left; margin: 8px 0 10px; }
#stats div { display: flex; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,.08); padding: 3px 0; font-size: 14px; }
#stats div:first-child { grid-column: 1 / -1; font-size: 20px; color: #ffe066; }
#stats span { opacity: .75; }
#overSeed { font-size: 12px; opacity: .6; }

/* ---------- Mehrspieler ---------- */
.mp { margin-top: 14px; padding: 12px 14px 8px; background: rgba(64,196,255,.07); border: 1px solid rgba(64,196,255,.25); border-radius: 14px; }
.mp h3 { margin: 0 0 6px; font-size: 17px; color: #80deea; }
#mpStatus { font-size: 12px; font-weight: 600; margin-left: 8px; }
.st-online { color: #69f0ae; } .st-connecting { color: #ffd54f; } .st-error { color: #ff8a80; } .st-off { color: #9e9e9e; }
#mpName, #mpCode {
  font: inherit; font-size: 15px; padding: 8px 11px; border-radius: 10px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.35); color: #fff; user-select: text; -webkit-user-select: text;
}
#mpName { width: 230px; }
#mpCode { width: 100px; text-transform: uppercase; letter-spacing: 3px; font-weight: 800; text-align: center; }
.mprow .or { opacity: .6; font-size: 13px; }
#mpCreate { background: linear-gradient(#26a69a, #00796b); box-shadow: 0 3px 0 #004d40; }
#mpJoin { background: linear-gradient(#42a5f5, #1565c0); box-shadow: 0 3px 0 #0d3c78; }
#mpHint { min-height: 18px; font-size: 13px; color: #ffe082; }
.mpinfo { font-size: 12px; opacity: .7; margin: 4px 0 6px; line-height: 1.45; }
#mpHiscores h4, #mpOverHiscores h4 { margin: 8px 0 4px; font-size: 13px; color: #ffe082; }
#mpHiscores div, #mpOverHiscores div, #mpRanking div {
  display: flex; gap: 8px; align-items: center; font-size: 13px; padding: 2px 4px; text-align: left;
}
#mpHiscores span, #mpOverHiscores span, #mpRanking span { width: 22px; opacity: .6; }
#mpHiscores b, #mpOverHiscores b, #mpRanking b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#mpHiscores em, #mpOverHiscores em, #mpRanking em { font-style: normal; color: #ffe066; font-weight: 700; }
#mpHiscores small, #mpOverHiscores small, #mpRanking small { opacity: .6; width: 62px; text-align: right; }
#mpRanking { margin: 6px 0 10px; }
#mpRanking div { font-size: 16px; padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,.08); }
#mpRanking div:first-child { font-size: 19px; }
#mpRanking i, #mpList i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(255,255,255,.6); flex: none; }
#mpRanking .me, #mpList .me { background: rgba(255,213,79,.12); border-radius: 6px; }
#mpOverSeed { font-size: 12px; opacity: .6; }
#pauseNote { color: #ffe082; margin: 0 0 6px; }

#mpPanel { width: 190px; padding: 7px 10px; font-size: 12px; pointer-events: auto; }
.mphead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.mphead b { letter-spacing: 2px; color: #80deea; font-size: 14px; }
.mphead button { padding: 1px 7px; font-size: 13px; border-radius: 6px; }
#mpList div { display: flex; gap: 6px; align-items: center; padding: 2px 3px; }
#mpList b { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#mpList em { font-style: normal; color: #ffe066; font-weight: 700; font-variant-numeric: tabular-nums; }
#mpList .dead { opacity: .5; }
#spectate {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%); background: rgba(10,16,28,.8);
  border: 1px solid #ffb74d; color: #ffe0b2; padding: 9px 18px; border-radius: 20px; font-weight: 700; white-space: nowrap;
}

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 22px; background: #0d1b2a; }
#err {
  position: fixed; left: 10px; right: 10px; bottom: 10px; background: rgba(120,0,0,.9); color: #fff; padding: 10px;
  font: 12px monospace; white-space: pre-wrap; max-height: 40vh; overflow: auto; z-index: 99; border-radius: 8px;
}

/* Abstand zu Notch/abgerundeten Ecken */
#hudLeft { left: calc(14px + env(safe-area-inset-left)); }
#hudRight { right: calc(14px + env(safe-area-inset-right)); }

/* Handy quer: wenig Höhe -> kompaktes HUD */
@media (max-height: 500px) {
  #hudLeft { width: 180px; padding: 6px 10px 8px; top: 8px; }
  #scoreLabel { display: none; }
  #score { font-size: 22px; }
  #comboWrap { height: 16px; margin: 0 0 2px; }
  #combo { font-size: 11px; height: 12px; }
  .bar { margin-top: 3px; }
  .track { height: 9px; }
  .effect { margin-top: 2px; font-size: 11px; }
  #hudRight { top: 8px; gap: 4px; }
  #minimap { width: 100px; height: 100px; border-width: 2px; }
  #biome { display: none; }
  #clock { font-size: 11px; padding: 2px 8px; }
  #mpPanel { width: 160px; font-size: 11px; max-height: 120px; overflow: hidden; }
  #speedo { display: none; }
  #toasts { top: 8px; }
  .toast { font-size: 13px; padding: 5px 12px; }
  #touch button { width: 64px; height: 64px; font-size: 22px; }
  #touch.tilt button.gas, #touch button.gas { width: 84px; height: 84px; }
  .tgroup.left { bottom: 16px; }
  .tgroup.right { bottom: 16px; }
  #spectate { bottom: 60px; font-size: 13px; }
}

@media (max-width: 700px) {
  #hudLeft { width: 190px; padding: 8px 10px; }
  #score { font-size: 26px; }
  #minimap { width: 120px; height: 120px; }
  #speedo { display: none; }
  .row label { width: auto; text-align: center; }
  .panel { padding: 18px 16px; }
}
