/* ============================================================
 * 大黄鸭 · 沙丘卡丁车 —— UI 样式
 * 全部为内联 UI，无任何外部字体 / 图片依赖
 * ============================================================ */
:root {
  --sand: #f4d49b;
  --sand-light: #fff3d8;
  --ink: #2f2114;
  --panel: rgba(48, 31, 18, 0.80);
  --panel-soft: rgba(48, 31, 18, 0.62);
  --line: rgba(255, 226, 170, 0.22);
  --gold: #ffc844;
  --gold-deep: #e8971f;
  --cyan: #7fd8e8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #e9c79a;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--sand-light);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app { position: relative; width: 100%; height: 100%; }

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- 加速暗角 ---------- */
#speed-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  background: radial-gradient(ellipse at 50% 52%, rgba(255, 220, 150, 0) 35%, rgba(255, 160, 60, 0.28) 78%, rgba(120, 55, 15, 0.55) 100%);
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(12px, 2vw, 24px);
}

.hud-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

.hud-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 11px 18px 12px;
  min-width: 132px;
  box-shadow: 0 8px 28px rgba(70, 40, 10, 0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.hud-card .label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 231, 190, 0.66);
}
.hud-card .value {
  font-size: clamp(26px, 3.4vw, 40px);
  font-weight: 800;
  line-height: 1.12;
  color: var(--gold);
  text-shadow: 0 2px 12px rgba(255, 180, 40, 0.32);
  font-variant-numeric: tabular-nums;
}
.hud-card .value.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; letter-spacing: 0.02em; }
.hud-card .sub { font-size: 12px; color: rgba(255, 236, 205, 0.82); margin-top: 2px; }
.hud-card .sub b { color: var(--sand-light); }
.time-card { text-align: right; }

.hud-buttons { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--sand-light);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.18s, transform 0.18s;
}
.icon-btn:hover { background: rgba(90, 58, 28, 0.85); transform: translateY(-1px); }
.icon-btn.off { opacity: 0.55; }

