/* ==========================================================================
   Design System & Custom Properties
   ========================================================================== */
:root {
  --bg-color: #f0f4f8; /* 明るく優しい水色グレー */
  --card-bg: #ffffff; /* クリーンな白背景 */
  --card-border: #e2e8f0; /* 優しいグレーの枠線 */
  --text-primary: #2d3748; /* 濃い目のチャコールグレー */
  --text-secondary: #64748b; /* 落ち着いたブルーグレー */
  
  /* Pop Switch Colors (より温かみのある明るいポップカラー) */
  --neon-blue: #00b0ff; /* 元気な青 */
  --neon-red: #ff4081; /* かわいいピンク赤 */
  --neon-green: #4caf50; /* 楽しい緑 */
  --neon-yellow: #ffb300; /* 温かいオレンジイエロー */
  
  --shadow-blue: rgba(0, 176, 255, 0.2);
  --shadow-red: rgba(255, 64, 129, 0.2);
  
  --font-main: 'M PLUS Rounded 1c', sans-serif;
  --font-mono: 'Nunito', 'M PLUS Rounded 1c', sans-serif;
}

/* ==========================================================================
   Global Reset & Base Styles
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
  overflow-x: hidden;
  position: relative;
}

/* Dynamic Ambient Glow Background */
.glow-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, #f0f8ff 0%, #fff9e6 100%); /* 淡いスカイブルーからクリーム色へのグラデーション */
}

.glow-bg::before,
.glow-bg::after {
  content: '';
  position: absolute;
  width: 450px;
  height: 450px;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
}

.glow-bg::before {
  top: -5%;
  left: -5%;
  background-color: rgba(0, 176, 255, 0.4); /* ポップな水色 */
  animation: float-slow 18s infinite alternate;
}

.glow-bg::after {
  bottom: -5%;
  right: -5%;
  background-color: rgba(255, 64, 129, 0.35); /* ポップなピンク */
  animation: float-slow 22s infinite alternate-reverse;
}

@keyframes float-slow {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(50px, 80px) scale(1.2); }
}

/* ==========================================================================
   Layout Containers
   ========================================================================== */
.app-container {
  width: 100%;
  max-width: 1280px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.app-header {
  text-align: center;
  margin-bottom: 0.5rem;
}

.neon-text {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: #ff4081; /* ポップなピンク */
  text-shadow: 
    3px 3px 0px #ffb300, /* オレンジ黄色のズレ影 */
    6px 6px 0px #00b0ff, /* 水色のズレ影 */
    9px 9px 12px rgba(0, 0, 0, 0.08); /* 柔らかいドロップシャドウ */
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

/* ==========================================================================
   Component: Cards (Glassmorphism)
   ========================================================================== */
.card {
  background: var(--card-bg);
  border: 3px solid var(--card-border); /* 太めの枠線でポップに */
  border-radius: 24px; /* より丸く */
  padding: 1.75rem;
  box-shadow: 0 8px 16px rgba(100, 116, 139, 0.08), 0 2px 4px rgba(100, 116, 139, 0.04);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.25s ease, box-shadow 0.25s ease;
}

.card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 16px 28px rgba(100, 116, 139, 0.12), 0 4px 8px rgba(100, 116, 139, 0.06);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px dashed #e2e8f0; /* 点線でかわいいデザインに */
  padding-bottom: 0.75rem;
}

.card-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
}

.icon-toio { color: var(--neon-blue); }
.icon-controller { color: var(--neon-red); }

.full-width {
  grid-column: 1 / -1;
}

/* ==========================================================================
   Interactive Status Panel
   ========================================================================== */
.status-panel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #f1f5f9;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  margin-bottom: 1.25rem;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #ef4444; /* 明るい赤 */
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
  transition: background-color 0.3s, box-shadow 0.3s;
}

.status-indicator.connected {
  background-color: #22c55e; /* 明るい緑 */
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.5);
}

.status-text {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
}

