/* ==========================================================================
   WAN-DASH 100m — Japanese Sports Day × Arcade Card Hurdle Sprint
   Mobile-First Touch UI & Tactile Arcade Styling
   ========================================================================== */

:root {
  --ink: #1e2433;
  --ink-soft: #4c566e;
  --cream: #fff9ee;
  --paper: #fffdf8;
  --sky-top: #38a8e8;
  --sky-mid: #7bd3ff;
  --sky-horizon: #fff2cc;
  --track: #d95b38;
  --track-dark: #b64324;
  --grass: #34a85a;
  --amber: #ffb72b;
  --amber-dark: #d9870a;
  --coral: #ff5647;
  --coral-dark: #c93326;
  --sky-btn: #3cb4f2;
  --sky-btn-dark: #1d86c4;

  /* Rarities */
  --r-color: #2f8be6;
  --r-bg: linear-gradient(155deg, #f2f9ff 0%, #d4ebff 100%);
  --sr-color: #d9387a;
  --sr-bg: linear-gradient(155deg, #fff5f9 0%, #ffd5e8 55%, #ffe6a8 100%);
  --ssr-color: #c77b00;
  --ssr-bg: linear-gradient(135deg, #fff8d6 0%, #ffd6f5 38%, #c9f2ff 72%, #ffe787 100%);

  --font-jp: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  --font-num: "Fredoka", "M PLUS Rounded 1c", sans-serif;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font-jp);
  color: var(--ink);
  background: radial-gradient(circle at 50% 0%, #58bdf4 0%, #266fb0 60%, #1b385c 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* Mobile phone centered frame on desktop, edge-to-edge on mobile */
.app-shell {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 44%, var(--sky-horizon) 100%);
  box-shadow: 0 0 0 3px rgba(30, 36, 51, 0.25), 0 24px 64px rgba(10, 22, 46, 0.45);
}

@media (max-width: 500px) {
  .app-shell {
    max-width: 100%;
    box-shadow: none;
  }
}

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

.screen--active {
  display: flex;
  animation: screenFadeIn 0.22s ease-out;
}

@keyframes screenFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Decorative Sports-Day Bunting Flags */
.bunting {
  position: absolute;
  top: env(safe-area-inset-top);
  left: -10px;
  right: -10px;
  height: 22px;
  pointer-events: none;
  z-index: 1;
  background-image:
    conic-gradient(from 150deg at 50% 0%, #ff5647 0 60deg, transparent 0),
    conic-gradient(from 150deg at 50% 0%, #ffd23f 0 60deg, transparent 0),
    conic-gradient(from 150deg at 50% 0%, #34c77b 0 60deg, transparent 0),
    conic-gradient(from 150deg at 50% 0%, #ffffff 0 60deg, transparent 0);
  background-size: 96px 20px;
  background-position: 0 0, 24px 0, 48px 0, 72px 0;
  background-repeat: repeat-x;
  opacity: 0.92;
  filter: drop-shadow(0 2px 0 rgba(30, 36, 51, 0.22));
}

/* ==================== HOME SCREEN ==================== */
#screen-home {
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.home-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 24px;
}

.header-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.88);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  box-shadow: 0 3px 0 var(--ink);
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--coral);
  animation: pulseDot 1.4s infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.65; }
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 3px 0 var(--ink);
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.08s ease;
}

.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--ink);
}

.title-block {
  position: relative;
  z-index: 2;
  text-align: center;
  margin-top: 2px;
}

.title-kicker {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 800;
  color: #164972;
  letter-spacing: 0.04em;
}

.game-title {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
}

.title-main {
  font-size: clamp(32px, 9.2vw, 42px);
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
  letter-spacing: -0.02em;
}

.title-accent {
  display: inline-block;
  margin-top: 2px;
  padding: 2px 14px;
  font-size: clamp(24px, 7.2vw, 32px);
  font-weight: 900;
  color: var(--ink);
  background: var(--amber);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  transform: rotate(-1.5deg);
}

/* Home Stage Card */
.home-stage-card {
  position: relative;
  z-index: 2;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 10px 12px 12px;
  box-shadow: 0 6px 0 var(--ink);
}

.stage-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.dog-name-tag {
  font-size: 16px;
  font-weight: 900;
  color: var(--ink);
}

.dog-breed-tag {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 9px;
  background: #eaf5ff;
  border: 2px solid var(--ink);
  border-radius: 999px;
}

.preview-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 360 / 185;
  border-radius: 12px;
  border: 2.5px solid var(--ink);
  background: #8fd8ff;
}

