/* 
  GRAPHITE VELOCITY — Charcoal & Pencil on Eggshell Paper
  Aesthetic: Fine sketchbook, drafting paper, graphite cross-hatching
*/

:root {
  --paper-bg: #f4ede1;
  --paper-grain: #e8ded0;
  --charcoal-black: #181614;
  --charcoal-dark: #2c2825;
  --charcoal-mid: #524d47;
  --graphite-light: #7e786f;
  --faint-pencil: #beb7ab;
  --eraser-smudge: rgba(220, 212, 198, 0.6);
  --pencil-blue-draft: #3a506b;
  --alert-red-chalk: #8c271e;
  --heal-green: #2e6f40;
  --font-family: 'Courier New', Courier, monospace, system-ui;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--paper-bg);
  font-family: var(--font-family);
  color: var(--charcoal-dark);
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--paper-bg);
}

#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Subtle Vignette & Deckle Edge Paper Simulation */
#game-container::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  box-shadow: inset 0 0 80px rgba(70, 60, 50, 0.12),
              inset 0 0 20px rgba(50, 40, 30, 0.08);
}

/* ---------------- HUD OVERLAY ---------------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.hud-left {
  align-items: flex-start;
}

.hud-right {
  align-items: flex-end;
}

/* Draft Box (Pencil Sketch Border) */
.draft-box {
  background: rgba(246, 241, 232, 0.92);
  backdrop-filter: blur(3px);
  border: 1.5px solid var(--charcoal-dark);
  border-radius: 2px;
  padding: 8px 14px;
  min-width: 190px;
  box-shadow: 2px 3px 0px rgba(44, 40, 37, 0.18);
  position: relative;
}

.draft-box::before {
  content: '';
  position: absolute;
  inset: -2px;
  border: 0.5px dashed var(--graphite-light);
  border-radius: 3px;
  pointer-events: none;
  opacity: 0.45;
}

.draft-label {
  font-size: 9.5px;
  letter-spacing: 1.5px;
  font-weight: 700;
  color: var(--charcoal-mid);
  margin-bottom: 3px;
  text-transform: uppercase;
}

/* Speed readout */
.speed-readout, .health-readout {
  font-size: 24px;
  font-weight: bold;
  color: var(--charcoal-black);
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.speed-readout .unit, .health-readout .unit {
  font-size: 11px;
  color: var(--graphite-light);
  font-weight: normal;
}

.speed-bar-container, .health-bar-container {
  position: relative;
  width: 100%;
  height: 9px;
  background: rgba(215, 206, 192, 0.5);
  border: 1px solid var(--charcoal-dark);
  margin-top: 5px;
  border-radius: 1px;
  overflow: hidden;
}

#speedBar {
  height: 100%;
  width: 25%;
  background: repeating-linear-gradient(
    45deg,
    var(--charcoal-dark),
    var(--charcoal-dark) 3px,
    var(--charcoal-mid) 3px,
    var(--charcoal-mid) 6px
  );
  transition: width 0.05s ease-out;
}

#speedBar.overspeed {
  background: repeating-linear-gradient(
    45deg, var(--alert-red-chalk), var(--alert-red-chalk) 3px,
    #b56a1e 3px, #b56a1e 6px
  );
}

#speedMinMarker {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 20%;
  width: 2px;
  background: var(--alert-red-chalk);
  z-index: 2;
  box-shadow: 0 0 2px rgba(140, 39, 30, 0.8);
}

.curve-note {
  font-size: 8px;
  color: var(--graphite-light);
  margin-top: 3px;
  letter-spacing: 0.5px;
}

/* Chassis Integrity / Health Bar */
#healthBar {
  height: 100%;
  width: 100%;
  background: var(--heal-green);
  transition: width 0.1s ease-out, background-color 0.2s;
}

.health-warning {
  font-size: 9px;
  font-weight: bold;
  color: var(--alert-red-chalk);
  margin-top: 4px;
  animation: pulse-sketch 0.6s infinite alternate;
}

.health-warning.hidden {
  display: none;
}

/* Centrifugal G-Meter */
.g-meter-box {
  min-width: 190px;
}

.g-meter-bar-wrapper {
  position: relative;
  width: 100%;
  height: 11px;
  background: rgba(215, 206, 192, 0.5);
  border: 1px solid var(--charcoal-dark);
  margin: 4px 0;
}