/* ==========================================================================
   Buttons UI
   ========================================================================== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: 16px; /* より丸っこく */
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  color: #fff;
}

.btn-primary {
  background: linear-gradient(135deg, #00b0ff, #0091ea);
  box-shadow: 0 6px 16px rgba(0, 176, 255, 0.3);
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 176, 255, 0.4);
}

.btn-primary:active {
  transform: translateY(-1px);
}

.btn-secondary {
  background: #f1f5f9;
  border: 2px solid #cbd5e1;
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
  transform: translateY(-2px);
}

.btn-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

/* ==========================================================================
   toio Controls Section
   ========================================================================== */
.control-group {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  transition: opacity 0.3s ease;
}

.disabled-until-connected {
  opacity: 0.4;
  pointer-events: none;
}

.control-group h3 {
  font-size: 0.95rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.25rem;
}

.sub-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sub-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* LED Color Customizer */
.led-control-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

#led-picker {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: none;
}

#led-picker::-webkit-color-swatch {
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
}

.color-preset-container {
  display: flex;
  gap: 0.5rem;
}

.color-preset {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

.color-preset:hover {
  transform: scale(1.15);
  border-color: #fff;
}

/* Sound Grid Buttons */
.sound-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

/* ==========================================================================
   Switch Controller Section
   ========================================================================== */
.controller-info {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  padding: 1.25rem;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.info-placeholder {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.6;
}

.controller-details {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.controller-name {
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  background: #f1f5f9;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  border: 2px solid #e2e8f0;
  max-width: 100%;
  word-break: break-all;
  color: var(--text-primary);
}

/* Virtual Analog Stick Visualizer */
.stick-visualizer-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.stick-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.stick-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.analog-area {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: #e2e8f0;
  border: 2px solid #cbd5e1;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.08);
}

.analog-stick {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle, #f8fafc 0%, #cbd5e1 100%);
  border: 2px solid #64748b;
  position: absolute;
  transition: transform 0.05s ease-out;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1), inset 0 1px 2px #fff;
}

.analog-stick::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.4);
}

.axis-values {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #0284c7;
}

/* Virtual Buttons Node */
.buttons-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-template-areas:
    ".    btnX ."
    "btnY .    btnA"
    ".    btnB .";
  gap: 4px;
  background: #e2e8f0;
  padding: 6px;
  border-radius: 50%;
  width: 100px;
  height: 100px;
  align-items: center;
  justify-items: center;
}

#btn-y { grid-area: btnY; }
#btn-x { grid-area: btnX; }
#btn-b { grid-area: btnB; }
#btn-a { grid-area: btnA; }

.btn-node {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #475569;
  font-size: 0.8rem;
  font-weight: 800;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.1s ease;
}

/* Button Pressed Active States */
.btn-node.pressed {
  color: #fff;
  transform: scale(1.15);
}

.btn-node.pressed#btn-a { background-color: #22c55e; box-shadow: 0 0 10px rgba(34, 197, 94, 0.4); border-color: #fff; }
.btn-node.pressed#btn-b { background-color: #ef4444; box-shadow: 0 0 10px rgba(239, 68, 68, 0.4); border-color: #fff; }
.btn-node.pressed#btn-x { background-color: #00b0ff; box-shadow: 0 0 10px rgba(0, 176, 255, 0.4); border-color: #fff; }
.btn-node.pressed#btn-y { background-color: #ffb300; color: #fff; box-shadow: 0 0 10px rgba(255, 179, 0, 0.4); border-color: #fff; }

.hidden {
  display: none !important;
}


/* ==========================================================================
   Footer & Guide Details
   ========================================================================== */