.hud-bottom { display: flex; justify-content: center; }
.gauge-card {
  width: min(340px, 82vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 16px 10px;
  box-shadow: 0 8px 28px rgba(70, 40, 10, 0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.gauge-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: rgba(255, 231, 190, 0.72);
  margin-bottom: 5px;
}
.gauge-line b { font-size: 15px; color: var(--sand-light); font-variant-numeric: tabular-nums; }
.nitro-line { margin-top: 9px; }
.nitro-line b { color: var(--cyan); }
.bar {
  height: 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.13);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 99px;
  transition: width 0.09s linear;
}
.bar-speed { background: linear-gradient(90deg, #ffd66b, #ff8a3d); }
.bar-nitro { background: linear-gradient(90deg, #7fe6f2, #3a9fd8); }
.hint {
  margin-top: 9px;
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: rgba(255, 231, 190, 0.58);
}

/* ---------- 遮罩 / 面板 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 40%, rgba(60, 34, 12, 0.35), rgba(35, 20, 8, 0.72));
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fade-in 0.35s ease both;
  z-index: 5;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(560px, 94vw);
  background: linear-gradient(160deg, rgba(64, 41, 22, 0.95), rgba(38, 25, 14, 0.95));
  border: 1px solid rgba(255, 213, 150, 0.30);
  border-radius: 24px;
  padding: clamp(22px, 4vw, 38px);
  text-align: center;
  box-shadow: 0 24px 70px rgba(30, 15, 4, 0.5), inset 0 1px 0 rgba(255, 235, 200, 0.12);
}
.panel-sm { width: min(420px, 92vw); }

.badge {
  display: inline-block;
  font-size: 10.5px;
  letter-spacing: 0.2em;
  color: var(--gold);
  border: 1px solid rgba(255, 200, 68, 0.38);
  border-radius: 999px;
  padding: 5px 14px;
  margin-bottom: 16px;
}
.panel h1 {
  margin: 0 0 12px;
  font-size: clamp(27px, 4.6vw, 42px);
  line-height: 1.25;
  letter-spacing: 0.01em;
  color: #fff6e2;
}
.panel h1 em { color: var(--gold); font-style: normal; }
.panel h2 { margin: 0 0 10px; font-size: clamp(24px, 3.6vw, 32px); color: #fff6e2; }
.lead { margin: 0 0 20px; font-size: 14px; line-height: 1.85; color: rgba(255, 236, 205, 0.84); }
.foot { margin: 16px 0 0; font-size: 11px; color: rgba(255, 231, 190, 0.48); }

.keylist {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin: 0 0 24px;
  text-align: left;
}
.keylist > div {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 236, 205, 0.07);
  border: 1px solid rgba(255, 236, 205, 0.10);
  border-radius: 11px;
  padding: 9px 11px;
  font-size: 12px;
  color: rgba(255, 240, 215, 0.88);
}
.keylist span { margin-left: auto; white-space: nowrap; font-size: 11px; color: rgba(255, 236, 205, 0.68); }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(255, 226, 170, 0.16);
  border: 1px solid rgba(255, 226, 170, 0.28);
  border-bottom-width: 2px;
  font: 600 11px ui-monospace, Consolas, monospace;
  color: #fff2d5;
  text-align: center;
}

.primary {
  border: 0;
  border-radius: 999px;
  padding: 13px 38px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #3a2409;
  background: linear-gradient(120deg, #ffd669, #ff9f36);
  box-shadow: 0 8px 26px rgba(255, 165, 45, 0.34);
  cursor: pointer;
  transition: transform 0.16s, box-shadow 0.16s;
}
.primary:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(255, 165, 45, 0.46); }
.primary:active { transform: translateY(0); }
.ghost {
  border: 1px solid rgba(255, 226, 170, 0.35);
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 14px;
  color: var(--sand-light);
  background: transparent;
  cursor: pointer;
  transition: background 0.16s;
}
.ghost:hover { background: rgba(255, 226, 170, 0.12); }
.btn-row { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 4px 0 24px;
}
.result > div {
  background: rgba(255, 236, 205, 0.07);
  border: 1px solid rgba(255, 236, 205, 0.10);
  border-radius: 12px;
  padding: 12px;
}
.result span { display: block; font-size: 11px; color: rgba(255, 236, 205, 0.62); margin-bottom: 4px; }
.result b { font-size: 24px; color: var(--gold); font-variant-numeric: tabular-nums; }

/* ---------- 飘字 ---------- */
#toast-layer {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.toast {
  font-size: 26px;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 3px 14px rgba(120, 60, 0, 0.75);
  animation: pop 0.9s ease-out forwards;
}
.toast-bad { color: #ff9a7a; font-size: 20px; }
@keyframes pop {
  0% { opacity: 0; transform: translateY(12px) scale(0.7); }
  22% { opacity: 1; transform: translateY(0) scale(1.15); }
  100% { opacity: 0; transform: translateY(-56px) scale(1); }
}

/* ---------- 触屏按键 ---------- */
#touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
  pointer-events: none;
  z-index: 4;
}
.touch-left, .touch-right { display: flex; gap: 12px; pointer-events: auto; }
.tbtn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 1px solid rgba(255, 226, 170, 0.35);
  background: rgba(48, 31, 18, 0.55);
  color: #fff3d8;
  font-size: 20px;
  font-weight: 700;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
  cursor: pointer;
}
.tbtn.pressed { background: rgba(255, 180, 60, 0.65); transform: scale(0.94); }
.tbtn-go { background: rgba(232, 145, 31, 0.72); font-size: 16px; width: 76px; height: 76px; }
.tbtn-nitro { background: rgba(58, 159, 216, 0.62); font-size: 17px; }

/* ---------- 启动失败 ---------- */
#boot-error { z-index: 9; }

/* ---------- 窄屏适配 ---------- */
@media (max-width: 620px) {
  .hud-card { min-width: 104px; padding: 9px 12px 10px; border-radius: 12px; }
  .hud-card .value { font-size: 25px; }
  .icon-btn { padding: 6px 9px; font-size: 11px; }
  .keylist { grid-template-columns: 1fr; }
  .gauge-card { width: min(260px, 62vw); padding: 9px 12px 8px; }
  .hint { display: none; }
}

@media (pointer: coarse) {
  .hud-bottom { position: absolute; left: 50%; transform: translateX(-50%); bottom: 112px; }
  .gauge-card { width: min(240px, 58vw); }
}
