/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #111118;
  --bg-card: #16161f;
  --bg-elevated: #1c1c28;
  --border: #2a2a3a;
  --border-light: #3a3a4a;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;
  --accent-gold: #d4a020;
  --accent-gold-bright: #ffd700;
  --accent-gold-dim: #8a6a10;
  --accent-red: #ff3b4a;
  --accent-blue: #4a8fff;
  --accent-green: #3adf7a;
  --rank-a: #ffd700;
  --rank-b: #60a0ff;
  --rank-c: #888;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-display: 'Orbitron', sans-serif;
  --font-body: 'Noto Sans JP', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-primary);
  box-shadow: 0 0 80px rgba(0,0,0,0.5);
}

/* ===== HEADER ===== */
#header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #1a1a28 0%, #0a0a14 100%);
  border: 1px solid var(--accent-gold-dim);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.logo-icon svg {
  width: 100%;
  height: 100%;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-main {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(90deg, var(--accent-gold-bright), var(--accent-gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.logo-sub {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 6px;
  height: 6px;
  background: var(--accent-green);
  border-radius: 50%;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--accent-green); }
  50% { opacity: 0.5; box-shadow: 0 0 8px var(--accent-green); }
}

.status-text {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--accent-green);
  letter-spacing: 1px;
}

/* ===== CONTROL PANEL ===== */
#control-panel {
  background: var(--bg-secondary);
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.control-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.input-group {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

#race-date {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}

#race-date:focus {
  border-color: var(--accent-gold);
}

#search-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--accent-red), #cc2233);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  min-height: 42px;
  flex-shrink: 0;
}

#search-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(255, 59, 74, 0.4);
}

#search-btn:active {
  transform: translateY(0);
}

.btn-icon {
  width: 16px;
  height: 16px;
}

/* ===== SEARCH OVERLAY ===== */
#search-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.5s;
}

#search-overlay.hidden {
  display: none;
}

#search-overlay.fade-out {
  opacity: 0;
}

.search-content {
  text-align: center;
  padding: 20px;
  width: 100%;
  max-width: 400px;
}

.search-logo-anim {
  width: 80px;
  height: 80px;
  margin: 0 auto 24px;
  position: relative;
}

.hex-grid {
  width: 100%;
  height: 100%;
  position: relative;
  animation: hex-rotate 4s linear infinite;
}

@keyframes hex-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.hex {
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--accent-gold);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  animation: hex-pulse 1.5s ease-in-out infinite;
}

.hex:nth-child(1) { top: 0; left: 50%; transform: translateX(-50%); animation-delay: 0s; }
.hex:nth-child(2) { top: 18px; right: 8px; animation-delay: 0.15s; }
.hex:nth-child(3) { top: 18px; left: 8px; animation-delay: 0.3s; }
.hex:nth-child(4) { top: 50%; left: 50%; transform: translate(-50%, -50%); animation-delay: 0.45s; background: var(--accent-gold-bright); }
.hex:nth-child(5) { bottom: 18px; right: 8px; animation-delay: 0.6s; }
.hex:nth-child(6) { bottom: 18px; left: 8px; animation-delay: 0.75s; }
.hex:nth-child(7) { bottom: 0; left: 50%; transform: translateX(-50%); animation-delay: 0.9s; }

@keyframes hex-pulse {
  0%, 100% { opacity: 0.3; transform: scale(1) translateX(var(--tx, 0)) translateY(var(--ty, 0)); }
  50% { opacity: 1; transform: scale(1.2) translateX(var(--tx, 0)) translateY(var(--ty, 0)); }
}

.hex:nth-child(1) { --tx: -50%; }
.hex:nth-child(4) { --tx: -50%; --ty: -50%; }
.hex:nth-child(7) { --tx: -50%; }

.search-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--accent-gold-bright), var(--accent-gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.search-subtitle {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent-gold);
  letter-spacing: 6px;
  margin-bottom: 28px;
  animation: blink-text 1s step-end infinite;
}