.app-footer {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.guide-toggle {
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.2s;
  color: var(--text-secondary);
}

.guide-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.guide-content {
  background: rgba(20, 22, 37, 0.4);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1.25rem;
  font-size: 0.85rem;
  line-height: 1.6;
}

.guide-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media(min-width: 600px) {
  .guide-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.guide-content h4 {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: #fff;
}

.guide-content ul {
  list-style: none;
}

.guide-content li {
  margin-bottom: 0.25rem;
}

/* ==========================================================================
   Logs System Panel
   ========================================================================== */
.system-logs {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  overflow: hidden;
}

.log-header {
  background: #e2e8f0;
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #cbd5e1;
}

.btn-clear {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
}

.btn-clear:hover {
  color: var(--neon-red);
}

.log-content {
  padding: 0.75rem 1rem;
  height: 120px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.log-line {
  color: var(--text-secondary);
  font-weight: 700;
}

.log-line.system {
  color: #0284c7; /* 青系 */
}

.log-line.error {
  color: #e11d48; /* 赤ピンク系 */
}

.log-line.success {
  color: #16a34a; /* 緑系 */
}

.log-line.controller {
  color: #b45309; /* 茶・オレンジ系 */
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ==========================================================================
   Compact Sensor Panel (Added)
   ========================================================================== */
.toio-sensor-panel {
  margin-top: 1rem;
  background: #f8fafc;
  border-radius: 16px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border: 2px solid #e2e8f0;
}

.sensor-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.sensor-label {
  color: var(--text-secondary);
  font-weight: 700;
}

.sensor-val {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--neon-blue);
}

.sensor-val.status-val {
  font-family: var(--font-main);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ==========================================================================
   Random Drive Mode (Added)
   ========================================================================== */
.random-drive-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.direction-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: rgba(0, 0, 0, 0.3);
  padding: 10px;
  border-radius: 12px;
  width: 140px;
  margin: 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.dir-arrow, .dir-arrow-center {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: #191b28;
  color: var(--text-secondary);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  transition: all 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.dir-arrow-center {
  background: #12141f;
  color: var(--text-secondary);
  font-size: 0.7rem;
}

.dir-empty {
  width: 36px;
  height: 36px;
  visibility: hidden;
}

/* Active State when toio drives in this direction */
.dir-arrow.active {
  color: var(--neon-green);
  background: rgba(57, 255, 20, 0.15);
  border-color: var(--neon-green);
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.3);
  text-shadow: 0 0 8px var(--neon-green);
  transform: scale(1.08);
}

.dir-arrow-center.active {
  color: var(--neon-red);
  background: rgba(255, 0, 85, 0.15);
  border-color: var(--neon-red);
  box-shadow: 0 0 10px rgba(255, 0, 85, 0.3);
  text-shadow: 0 0 8px var(--neon-red);
  transform: scale(1.08);
}

/* ==========================================================================
   Control Shuffle Gimmick (Added)
   ========================================================================== */
.shuffle-control-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.switch-label {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 600;
}

/* Custom Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: .3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-secondary);
  transition: .3s;
}

.slider.round {
  border-radius: 22px;
}

.slider.round:before {
  border-radius: 50%;
}

input:checked + .slider {
  background-color: rgba(0, 195, 227, 0.2);
  border-color: var(--neon-blue);
  box-shadow: 0 0 8px rgba(0, 195, 227, 0.3);
}

input:checked + .slider:before {
  transform: translateX(22px);
  background-color: var(--neon-blue);
  box-shadow: 0 0 5px var(--neon-blue);
}

/* Shuffle Status Panel */
.shuffle-status-panel {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.shuffle-status-panel.normal {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: var(--text-secondary);
}

.shuffle-status-panel.shuffled {
  background: #fffbeb; /* パステル黄色 */
  border-color: #f59e0b; /* オレンジ */
  color: #b45309; /* 濃い茶色(読みやすさのため) */
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.15);
  animation: warning-pulse 1.5s infinite alternate;
}

@keyframes warning-pulse {
  0% {
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.4);
  }
  100% {
    box-shadow: 0 6px 14px rgba(245, 158, 11, 0.25);
    border-color: rgba(245, 158, 11, 0.9);
  }
}

.text-yellow {
  color: #d97706 !important; /* 暗めのひまわり色 */
}

/* ==========================================================================
   Time Attack Section
   ========================================================================== */
#time-attack-section {
  position: relative;
  overflow: hidden;
}

.icon-timer {
  color: var(--neon-yellow);
}

.ta-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 0.5rem 0;
  width: 100%;
}

@media(min-width: 600px) {
  .ta-container {
    flex-direction: row;
    justify-content: space-around;
  }
}

.ta-display {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ta-status-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  transition: color 0.3s;
}

.ta-status-label.ready {
  color: #d97706; /* ひまわりオレンジ */
}

.ta-status-label.countdown {
  color: #e11d48; /* ポップな赤ピンク */
}

.ta-status-label.running {
  color: #16a34a; /* 明るい緑 */
}

.ta-status-label.finished {
  color: #0284c7; /* 深い水色 */
}

.ta-timer-digits {
  font-family: var(--font-mono);
  font-size: 3.5rem;
  font-weight: 900;
  color: #1e293b; /* 濃い目のグレー */
  line-height: 1;
}

.ta-best-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f8fafc;
  padding: 0.75rem 1.5rem;
  border-radius: 18px; /* 丸みを強める */
  border: 2px solid #e2e8f0;
  min-width: 160px;
}

