@import url('https://fonts.googleapis.com/css2?family=Zen+Dots&family=Noto+Sans+JP:wght@300;400;700&family=Share+Tech+Mono&display=swap');

:root {
  --bg:        #0d0d0f;
  --bg2:       #13131a;
  --bg3:       #1a1a24;
  --panel:     #16161f;
  --border:    #2a2a3a;
  --border2:   #3a3a50;
  --red:       #e8142a;
  --red-glow:  rgba(232,20,42,0.25);
  --gold:      #c8a84b;
  --gold-dim:  rgba(200,168,75,0.15);
  --white:     #f0ede8;
  --dim:       #5a5a72;
  --dim2:      #3a3a50;
  --green:     #39ff14;
  --green-glow:rgba(57,255,20,0.2);
  --font-display: 'Zen Dots', cursive;
  --font-mono:    'Share Tech Mono', monospace;
  --font-body:    'Noto Sans JP', sans-serif;
}

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

html { height: 100%; }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Noise texture overlay ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

/* ── Scanlines ── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 3px,
    rgba(0,0,0,0.07) 3px, rgba(0,0,0,0.07) 4px
  );
  pointer-events: none;
  z-index: 1;
}

/* ── Page wrapper ── */
#app {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top nav bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,13,15,0.95);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.topbar-logo {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--red);
  text-shadow: 0 0 12px var(--red-glow), 0 0 30px var(--red-glow);
  letter-spacing: 2px;
}
.topbar-logo span {
  color: var(--gold);
  font-size: 10px;
  font-family: var(--font-mono);
  letter-spacing: 3px;
  vertical-align: super;
  margin-left: 4px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.online-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--dim);
  transition: background 0.3s, box-shadow 0.3s;
}
.online-dot.on {
  background: var(--green);
  box-shadow: 0 0 8px var(--green), 0 0 16px rgba(57,255,20,0.4);
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.5} }

.user-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--dim);
}
.user-tag span { color: var(--gold); }

/* ── Bottom nav ── */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(13,13,15,0.97);
  border-top: 1px solid var(--border);
  z-index: 50;
  backdrop-filter: blur(8px);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 0 12px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  transition: color 0.2s;
  position: relative;
}
.nav-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.5; }
.nav-btn.active { color: var(--red); }
.nav-btn.active::after {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 2px;
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
  border-radius: 0 0 2px 2px;
}

/* ── Page content ── */
.page { display: none; flex: 1; padding: 16px 16px 80px; flex-direction: column; gap: 14px; }
.page.active { display: flex; }

/* ── Section header ── */
.section-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 4px;
  color: var(--dim);
  text-transform: uppercase;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Cards ── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border2), transparent);
}
.card.red-accent::before { background: linear-gradient(90deg, transparent, var(--red), transparent); }
.card.gold-accent::before { background: linear-gradient(90deg, transparent, var(--gold), transparent); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border: 1px solid var(--border2);
  border-radius: 3px;
  background: transparent;
  color: var(--white);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn-red {
  border-color: var(--red);
  color: var(--red);
}
.btn-red:hover { background: var(--red-glow); box-shadow: 0 0 20px var(--red-glow); }
.btn-gold {
  border-color: var(--gold);
  color: var(--gold);
}
.btn-gold:hover { background: var(--gold-dim); box-shadow: 0 0 20px var(--gold-dim); }
.btn-green {
  border-color: var(--green);
  color: var(--green);
  font-size: 14px;
  padding: 16px;
}
.btn-green:hover { background: var(--green-glow); box-shadow: 0 0 30px var(--green-glow); }
.btn-solid-red {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-size: 13px;
  padding: 14px;
  box-shadow: 0 0 20px var(--red-glow);
}

/* ── Inputs ── */
.input-group { display: flex; flex-direction: column; gap: 5px; }
.input-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--dim);
  text-transform: uppercase;
}
input, select, textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--white);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
input:focus, select:focus { border-color: var(--red); }
select option { background: var(--bg2); }

/* ── Speedometer ── */
.speedo-wrap {
  position: relative;
  width: 220px;
  height: 140px;
  margin: 0 auto;
}
.speedo-svg { width: 100%; height: 100%; overflow: visible; }
.speedo-num {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: 56px;
  color: var(--white);
  line-height: 1;
  white-space: nowrap;
}
.speedo-unit {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--dim);
  text-align: center;
  margin-top: 2px;
}

/* ── Nearby user cards ── */
.nearby-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}
.nearby-card:active, .nearby-card:hover { border-color: var(--red); background: rgba(232,20,42,0.04); }
.nearby-avatar {
  width: 44px; height: 44px;
  border-radius: 3px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--red);
  flex-shrink: 0;
}
.nearby-info { flex: 1; min-width: 0; }
.nearby-name {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--white);
  margin-bottom: 2px;
}
.nearby-car {
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nearby-dist {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--gold);
  flex-shrink: 0;
}