@keyframes blink-text {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.search-progress {
  width: 100%;
  height: 3px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 24px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-gold), var(--accent-gold-bright));
  border-radius: 2px;
  transition: width 0.1s linear;
}

.search-metrics {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-bottom: 20px;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.metric-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-gold-bright);
}

.search-log {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.8;
  max-height: 120px;
  overflow: hidden;
}

.search-log .log-line {
  opacity: 0;
  animation: fade-in-line 0.3s forwards;
}

@keyframes fade-in-line {
  to { opacity: 1; }
}

.log-line .log-ok { color: var(--accent-green); }
.log-line .log-warn { color: var(--accent-gold); }

/* ===== MAIN RESULTS ===== */
#results {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#results.hidden {
  display: none;
}

/* Race Card */
.race-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px);
  animation: card-in 0.5s ease forwards;
}

.race-card[data-delay="0"]   { animation-delay: 0s; }
.race-card[data-delay="150"] { animation-delay: 0.15s; }
.race-card[data-delay="300"] { animation-delay: 0.3s; }

@keyframes card-in {
  to { opacity: 1; transform: translateY(0); }
}

.race-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.race-badge {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--bg-primary);
  background: var(--accent-gold);
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 1px;
}

.race-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.race-venue {
  font-weight: 700;
  font-size: 13px;
}

.race-name {
  font-size: 12px;
  color: var(--text-secondary);
}

.race-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* Horse Card */
.horse-card {
  padding: 14px;
}