.g-center-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--charcoal-mid);
}

#gMeterMarker {
  position: absolute;
  top: -1px;
  left: 50%;
  width: 6px;
  height: 13px;
  background: var(--charcoal-black);
  transform: translateX(-50%);
  transition: left 0.05s ease-out;
}

.g-readout {
  font-size: 12px;
  font-weight: bold;
  text-align: right;
  color: var(--charcoal-dark);
}

/* Distance inline display */
.distance-box {
  min-width: 190px;
}

.metric-inline {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.metric-label {
  font-size: 10px;
  color: var(--charcoal-mid);
}

.metric-sep {
  color: var(--faint-pencil);
}

.drift-metric {
  color: var(--pencil-blue-draft);
}

/* ---------------- PROMINENT RALLY ROADBOOK MINIMAP ---------------- */
.minimap-box {
  padding: 6px;
  background: rgba(246, 241, 232, 0.95);
  min-width: 272px;
  box-shadow: 3px 4px 0px rgba(44, 40, 37, 0.25);
}

#minimapCanvas {
  display: block;
  width: 260px;
  height: 380px;
  border: 1.5px solid var(--charcoal-dark);
  background: #f4ede1;
}

.map-legend {
  display: flex;
  justify-content: space-around;
  margin-top: 5px;
  font-size: 8.5px;
  font-weight: bold;
  color: var(--charcoal-dark);
}

.map-legend-sub {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px dashed var(--graphite-light);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 3px;
}

.leg-hairpin {
  color: var(--alert-red-chalk);
  font-size: 10px;
}

.leg-medium {
  color: #b56a1e;
  font-size: 10px;
}

.leg-fast {
  color: var(--charcoal-dark);
  font-size: 10px;
}

.leg-hazard {
  color: var(--alert-red-chalk);
  font-weight: bold;
}

.leg-repair {
  color: var(--heal-green);
  font-weight: bold;
}

/* ---------------- RALLY PACENOTES (VISUAL CO-DRIVER) ---------------- */
.hud-center {
  position: fixed;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  flex: 1;
}

.pacenote-card {
  background: rgba(246, 241, 232, 0.96);
  border: 2px solid var(--charcoal-black);
  border-radius: 3px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 3px 4px 0px rgba(44, 40, 37, 0.28);
  min-width: 0;
  width: 100%;
}

#heightProfile {
  display: block;
  width: 100%;
  height: 52px;
}

.height-label {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-top: 7px;
  color: #806b4f;
  font-size: 8px;
  font-weight: bold;
}

.road-status {
  margin-top: 6px;
  font-size: 9px;
  font-weight: bold;
  color: #536d79;
  letter-spacing: 0.3px;
}

.terrain-status {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px dashed rgba(100, 85, 65, 0.35);
  color: #806b4f;
  font-size: 9px;
  font-weight: bold;
  letter-spacing: 0.4px;
}

.pace-badge {
  background: var(--charcoal-black);
  color: #ffffff;
  padding: 6px 10px;
  border-radius: 3px;
  font-weight: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  box-shadow: 1px 2px 0 rgba(0,0,0,0.25);
  transition: background-color 0.2s;
}

#paceIcon {
  font-size: 20px;
  line-height: 1;
}

#paceGrade {
  font-size: 11px;
  letter-spacing: 1px;
}

.pace-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.pace-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--charcoal-black);
}

.pace-dist-label {
  font-size: 15px;
  font-weight: 900;
  color: var(--alert-red-chalk);
}

.pace-progress-bar {
  width: 100%;
  height: 5px;
  background: rgba(200, 190, 175, 0.5);
  border: 1px solid var(--charcoal-dark);
  margin: 4px 0;
  border-radius: 1px;
  overflow: hidden;
}

#paceProgressFill {
  height: 100%;
  width: 60%;
  background: var(--charcoal-dark);
  transition: width 0.08s linear;
}