.best-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--neon-yellow);
  letter-spacing: 1.5px;
  margin-bottom: 0.25rem;
}

.best-digits {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--neon-yellow);
  text-shadow: 0 0 8px rgba(255, 230, 0, 0.3);
}

/* カウントダウンオーバーレイ */
.countdown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(11, 12, 19, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.3s ease;
}

.countdown-content {
  text-align: center;
}

#countdown-number {
  font-family: var(--font-mono);
  font-size: 6rem;
  font-weight: 900;
  color: var(--neon-red);
  text-shadow: 0 0 30px rgba(255, 0, 85, 0.6);
  display: inline-block;
  animation: countdown-scale 1s infinite ease-in-out;
}

@keyframes countdown-scale {
  0% { transform: scale(1.5); opacity: 0; }
  20% { transform: scale(1); opacity: 1; }
  80% { transform: scale(0.9); opacity: 1; }
  100% { transform: scale(0.8); opacity: 0; }
}

/* ゴール結果オーバーレイ */
.result-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(240, 244, 248, 0.92); /* 明るい背景 */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.3s ease;
}

.result-content {
  text-align: center;
  padding: 2.25rem;
  background: #ffffff;
  border: 3px solid #cbd5e1;
  border-radius: 24px;
  box-shadow: 0 16px 36px rgba(100, 116, 139, 0.15);
  max-width: 90%;
  animation: result-appear 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes result-appear {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.result-title {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 900;
  color: #ff4081; /* ポップなピンク */
  margin-bottom: 1rem;
}

.result-time {
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 900;
  color: #1e293b;
  margin-bottom: 0.5rem;
}

.result-record-msg {
  font-size: 0.95rem;
  font-weight: 700;
  color: #16a34a;
  min-height: 1.5rem;
}

/* ==========================================================================
   Player Name & Lap Times Styles (Added)
   ========================================================================== */
.player-name-container {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: #f8fafc;
  padding: 0.75rem 1rem;
  border-radius: 18px; /* 丸みを強く */
  border: 2px solid #e2e8f0;
  width: 100%;
  max-width: 250px;
}

.player-name-container label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

#player-name-input {
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: 12px;
  color: #1e293b;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#player-name-input:focus {
  outline: none;
  border-color: #00b0ff;
  box-shadow: 0 0 0 3px rgba(0, 176, 255, 0.2);
}

#ta-best-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.best-player-name {
  font-size: 0.75rem;
  color: var(--text-secondary);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ta-laps-section {
  width: 100%;
  margin-top: 1rem;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  padding: 1rem;
}

.ta-laps-section h3 {
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 2px dashed #cbd5e1;
  padding-bottom: 0.5rem;
}

.laps-container {
  max-height: 120px;
  overflow-y: auto;
}

.laps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.lap-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  border: 2px solid #cbd5e1;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  border-left: 4px solid var(--neon-blue);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.lap-item.lap-warn {
  border-left-color: var(--neon-red);
}