.stage-record-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.record-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 10px;
}

.record-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-soft);
}

.record-value {
  font-family: var(--font-num);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

/* Tactile Arcade Buttons */
.home-actions {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.home-sub-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.home-sub-actions .btn-arcade {
  font-size: 14px;
  padding: 12px 10px;
  white-space: nowrap;
}

.btn-arcade {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  font-family: var(--font-jp);
  font-size: 15px;
  font-weight: 900;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}

.btn-arcade:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--ink);
}

.btn-arcade--xl {
  padding: 15px 18px;
  font-size: 20px;
  border-radius: 18px;
}

.btn-arcade--lg {
  padding: 13px 16px;
  font-size: 17px;
}

.btn-arcade--primary {
  color: #fff;
  background: linear-gradient(180deg, #ff6c57 0%, var(--coral) 100%);
  text-shadow: 0 2px 0 rgba(30, 36, 51, 0.35);
}

.btn-arcade--amber {
  background: linear-gradient(180deg, #ffd35c 0%, var(--amber) 100%);
}

.btn-arcade--sky {
  color: #fff;
  background: linear-gradient(180deg, #5cc7ff 0%, var(--sky-btn) 100%);
  text-shadow: 0 1.5px 0 rgba(30, 36, 51, 0.25);
}

.btn-arcade--x {
  color: #fff;
  background: linear-gradient(180deg, #272c38 0%, #0f1419 100%);
}

.btn-arcade--cream {
  background: var(--cream);
  font-size: 13px;
  padding: 10px 10px;
}

.btn-icon {
  font-size: 1.15em;
  line-height: 1;
}

.home-hint {
  position: relative;
  z-index: 2;
  margin: 0;
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  color: #1f4466;
  background: rgba(255, 255, 255, 0.72);
  padding: 6px 10px;
  border-radius: 10px;
}

/* ==================== CUSTOMIZER SCREEN ==================== */
#screen-customizer {
  background: var(--cream);
}

.sub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--paper);
  border-bottom: 3px solid var(--ink);
  flex-shrink: 0;
}

.sub-title {
  margin: 0;
  font-size: 17px;
  font-weight: 900;
}

.btn-mini {
  padding: 6px 11px;
  font-family: var(--font-jp);
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
}

.btn-mini:active {
  transform: translateY(2px);
  box-shadow: none;
}

.btn-mini--accent {
  background: #ffe17d;
}

.custom-preview-wrap {
  position: relative;
  padding: 10px 14px 8px;
  background: linear-gradient(180deg, #6bc9f8 0%, #cceeff 100%);
  border-bottom: 3px solid var(--ink);
  flex-shrink: 0;
}

.custom-preview-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 380 / 155;
  border-radius: 14px;
  border: 2.5px solid var(--ink);
  background: #8fd8ff;
}

.preview-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.pose-chip {
  padding: 4px 10px;
  font-family: var(--font-jp);
  font-size: 11px;
  font-weight: 800;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
}

.cookie-badge {
  font-size: 11px;
  font-weight: 800;
  color: #1c6b39;
  background: #dcfce7;
  border: 2px solid #1c6b39;
  padding: 2px 9px;
  border-radius: 999px;
}

.custom-tabs {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px 0;
  background: #f3ead8;
  border-bottom: 3px solid var(--ink);
  flex-shrink: 0;
}

.custom-tab {
  padding: 8px 4px;
  font-family: var(--font-jp);
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-soft);
  background: #e5dac4;
  border: 2.5px solid var(--ink);
  border-bottom: none;
  border-radius: 11px 11px 0 0;
  cursor: pointer;
  margin-bottom: -3px;
}

.custom-tab--active {
  color: var(--ink);
  background: var(--cream);
  padding-bottom: 11px;
}

.custom-panel-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 20px;
}

.custom-tab-pane {
  display: none;
}

.custom-tab-pane--active {
  display: block;
}

.field-group {
  margin-bottom: 14px;
}

.field-label {
  font-size: 12px;
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 7px;
  display: block;
}

.text-input {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-jp);
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.text-input:focus {
  border-color: var(--sky-btn-dark);
  box-shadow: 0 0 0 3px rgba(60, 180, 242, 0.25);
}

.breed-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.breed-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 5px;
  font-family: var(--font-jp);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
  text-align: center;
}

.breed-btn--active {
  background: #ffe17d;
  border-width: 2.5px;
  transform: translateY(-1px);
  box-shadow: 0 3px 0 var(--ink);
}

.breed-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--ink);
}