.pace-next-hint {
  font-size: 9px;
  font-weight: bold;
  color: var(--charcoal-mid);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.toast-notification {
  position: absolute;
  bottom: calc(100% + 10px);
  width: 100%;
  text-align: center;
  background: rgba(246, 241, 232, 0.95);
  border: 2px solid var(--charcoal-black);
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 2px 3px 0px rgba(0, 0, 0, 0.2);
  transition: opacity 0.3s, transform 0.3s;
}

.toast-notification.hidden {
  opacity: 0;
  transform: translateY(-15px);
}

.alert-icon {
  font-size: 16px;
}

/* Buttons in HUD */
.draft-buttons {
  display: flex;
  gap: 8px;
}

.pencil-btn {
  background: var(--paper-bg);
  border: 1.5px solid var(--charcoal-dark);
  color: var(--charcoal-dark);
  padding: 6px 12px;
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  cursor: pointer;
  box-shadow: 2px 2px 0px rgba(44, 40, 37, 0.2);
  transition: all 0.1s;
}

.pencil-btn:hover {
  background: #ede3d3;
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0px rgba(44, 40, 37, 0.3);
}

.pencil-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0px rgba(44, 40, 37, 0.3);
}

/* Controls Banner (Bottom) */
#controlsBanner {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(246, 241, 232, 0.92);
  border: 1px solid var(--charcoal-mid);
  padding: 6px 18px;
  display: flex;
  gap: 18px;
  font-size: 10.5px;
  color: var(--charcoal-dark);
  box-shadow: 1px 2px 0px rgba(0, 0, 0, 0.12);
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
}

.key {
  display: inline-block;
  background: #fbf7ee;
  border: 1px solid var(--charcoal-mid);
  padding: 1px 5px;
  border-radius: 2px;
  font-weight: bold;
  font-size: 9.5px;
  box-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

/* Modal Overlay */
.overlay-modal {
  position: absolute;
  inset: 0;
  background: rgba(235, 226, 212, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  transition: opacity 0.3s;
}

.overlay-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.sketch-card {
  background: var(--paper-bg);
  border: 2.5px solid var(--charcoal-black);
  padding: 30px 34px;
  max-width: 580px;
  width: 90%;
  box-shadow: 6px 8px 0px rgba(35, 30, 25, 0.3);
  position: relative;
  text-align: center;
}

.sketch-card::before {
  content: '';
  position: absolute;
  inset: -6px;
  border: 1px dashed var(--graphite-light);
  pointer-events: none;
}

.danger-card {
  border-color: var(--alert-red-chalk);
}

.danger-card::before {
  border-color: var(--alert-red-chalk);
}

.sketch-title {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--charcoal-black);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.text-danger {
  color: var(--alert-red-chalk);
}

.sketch-subtitle {
  font-size: 13px;
  font-style: italic;
  color: var(--charcoal-mid);
  margin-bottom: 22px;
}

.sketch-rules {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 11px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--charcoal-dark);
  margin-bottom: 26px;
  background: rgba(235, 226, 212, 0.5);
  padding: 16px 18px;
  border-left: 3px solid var(--charcoal-black);
}

.rule-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.bullet {
  color: var(--alert-red-chalk);
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-box {
  background: rgba(235, 226, 212, 0.5);
  border: 1px solid var(--charcoal-mid);
  padding: 12px;
}

.stat-label {
  font-size: 9.5px;
  font-weight: bold;
  letter-spacing: 1px;
  color: var(--charcoal-mid);
  margin-bottom: 4px;
}

.stat-num {
  font-size: 22px;
  font-weight: bold;
  color: var(--charcoal-black);
}

.big-btn {
  font-size: 14px;
  padding: 12px 26px;
  letter-spacing: 2px;
  border-width: 2px;
}

/* Touch Controls */
.touch-controls {
  display: none;
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 100%;
  padding: 0 20px;
  justify-content: space-between;
  pointer-events: none;
  z-index: 50;
}

@media (pointer: coarse) {
  .hud-center {
    bottom: 92px;
  }
  .touch-controls {
    display: flex;
  }
  #controlsBanner {
    display: none;
  }
}

.touch-btn {
  pointer-events: auto;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: rgba(244, 237, 225, 0.85);
  border: 2px solid var(--charcoal-dark);
  font-family: var(--font-family);
  font-size: 17px;
  font-weight: bold;
  color: var(--charcoal-black);
  box-shadow: 2px 3px 0 rgba(0,0,0,0.2);
  touch-action: manipulation;
}

.touch-steer-zone, .touch-pedal-zone {
  display: flex;
  gap: 12px;
}

.touch-btn:active {
  background: #e2d7c5;
  transform: scale(0.95);
}

.accel-btn {
  background: rgba(230, 240, 230, 0.85);
}

.decel-btn {
  background: rgba(245, 230, 230, 0.85);
}
