/* ============ Mario Cart Web — style ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body, #app {
  width: 100%; height: 100%; overflow: hidden;
  background: #0b1020;
  font-family: "Arial Rounded MT Bold", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}

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

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }

.hud-panel {
  position: absolute;
  background: rgba(10, 16, 38, .55);
  border: 2px solid rgba(255, 255, 255, .28);
  border-radius: 14px;
  padding: 10px 14px;
  color: #fff;
  backdrop-filter: blur(4px);
  text-shadow: 0 2px 4px rgba(0, 0, 0, .6);
}

#hud-topleft { top: 16px; left: 16px; display: flex; align-items: center; gap: 14px; }
.hud-lap { display: flex; flex-direction: column; line-height: 1; }
.hud-label { font-size: 11px; opacity: .8; letter-spacing: 2px; }
#lap-text { font-size: 26px; font-weight: bold; }
.hud-pos { display: flex; align-items: baseline; }
#pos-text { font-size: 44px; font-weight: bold; color: #ffd93b;
  -webkit-text-stroke: 2px #3a2a00; paint-order: stroke fill; line-height: .9; }
.pos-suffix { font-size: 16px; font-weight: bold; color: #ffd93b; -webkit-text-stroke: 1px #3a2a00; }

#hud-topright { top: 16px; right: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px; }
#minimap { display: block; width: 180px; height: 180px; }
#hud-time-row { font-size: 18px; font-weight: bold; font-variant-numeric: tabular-nums; }
#hud-coins { display: flex; align-items: center; gap: 6px; font-size: 18px; font-weight: bold; color: #ffd93b; }
.coin-icon {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6a0, #ffcc00 60%, #d99a00);
  box-shadow: 0 0 6px rgba(255, 204, 0, .8); display: inline-block;
}

#center-msg {
  position: absolute; top: 26%; left: 0; right: 0; text-align: center;
  font-size: 96px; font-weight: bold; color: #fff;
  -webkit-text-stroke: 5px #1a2a6a; paint-order: stroke fill;
  text-shadow: 0 8px 24px rgba(0, 0, 0, .55);
  opacity: 0; transform: scale(.4); transition: opacity .12s, transform .12s;
}
#center-msg.show { opacity: 1; transform: scale(1); }

#hud-bottom {
  position: absolute; bottom: 18px; left: 0; right: 0;
  display: flex; align-items: flex-end; justify-content: space-between; padding: 0 26px;
}
#item-slot {
  width: 96px; height: 96px; border-radius: 50%;
  background: rgba(10, 16, 38, .55); border: 3px solid rgba(255, 255, 255, .35);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
}
#item-slot.rolling { animation: spinItem .35s linear infinite; }
@keyframes spinItem { from { transform: rotate(0) } to { transform: rotate(360deg) } }
#item-slot.active { border-color: #ffd93b; box-shadow: 0 0 18px rgba(255, 217, 59, .8); }

#speed-box {
  min-width: 150px; text-align: right; color: #fff;
  background: rgba(10, 16, 38, .55); border: 2px solid rgba(255, 255, 255, .28);
  border-radius: 14px; padding: 8px 16px;
}
#speed-num { font-size: 44px; font-weight: bold; line-height: 1; font-variant-numeric: tabular-nums; }
#speed-unit { font-size: 12px; opacity: .85; letter-spacing: 2px; }
#speed-box.boosting #speed-num { color: #ff9d3b; text-shadow: 0 0 14px rgba(255, 157, 59, .9); }

#hud-hint {
  position: absolute; bottom: 4px; left: 0; right: 0; text-align: center;
  color: rgba(255, 255, 255, .55); font-size: 11px; letter-spacing: .5px;
}

/* ---------- 覆盖层 / 菜单 ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(28, 52, 120, .88), rgba(6, 10, 26, .96));
  overflow-y: auto; padding: 20px;
}
.overlay.hidden { display: none; }

.game-title { text-align: center; line-height: .95; margin-bottom: 4px; }
.t-super { display: block; font-size: 34px; letter-spacing: 10px; color: #ffe98a;
  -webkit-text-stroke: 2px #6b4a00; paint-order: stroke fill; }
.t-cart { display: block; font-size: 78px; font-weight: bold; letter-spacing: 4px;
  color: #fff; -webkit-text-stroke: 5px #d22; paint-order: stroke fill;
  text-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
.subtitle { color: #bcd0ff; margin-bottom: 16px; letter-spacing: 3px; font-size: 14px; }

.menu-card {
  background: rgba(12, 20, 48, .82);
  border: 2px solid rgba(255, 255, 255, .18);
  border-radius: 22px; padding: 22px 26px; color: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  text-align: center; max-width: 720px; width: 100%;
}
.menu-card.wide { max-width: 780px; }
.menu-card h2 { margin-bottom: 12px; font-size: 30px; color: #ffd93b; }
.menu-card h3 { margin: 14px 0 10px; font-size: 17px; color: #9fd0ff; letter-spacing: 2px; }

.char-grid { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.char-item {
  width: 104px; padding: 10px 6px; border-radius: 14px; cursor: pointer;
  background: rgba(255, 255, 255, .07); border: 2px solid transparent;
  transition: transform .12s, background .12s, border-color .12s;
}
.char-item:hover { transform: translateY(-3px); background: rgba(255, 255, 255, .14); }
.char-item.selected { border-color: #ffd93b; background: rgba(255, 217, 59, .16); }
.char-portrait {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 6px;
  border: 3px solid rgba(255, 255, 255, .5); position: relative; overflow: hidden;
}
.char-portrait .eyes { position: absolute; bottom: 16px; left: 0; right: 0; text-align: center;
  font-size: 0; }
.char-portrait .eyes i {
  display: inline-block; width: 8px; height: 10px; background: #fff; border-radius: 40%;
  margin: 0 3px; vertical-align: bottom; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .35);
}
.char-portrait .cap {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; height: 46%; border-radius: 56px 56px 0 0;
}
.char-name { font-weight: bold; font-size: 14px; }
.char-desc { font-size: 11px; opacity: .75; margin-top: 2px; }

.track-grid { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.track-item {
  width: 210px; border-radius: 14px; overflow: hidden; cursor: pointer;
  border: 2px solid transparent; background: rgba(255, 255, 255, .07);
  transition: transform .12s, border-color .12s;
}
.track-item:hover { transform: translateY(-3px); }
.track-item.selected { border-color: #ffd93b; }
.track-thumb { width: 100%; height: 88px; display: block; }
.track-meta { padding: 8px 10px; text-align: left; }
.track-name { font-weight: bold; font-size: 14px; }
.track-sub { font-size: 11px; opacity: .7; }

.settings-row { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin: 6px 0 16px; }
.settings-row label { font-size: 13px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.settings-row select {
  background: #101a3c; color: #fff; border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 8px; padding: 7px 12px; font-size: 14px; font-family: inherit;
}

.mbtn {
  display: inline-block; margin: 6px 5px 0; padding: 12px 28px;
  font-family: inherit; font-size: 16px; font-weight: bold; cursor: pointer;
  color: #fff; background: linear-gradient(180deg, #ff6b4a, #d32f2f);
  border: none; border-radius: 30px; letter-spacing: 1px;
  box-shadow: 0 6px 0 #8e1b1b, 0 10px 18px rgba(0, 0, 0, .4);
  transition: transform .08s, box-shadow .08s;
}
.mbtn:hover { filter: brightness(1.08); }
.mbtn:active { transform: translateY(4px); box-shadow: 0 2px 0 #8e1b1b; }
.mbtn.big { font-size: 22px; padding: 14px 46px; }
.mbtn.green { background: linear-gradient(180deg, #7ee06a, #2f9e2f); box-shadow: 0 6px 0 #1a6b1a, 0 10px 18px rgba(0, 0, 0, .4); }

.controls-help {
  margin-top: 16px; font-size: 12px; line-height: 1.9; color: rgba(255, 255, 255, .72);
  border-top: 1px solid rgba(255, 255, 255, .15); padding-top: 12px;
}

#result-table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-size: 15px; }
#result-table th { color: #9fd0ff; font-size: 12px; letter-spacing: 1px; padding: 6px; }
#result-table td { padding: 7px 6px; border-top: 1px solid rgba(255, 255, 255, .12); }
#result-table tr.me td { color: #ffd93b; font-weight: bold; }
.pos-badge {
  display: inline-block; width: 26px; height: 26px; line-height: 26px; border-radius: 50%;
  font-weight: bold; font-size: 13px; color: #333;
}
.pos-badge.p1 { background: #ffd93b; } .pos-badge.p2 { background: #dfe6ef; }
.pos-badge.p3 { background: #e2a05a; } .pos-badge.pn { background: rgba(255, 255, 255, .18); color: #fff; }

#loading {
  position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; letter-spacing: 4px; background: #0b1020;
}
#loading.hidden { display: none; }

/* ---------- 触摸控制 ---------- */
#touch-controls { position: absolute; inset: 0; z-index: 15; pointer-events: none; }
.tbtn {
  position: absolute; pointer-events: auto;
  width: 74px; height: 74px; border-radius: 50%;
  background: rgba(255, 255, 255, .16); border: 2px solid rgba(255, 255, 255, .35);
  color: #fff; font-size: 15px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
.tbtn:active, .tbtn.pressed { background: rgba(255, 217, 59, .55); }
#touch-left  { left: 18px; bottom: 96px; }
#touch-right { left: 104px; bottom: 96px; }
#touch-drift { left: 190px; bottom: 96px; width: 64px; height: 64px; }
#touch-accel { right: 22px; bottom: 104px; }
#touch-brake { right: 106px; bottom: 104px; }
#touch-item  { right: 22px; bottom: 190px; width: 64px; height: 64px; }

@media (max-width: 820px) {
  #minimap { width: 120px; height: 120px; }
  #center-msg { font-size: 60px; -webkit-text-stroke-width: 3px; }
  #hud-hint { display: none; }
  .t-cart { font-size: 52px; }
  .t-super { font-size: 24px; }
  .char-item { width: 88px; }
  .track-item { width: 150px; }
}

/* ---------- 载入失败提示 ---------- */
.loading-inner { max-width: 560px; padding: 24px; text-align: center; }
.loading-text { font-size: 20px; letter-spacing: 4px; }
#loading-hint { margin-top: 18px; text-align: left; font-size: 13px; line-height: 1.9;
  letter-spacing: 0; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 14px; padding: 16px 18px; }
#loading-hint.hidden { display: none; }
#loading-hint p { margin: 6px 0; }
.hint-title { font-size: 17px; font-weight: bold; color: #ffb3b3; letter-spacing: 1px; }
.hint-opt { background: rgba(255, 217, 59, .10); border-left: 3px solid #ffd93b;
  border-radius: 6px; padding: 8px 10px; margin: 8px 0; }
#loading-hint code { background: rgba(0, 0, 0, .45); padding: 1px 6px; border-radius: 5px;
  font-size: 12px; color: #9fd0ff; }