.breed-name {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.15;
  color: var(--ink);
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.option-grid--3 {
  grid-template-columns: repeat(3, 1fr);
}

.opt-btn {
  padding: 9px 8px;
  font-family: var(--font-jp);
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 11px;
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
}

.opt-btn--active {
  background: #ffe17d;
  border-width: 2.5px;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.swatch-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
  position: relative;
}

.swatch-btn--active::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 3px #000, 0 0 2px #000;
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 800;
}

.color-picker-row input[type="color"] {
  width: 34px;
  height: 26px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: none;
  padding: 0;
  cursor: pointer;
}

.custom-footer {
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 3px solid var(--ink);
  flex-shrink: 0;
}

/* ==================== RACE SCREEN ==================== */
.screen--race {
  background: #1e2433;
  touch-action: none;
}

.race-hud {
  flex-shrink: 0;
  background: var(--paper);
  border-bottom: 3px solid var(--ink);
  padding: 8px 12px 7px;
  z-index: 5;
  pointer-events: none;
}

.hud-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud-dog-pill {
  max-width: 115px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 900;
  padding: 3px 10px;
  background: #ffe694;
  border: 2px solid var(--ink);
  border-radius: 999px;
}

.hud-timer-box {
  font-family: var(--font-num);
  font-size: 27px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.hud-unit {
  font-size: 14px;
  margin-left: 1px;
  color: var(--ink-soft);
}

.hud-speed-box {
  font-family: var(--font-num);
  font-size: 15px;
  font-weight: 700;
  padding: 3px 9px;
  background: #e9f5ff;
  border: 2px solid var(--ink);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

.hud-unit-sm {
  font-size: 10px;
  margin-left: 2px;
  color: var(--ink-soft);
}

.progress-wrap {
  margin-top: 6px;
}

.progress-track {
  position: relative;
  height: 12px;
  background: #e7dfd0;
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: visible;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff7b47, #ffb72b);
  border-radius: 999px;
}

.progress-pin {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  font-size: 15px;
  filter: drop-shadow(0 1px 0 #fff);
  transition: none;
}

.progress-finish-flag {
  position: absolute;
  right: -2px;
  top: 50%;
  transform: translateY(-56%);
  font-size: 14px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* Active Effect Status Strip */
.active-effect-bar {
  margin-top: 6px;
  padding: 5px 8px;
  background: #1e2433;
  color: #fff;
  border-radius: 10px;
  transition: opacity 0.15s ease;
}

.active-effect-bar--hidden {
  display: none;
}

.active-effect-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 800;
}

.active-effect-hint {
  margin-left: auto;
  font-size: 10.5px;
  color: #ffe17d;
}

.active-effect-meter {
  height: 5px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  margin-top: 4px;
  overflow: hidden;
}

.active-effect-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ffcf33, #ff5f6d);
}

/* Main Jump Canvas Zone */
.race-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 220px;
  overflow: hidden;
  cursor: pointer;
  touch-action: none;
  outline: none;
}

.race-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.jump-hint-pill {
  position: absolute;
  right: 12px;
  bottom: 10px;
  padding: 5px 11px;
  background: rgba(30, 36, 51, 0.72);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.jump-hint-pill--fade {
  opacity: 0.35;
}

/* Countdown Overlay */
.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(20, 30, 48, 0.32);
  pointer-events: none;
  z-index: 6;
  transition: opacity 0.18s ease;
}

.countdown-overlay--hidden {
  opacity: 0;
  display: none;
}

.countdown-text {
  font-family: var(--font-num);
  font-size: 72px;
  font-weight: 700;
  color: #fff;
  -webkit-text-stroke: 3.5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--ink);
  animation: popBounce 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}