.lap-item .lap-label {
  color: var(--text-secondary);
  font-weight: 700;
}

.lap-item .lap-time {
  color: #1e293b;
  font-weight: 700;
}

.lap-empty {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
  padding: 0.5rem 0;
}

/* ==========================================================================
   Error Messages & Leaderboards (Added)
   ========================================================================== */
.error-msg {
  font-size: 0.7rem;
  color: var(--neon-red);
  text-shadow: 0 0 5px rgba(255, 0, 85, 0.4);
  margin-top: 0.2rem;
}

#player-name-input.input-error {
  border-color: var(--neon-red);
  box-shadow: 0 0 10px rgba(255, 0, 85, 0.4);
}

.ta-ranking-section {
  width: 100%;
  margin-top: 1rem;
  background: rgba(20, 22, 37, 0.25);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1rem;
}

.ta-ranking-section h3 {
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.5rem;
}

.ranking-container {
  max-height: 500px;
  overflow-y: auto;
overflow-x: hidden; 
}

.ranking-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ranking-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #f8fafc;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
  border-left: 5px solid #cbd5e1;
  font-size: 0.85rem;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.ranking-item .rank-info {
  flex-shrink: 0;
}

.ranking-item .rank-time-date {
  margin-left: auto;
  flex-shrink: 0;
}

/* 個別削除ボタンのスタイル */
.btn-delete-row {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-delete-row:hover {
  color: var(--neon-red);
  background: rgba(255, 64, 129, 0.1);
  transform: scale(1.1);
}

.btn-delete-row svg {
  width: 14px;
  height: 14px;
}

.ranking-item:hover {
  transform: translateX(4px);
  background: #f1f5f9;
}

/* 順位別のハイライトデザイン */
.ranking-item.rank-1 {
  border-left-color: #ffb300; /* 金 */
  background: #fffbeb;
}
.ranking-item.rank-1 .rank-num {
  color: #d97706;
  font-weight: 900;
}

.ranking-item.rank-2 {
  border-left-color: #94a3b8; /* 銀 */
  background: #f1f5f9;
}
.ranking-item.rank-2 .rank-num {
  color: #475569;
  font-weight: 800;
}

.ranking-item.rank-3 {
  border-left-color: #b45309; /* 銅 */
  background: #faf5f0;
}
.ranking-item.rank-3 .rank-num {
  color: #b45309;
  font-weight: 800;
}

.ranking-item .rank-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.ranking-item .rank-num {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  min-width: 1.5rem;
}

.ranking-item .rank-name {
  color: var(--text-primary);
  font-weight: 700;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-item .rank-time-date {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
}

.ranking-item .rank-time {
  font-family: var(--font-mono);
  color: #0284c7; /* ポップな濃い水色 */
  font-weight: 700;
}

.ranking-item .rank-date {
  font-size: 0.65rem;
  color: var(--text-dim);
}

.ranking-empty {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
  padding: 1rem 0;
}

/* ==========================================================================
   2-Column Layout & Sidebar Style
   ========================================================================== */
.main-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  align-items: start;
  width: 100%;
}

.sidebar-layout {
  position: sticky;
  top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-content {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.guide-section-block {
  padding-bottom: 1rem;
  border-bottom: 2px dashed #e2e8f0; /* 点線でかわいく */
}

.guide-section-block:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.rule-list {
  margin: 0;
}

.rule-list li {
  margin-bottom: 0.5rem;
}

.rule-list li:last-child {
  margin-bottom: 0;
}

.rule-list strong {
  color: var(--text-primary);
}

@media (max-width: 950px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  .sidebar-layout {
    position: static;
  }
}