.horse-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.horse-number {
  width: 36px;
  height: 36px;
  background: #888;
  color: #fff;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

/* JRA 枠色 */
.horse-number.waku-1 { background: #ffffff; color: #111; border: 2px solid #ccc; }
.horse-number.waku-2 { background: #1a1a1a; color: #fff; }
.horse-number.waku-3 { background: #e02020; color: #fff; }
.horse-number.waku-4 { background: #1a6dcc; color: #fff; }
.horse-number.waku-5 { background: #e8c820; color: #111; }
.horse-number.waku-6 { background: #18a050; color: #fff; }
.horse-number.waku-7 { background: #e87020; color: #fff; }
.horse-number.waku-8 { background: #e868a8; color: #fff; }

.horse-name {
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
}

.horse-rating {
  display: flex;
  gap: 2px;
}

.star {
  width: 18px;
  height: 18px;
  display: inline-block;
  background: var(--border);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.star.active {
  background: var(--accent-gold-bright);
}

.horse-body {
  display: flex;
  gap: 12px;
}

.radar-wrap {
  width: 180px;
  height: 180px;
  flex-shrink: 0;
  overflow: visible;
}

.radar-chart {
  width: 100%;
  height: 100%;
}

.picks-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.picks-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 6px;
  padding-left: 2px;
}

.picks-scroll {
  flex: 1;
  max-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 4px;
}

/* Custom scrollbar */
.picks-scroll::-webkit-scrollbar {
  width: 4px;
}

.picks-scroll::-webkit-scrollbar-track {
  background: var(--bg-primary);
  border-radius: 2px;
}

.picks-scroll::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 2px;
}

.picks-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  font-size: 12px;
  transition: background 0.15s;
}

.pick-row:hover {
  background: var(--bg-elevated);
}

.pick-type {
  font-size: 10px;
  color: var(--text-muted);
  width: 42px;
  flex-shrink: 0;
}

.pick-nums {
  flex: 1;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.pick-rank {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  flex-shrink: 0;
}

.rank-a {
  background: rgba(255, 215, 0, 0.15);
  color: var(--rank-a);
  border: 1px solid rgba(255, 215, 0, 0.3);
}

.rank-b {
  background: rgba(96, 160, 255, 0.1);
  color: var(--rank-b);
  border: 1px solid rgba(96, 160, 255, 0.2);
}

.rank-c {
  background: rgba(136, 136, 136, 0.1);
  color: var(--rank-c);
  border: 1px solid rgba(136, 136, 136, 0.2);
}

/* ===== HEADER NAV ===== */
.header-nav {
  display: flex;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.header-nav a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s, background 0.2s;
  position: relative;
}

.header-nav a:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.02);
}

.header-nav a.active {
  color: var(--accent-gold);
}

.header-nav a.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--accent-gold);
  border-radius: 1px;
}

.header-nav svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* ===== FOOTER NAV ===== */
#footer-nav {
  position: sticky;
  bottom: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.footer-nav-inner {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
}

.footer-nav-inner a {
  text-decoration: none;
  color: var(--text-muted);
  transition: color 0.15s;
  letter-spacing: 0.5px;
}

.footer-nav-inner a:hover {
  color: var(--text-secondary);
}

.footer-nav-inner a.active {
  color: var(--accent-gold);
}

.footer-nav-inner .foot-sep {
  color: var(--border-light);
  user-select: none;
}

/* ===== PAGE CONTENT (shared) ===== */
.page-content {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page-title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 2px;
  text-transform: uppercase;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ===== NEWS PAGE ===== */
.news-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.2s;
}

.news-item:hover {
  border-color: var(--border-light);
}

.news-item-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
}

.news-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.news-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

.news-tag.important {
  background: rgba(255, 59, 74, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(255, 59, 74, 0.25);
}

.news-tag.update {
  background: rgba(74, 143, 255, 0.1);
  color: var(--accent-blue);
  border: 1px solid rgba(74, 143, 255, 0.2);
}

.news-tag.info {
  background: rgba(136, 136, 136, 0.1);
  color: var(--text-secondary);
  border: 1px solid rgba(136, 136, 136, 0.2);
}

.news-title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.news-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s;
}

.news-item.open .news-chevron {
  transform: rotate(90deg);
}

.news-detail {
  display: none;
  padding: 0 14px 14px;
  font-size: 12px;
  line-height: 1.8;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  margin: 0 14px;
  padding-top: 12px;
}

.news-item.open .news-detail {
  display: block;
}

/* ===== MY PAGE ===== */
.mypage-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.mypage-section-title {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 12px 14px 8px;
}

.mypage-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

.mypage-row-icon {
  width: 32px;
  height: 32px;
  background: var(--bg-elevated);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mypage-row-icon svg {
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
}

.mypage-row-content {
  flex: 1;
  min-width: 0;
}

.mypage-row-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.mypage-row-value {
  font-size: 13px;
  font-weight: 500;
}

.mypage-link {
  display: flex;
  align-items: center;
  padding: 14px;
  border-top: 1px solid var(--border);
  text-decoration: none;
  color: var(--text-primary);
  gap: 12px;
  transition: background 0.15s;
}

.mypage-link:hover {
  background: var(--bg-elevated);
}

.mypage-link-text {
  flex: 1;
  font-size: 13px;
}

.mypage-link-arrow {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.mypage-link.danger {
  color: var(--accent-red);
}

.mypage-link.danger .mypage-row-icon svg {
  color: var(--accent-red);
}

/* ===== FOOTER ===== */
#footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer-text {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.footer-version {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 520px) {
  #app {
    max-width: 100%;
    box-shadow: none;
  }
}

@media (max-width: 400px) {
  .horse-body {
    flex-direction: column;
    align-items: center;
  }

  .radar-wrap {
    width: 200px;
    height: 200px;
  }

  .picks-area {
    width: 100%;
  }

  .picks-scroll {
    max-height: 150px;
  }

  .search-metrics {
    gap: 16px;
  }

  .logo-main {
    font-size: 13px;
  }

  .control-row {
    flex-direction: column;
    gap: 8px;
  }

  .date-history {
    justify-content: center;
  }

  .header-nav a {
    font-size: 11px;
    padding: 8px 6px;
  }

  .mypage-row-value {
    font-size: 13px;
  }

  .race-header {
    flex-wrap: wrap;
    gap: 4px;
  }

  .pick-row {
    font-size: 12px;
  }
}