@keyframes popBounce {
  0% { transform: scale(0.45); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.countdown-sub {
  margin-top: 8px;
  padding: 5px 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  color: var(--ink);
}

/* Card Activation Cut-in */
.card-cutin {
  position: absolute;
  left: 0;
  right: 0;
  top: 14%;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 7;
  opacity: 0;
  transform: translateX(-40px) scale(0.92);
}

.card-cutin--show {
  animation: cutinSlide 1.15s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes cutinSlide {
  0% { opacity: 0; transform: translateX(-80px) skewX(-8deg) scale(0.9); }
  14% { opacity: 1; transform: translateX(0) skewX(-5deg) scale(1.03); }
  78% { opacity: 1; transform: translateX(4px) skewX(-5deg) scale(1); }
  100% { opacity: 0; transform: translateX(70px) skewX(-8deg) scale(0.95); }
}

.cutin-ribbon {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  background: var(--ink);
  color: #fff;
  border: 3px solid #fff;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.cutin-ribbon--R { background: linear-gradient(120deg, #1b5ea8, #3291eb); }
.cutin-ribbon--SR { background: linear-gradient(120deg, #b81d62, #ff6a3d); }
.cutin-ribbon--SSR {
  background: linear-gradient(120deg, #ff3b7f, #ffae00, #00c2ff);
  border-color: #fff8a8;
}

.cutin-rarity {
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 700;
  padding: 2px 7px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 6px;
}

.cutin-icon {
  font-size: 28px;
  line-height: 1;
}

.cutin-name {
  font-size: 16px;
  font-weight: 900;
  line-height: 1.15;
}

.cutin-sub {
  font-size: 11px;
  font-weight: 700;
  color: #fff3b0;
}

/* ==================== BOTTOM 3-CARD DOCK ==================== */
.card-dock {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px 10px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #252c3f 0%, #171c29 100%);
  border-top: 3px solid var(--ink);
  z-index: 6;
  touch-action: none;
}

.race-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 126px;
  padding: 7px 6px 8px;
  font-family: var(--font-jp);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 15px;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.08s ease, filter 0.18s ease, opacity 0.18s ease;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.55);
  touch-action: none;
}

.race-card:active:not(:disabled) {
  transform: translateY(4px) scale(0.97);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.55);
}

.race-card--R {
  background: var(--r-bg);
  border-color: #2f8be6;
}

.race-card--SR {
  background: var(--sr-bg);
  border-color: #eb3c85;
}

.race-card--SSR {
  background: var(--ssr-bg);
  border-color: #ffad1f;
  box-shadow: 0 0 14px rgba(255, 196, 46, 0.65), 0 5px 0 rgba(0, 0, 0, 0.55);
}

/* Shimmer sweep for SR & SSR */
.race-card--SR::before,
.race-card--SSR::before {
  content: "";
  position: absolute;
  inset: -40% -80%;
  background: linear-gradient(115deg, transparent 42%, rgba(255, 255, 255, 0.72) 50%, transparent 58%);
  animation: foilSweep 2.6s infinite linear;
  pointer-events: none;
}

.race-card--SSR::before {
  animation-duration: 1.85s;
}

@keyframes foilSweep {
  0% { transform: translateX(-55%); }
  100% { transform: translateX(55%); }
}

.race-card--deal {
  animation: cardDeal 0.36s cubic-bezier(0.22, 1.3, 0.36, 1) backwards;
}

@keyframes cardDeal {
  0% { opacity: 0; transform: translateY(36px) scale(0.84); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.race-card--active {
  transform: translateY(-5px);
  box-shadow: 0 0 0 3px #fff, 0 0 18px #ffd23f;
}

.race-card--used {
  filter: grayscale(0.92) brightness(0.68);
  opacity: 0.55;
  transform: scale(0.95);
  box-shadow: none;
  cursor: default;
}

.race-card--used::before {
  display: none;
}

.race-card--locked {
  opacity: 0.88;
}

.card-top-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1;
}

.rarity-tag {
  font-family: var(--font-num);
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 6px;
  color: #fff;
  letter-spacing: 0.03em;
}

.rarity-tag--R { background: #2679d4; }
.rarity-tag--SR { background: linear-gradient(90deg, #df2d76, #ff7b29); }
.rarity-tag--SSR { background: linear-gradient(90deg, #ff3377, #ff9900, #00a8e8); }

.card-dur-pill {
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-soft);
}

.card-emoji {
  font-size: 32px;
  line-height: 1;
  margin: 2px 0;
  z-index: 1;
  filter: drop-shadow(0 2px 0 rgba(255, 255, 255, 0.8));
}

.card-name {
  font-size: 11px;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-align: center;
  white-space: nowrap;
  z-index: 1;
}

.card-short {
  font-size: 9.5px;
  font-weight: 800;
  color: #414b63;
  text-align: center;
  line-height: 1.15;
  z-index: 1;
}

.card-used-stamp {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-num);
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: rgba(20, 25, 38, 0.35);
  z-index: 3;
  letter-spacing: 0.08em;
}

/* ==================== RESULT SCREEN ==================== */
#screen-result {
  background: linear-gradient(180deg, #4cb9f2 0%, #c6ecff 45%, #fff5dc 100%);
}

.result-scroll {
  position: relative;
  z-index: 2;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 26px 14px calc(22px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-header-banner {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  box-shadow: 0 5px 0 var(--ink);
  text-align: center;
}

.new-record-badge {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 12px;
  background: linear-gradient(90deg, #ff476f, #ffad1f);
  color: #fff;
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 700;
  border: 2px solid var(--ink);
  border-radius: 999px;
}

.new-record-badge--hidden {
  display: none;
}

.result-rank-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.rank-medal {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-num);
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(145deg, #ffcf33, #e67e00);
  border: 3.5px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  flex-shrink: 0;
}

.result-time-col {
  text-align: left;
}

.result-label {
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
}

.result-time {
  font-family: var(--font-num);
  font-size: 38px;
  font-weight: 700;
  line-height: 1.05;
  color: var(--ink);
}

.result-sec {
  font-family: var(--font-jp);
  font-size: 17px;
  font-weight: 900;
  margin-left: 2px;
}

.result-diff {
  font-size: 12px;
  font-weight: 800;
  color: #d9462f;
}

.photo-card-wrap {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 4px 0 var(--ink);
}

.result-photo-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
}

.result-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-card {
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
  box-shadow: 0 3px 0 var(--ink);
}

.stat-k {
  display: block;
  font-size: 10.5px;
  font-weight: 800;
  color: var(--ink-soft);
}

.stat-v {
  display: block;
  margin-top: 2px;
  font-family: var(--font-num);
  font-size: 15px;
  font-weight: 700;
}

.result-cards-summary,
.leaderboard-box {
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 15px;
  padding: 10px 12px;
  box-shadow: 0 3px 0 var(--ink);
}

.summary-title {
  font-size: 12.5px;
  font-weight: 900;
  margin-bottom: 7px;
}

.result-cards-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.result-card-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  font-size: 11.5px;
  font-weight: 800;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 9px;
}

.result-card-chip--unused {
  opacity: 0.52;
  text-decoration: line-through;
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lb-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: var(--cream);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.lb-item--current {
  background: #fff0b3;
  border: 1.5px solid var(--ink);
}

.lb-rank {
  width: 22px;
  font-family: var(--font-num);
  font-weight: 700;
  text-align: center;
}

.lb-dog {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-time {
  font-family: var(--font-num);
  font-weight: 700;
  color: var(--track-dark);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.result-share-row,
.result-nav-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ==================== MODAL (CARD ENCYCLOPEDIA) ==================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 32, 0.58);
}

.modal-sheet {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 480px;
  height: 86dvh;
  background: var(--cream);
  border-top: 3.5px solid var(--ink);
  border-left: 3.5px solid var(--ink);
  border-right: 3.5px solid var(--ink);
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: sheetUp 0.22s ease-out;
}

@keyframes sheetUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--paper);
  border-bottom: 2.5px solid var(--ink);
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
}

.modal-sub {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
}

.dex-filter-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: #f3ead8;
  border-bottom: 2px solid var(--ink);
}

.dex-filter {
  flex: 1;
  padding: 6px 4px;
  font-family: var(--font-jp);
  font-size: 11.5px;
  font-weight: 800;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 9px;
  cursor: pointer;
}

.dex-filter--active {
  background: #ffe17d;
}

.dex-grid {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 12px calc(18px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
}

.dex-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 9px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 3px 0 var(--ink);
}

.dex-card--R { background: var(--r-bg); }
.dex-card--SR { background: var(--sr-bg); }
.dex-card--SSR { background: var(--ssr-bg); }

.dex-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dex-seen {
  font-size: 10px;
  font-weight: 800;
  color: #1f7a3f;
}

.dex-seen--unseen {
  color: #8a93a6;
}

.dex-emoji-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 2px;
}

.dex-emoji {
  font-size: 25px;
}

.dex-name {
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
}

.dex-desc {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 700;
  color: #364057;
  line-height: 1.38;
}

.dex-meta {
  margin-top: auto;
  padding-top: 4px;
  font-family: var(--font-num);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-soft);
}

/* ==================== TOAST ==================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  padding: 9px 16px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  z-index: 60;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

.toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Small height phone tweaks (e.g. iPhone SE 375x667) */
@media (max-height: 690px) {
  .home-header { margin-top: 18px; }
  .title-main { font-size: 30px; }
  .title-accent { font-size: 22px; }
  .preview-canvas { aspect-ratio: 360 / 158; }
  .btn-arcade--xl { padding: 12px 16px; font-size: 18px; }
  .race-card { min-height: 110px; padding: 5px 4px 6px; }
  .card-emoji { font-size: 26px; }
  .custom-preview-canvas { aspect-ratio: 380 / 132; }
}