/* ── Chat ── */
.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 35vh;
}
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.theirs { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
  padding: 8px 12px;
  border-radius: 3px;
  font-size: 13px;
  line-height: 1.4;
}
.chat-msg.mine .chat-bubble {
  background: var(--red);
  color: #fff;
}
.chat-msg.theirs .chat-bubble {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--white);
}
.chat-meta {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--dim);
  margin-top: 2px;
  letter-spacing: 1px;
}
.chat-input-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.chat-input-row input { flex: 1; }
.chat-send {
  padding: 10px 14px;
  background: var(--red);
  border: none;
  border-radius: 3px;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

/* ── Race screen ── */
.race-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
}
.race-screen.active { display: flex; }

.race-status {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 4px;
  color: var(--dim);
  text-transform: uppercase;
  text-align: center;
}

.countdown-num {
  font-family: var(--font-display);
  font-size: 120px;
  line-height: 1;
  color: var(--red);
  text-shadow: 0 0 40px var(--red), 0 0 80px var(--red-glow);
  animation: countPulse 0.8s ease-out;
}
@keyframes countPulse {
  0% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.go-text {
  font-family: var(--font-display);
  font-size: 100px;
  color: var(--green);
  text-shadow: 0 0 40px var(--green), 0 0 80px var(--green-glow);
}

.race-speeds {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}
.race-speed-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px 12px;
  text-align: center;
}
.race-speed-box.me { border-color: var(--red); }
.race-speed-box.them { border-color: var(--gold); }
.race-speed-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--dim);
  margin-bottom: 6px;
}
.race-speed-num {
  font-family: var(--font-display);
  font-size: 44px;
  line-height: 1;
}
.race-speed-box.me .race-speed-num { color: var(--red); }
.race-speed-box.them .race-speed-num { color: var(--gold); }

.race-lead-bar {
  width: 100%;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.race-lead-indicator {
  position: absolute;
  top: 0; bottom: 0;
  width: 40%;
  left: 30%;
  background: var(--dim2);
  border-radius: 3px;
  transition: left 0.4s, background 0.4s, width 0.4s;
}

.winner-banner {
  font-family: var(--font-display);
  font-size: 36px;
  text-align: center;
  line-height: 1.2;
}

/* ── Stats page ── */
.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.stat-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 10px;
  text-align: center;
}
.stat-box-num {
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--white);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-box-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--dim);
  text-transform: uppercase;
}
.stat-box.highlight .stat-box-num { color: var(--red); }

/* ── Race history ── */
.race-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.rhi-left { display: flex; flex-direction: column; gap: 2px; }
.rhi-opponent { font-family: var(--font-mono); font-size: 12px; color: var(--white); }
.rhi-type { font-size: 10px; color: var(--dim); }
.rhi-result {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 1px;
}
.rhi-result.win { color: var(--green); }
.rhi-result.loss { color: var(--red); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 150;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 24px 20px;
  width: 100%;
  max-width: 360px;
  position: relative;
}
.modal::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--red);
  box-shadow: 0 0 12px var(--red);
}
.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--red);
  margin-bottom: 16px;
  letter-spacing: 1px;
}
.modal-car-stat {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.modal-car-stat:last-of-type { border-bottom: none; }
.modal-car-stat span:first-child { color: var(--dim); font-family: var(--font-mono); letter-spacing: 1px; }
.modal-car-stat span:last-child { color: var(--white); font-weight: 700; }
.modal-buttons { display: flex; gap: 10px; margin-top: 18px; }
.modal-buttons .btn { flex: 1; }

/* ── Utility ── */
.flex-row { display: flex; gap: 10px; }
.flex-row > * { flex: 1; }
.text-center { text-align: center; }
.text-gold { color: var(--gold); }
.text-red { color: var(--red); }
.text-dim { color: var(--dim); }
.text-mono { font-family: var(--font-mono); }
.text-display { font-family: var(--font-display); }
.mt4 { margin-top: 4px; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  border: 1px solid;
}
.tag-red { color: var(--red); border-color: var(--red); }
.tag-gold { color: var(--gold); border-color: var(--gold); }
.tag-green { color: var(--green); border-color: var(--green); }
.tag-dim { color: var(--dim); border-color: var(--dim2); }

/* NearLink toggle */
.nearlink-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.toggle-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toggle-name {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--white);
}
.toggle-desc { font-size: 11px; color: var(--dim); }
.toggle-switch {
  width: 48px; height: 26px;
  border-radius: 13px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  position: relative;
  cursor: pointer;
  transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--dim);
  transition: left 0.3s, background 0.3s;
}
.toggle-switch.on {
  background: rgba(232,20,42,0.2);
  border-color: var(--red);
  box-shadow: 0 0 12px var(--red-glow);
}
.toggle-switch.on::after { left: 25px; background: var(--red); }

/* ── Setup screen ── */
#setup-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 20px;
}
.setup-logo {
  font-family: var(--font-display);
  font-size: 48px;
  color: var(--red);
  text-shadow: 0 0 20px var(--red-glow), 0 0 60px var(--red-glow);
  letter-spacing: 4px;
  text-align: center;
}
.setup-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 5px;
  color: var(--dim);
  text-align: center;
  margin-top: -14px;
}
.setup-form {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* Touge badge on setup */
.kanji-badge {
  font-size: 11px;
  color: var(--dim);
  font-family: var(--font-mono);
  letter-spacing: 3px;
  text-align: center;
}
