:root {
  --bg: #f8f8f6;
  --surface: #ffffff;
  --border: #e8e8e4;
  --text: #1a1a1a;
  --text-sub: #666660;
  --accent: #2d6a4f;
  --up: #1a7f4b;
  --down: #c0392b;
  --new-badge: #e67e22;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.07);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Hero */
.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #1b4332 100%);
  color: #fff;
  padding: 56px 20px;
  text-align: center;
}

.hero h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 800;
  margin-bottom: 8px;
}

.hero-sub {
  font-size: 1.05rem;
  opacity: 0.85;
  margin-bottom: 12px;
}

.last-updated {
  font-size: 0.85rem;
  opacity: 0.6;
}

/* Intro */
.intro-section {
  margin-top: 32px;
  margin-bottom: 8px;
}

.intro-section h2 {
  font-size: 1.15rem;
  margin-bottom: 10px;
}

.intro-section p {
  color: var(--text-sub);
  font-size: 0.9rem;
  line-height: 1.6;
}

.intro-section p + p {
  margin-top: 16px;
}

.intro-more {
  position: relative;
  max-height: 30px;
  overflow: hidden;
  transition: max-height 0.35s ease-in-out;
  margin-top: 16px;
}

.intro-more > p:first-child {
  margin-top: 0;
}

.intro-more::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--bg));
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.intro-expanded .intro-more::after {
  opacity: 0;
}

.intro-toggle {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

.intro-toggle:hover {
  text-decoration: underline;
}

/* Highlights */
.highlights {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 32px;
  margin-bottom: 8px;
}

.highlight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
}

.highlight-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hl-icon {
  font-size: 0.7rem;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}

.hl-icon--up { background: #e6f4ed; color: var(--up); }
.hl-icon--down { background: #fde8e8; color: var(--down); }
.hl-icon--climb { background: #e8edf5; color: #3b5998; }

.highlight-list {
  list-style: none;
}

.highlight-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  min-height: 38px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
}

.highlight-list li:last-child {
  border-bottom: none;
}

.hl-medal {
  font-size: 1rem;
  margin-right: 8px;
  flex-shrink: 0;
}

.hl-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-sub);
  margin-right: 8px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.hl-name {
  font-weight: 600;
  font-size: 0.82rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hl-detail {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  margin-left: 8px;
}

.hl-detail--up { color: var(--up); }
.hl-detail--down { color: var(--down); }
.hl-detail--climb { color: #3b5998; }

/* Comparison toggle */
.comparison-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 4px;
  font-size: 0.9rem;
}

.comparison-bar label {
  color: var(--text-sub);
  font-weight: 500;
  white-space: nowrap;
}

.toggle-group {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 40px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.toggle-btn {
  padding: 8px 20px;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.toggle-btn:hover {
  color: var(--text);
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.toggle-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Table */
.table-wrap {
  margin: 24px 0 40px;
}

.hidden-row {
  display: none;
}

.table-fade {
  position: relative;
}

.table-fade::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(transparent, var(--bg));
  pointer-events: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.show-all-btn {
  display: block;
  margin: 16px auto 0;
  padding: 10px 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 40px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}

.show-all-btn:hover {
  background: #245a42;
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.ranking-table thead th {
  background: #f0efe9;
  text-align: left;
  padding: 12px 16px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-sub);
  font-weight: 600;
}

.ranking-table thead th.col-rank {
  text-align: center;
}

.ranking-table td {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.95rem;
}

.ranking-table tbody tr:hover td {
  background: #fafaf8;
}

.col-rank {
  width: 50px;
  font-weight: 700;
  color: var(--text-sub);
  text-align: center;
}

.name-row {
  display: flex;
  align-items: center;
  min-width: 0;
}

.col-name a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.col-name a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.col-name .domain {
  display: block;
  font-size: 0.78rem;
  color: var(--text-sub);
  font-weight: 400;
}

.table-badge {
  flex-shrink: 0;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 40px;
  white-space: nowrap;
}

.table-badge--winner { background: #e6f4ed; color: var(--up); }
.table-badge--loser { background: #fde8e8; color: var(--down); }
.table-badge--climber { background: #e8edf5; color: #3b5998; }

.col-traffic {
  width: 160px;
  color: var(--text-sub);
  font-size: 0.88rem;
  white-space: nowrap;
}

.col-change {
  width: 90px;
  text-align: right;
}

.change {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

.change--up { color: var(--up); }
.change--down { color: var(--down); }
.change--same { color: var(--text-sub); }
.change--new { color: var(--new-badge); font-weight: 500; }

.traffic-sub {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 1px;
  white-space: nowrap;
}
.traffic-sub--up { color: var(--up); }
.traffic-sub--down { color: var(--down); }

.loading {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-sub);
}

/* Signup */
.signup {
  margin-bottom: 56px;
}

.signup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 500px;
  margin: 0 auto;
  text-align: center;
  box-shadow: var(--shadow);
}

.signup-card h2 {
  font-size: 1.2rem;
  margin-bottom: 6px;
}

.signup-card > p {
  color: var(--text-sub);
  margin-bottom: 14px;
  font-size: 0.92rem;
}

.signup-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.signup-form input {
  flex: 1 1 40%;
  min-width: 0;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 40px;
  font-size: 0.95rem;
  outline: none;
}

.signup-form .btn {
  width: 100%;
}

.signup-form input:focus {
  border-color: var(--accent);
}

.btn {
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 40px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: #245a42;
}

.feedback {
  font-size: 0.88rem;
  margin-top: 8px;
}

.feedback:empty {
  display: none;
}

.feedback--ok { color: var(--up); }
.feedback--err { color: var(--down); }

.signup-note {
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-top: 14px;
  opacity: 0.7;
}

/* Info sections */
.info-section {
  margin-bottom: 32px;
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.info-card h2 {
  font-size: 1.15rem;
  margin-bottom: 12px;
}

.info-card h3 {
  font-size: 0.92rem;
  margin-top: 16px;
  margin-bottom: 6px;
}

.info-card p {
  color: var(--text-sub);
  font-size: 0.9rem;
  line-height: 1.6;
}

.info-card p + p {
  margin-top: 8px;
}

.info-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.info-link:hover {
  text-decoration: underline;
}

/* Footer */
.footer {
  text-align: center;
  padding: 28px 20px;
  font-size: 0.82rem;
  color: var(--text-sub);
  border-top: 1px solid var(--border);
}

.footer a {
  color: var(--text-sub);
  text-decoration: none;
  font-weight: 600;
}

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

/* Scroll to top */
.scroll-top {
  position: fixed;
  bottom: calc(25px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s, background 0.3s;
  transform: translate3d(0, 15px, 0);
  z-index: 110;
}

.scroll-top.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate3d(0, 0, 0);
}

.scroll-top:hover {
  background: #245a42;
}

/* Mobile */
/* Confirmation popup */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.confirm-popup {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.confirm-popup h2 {
  font-size: 1.2rem;
  margin-bottom: 10px;
}

.confirm-popup p {
  color: var(--text-sub);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 10px;
}

.confirm-close {
  margin-top: 12px;
}

@media (max-width: 600px) {
  .signup-form { flex-direction: column; }
  .col-traffic { display: none; }
  .ranking-table thead .col-traffic { display: none; }
  .highlights { grid-template-columns: 1fr; }
  .comparison-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .col-rank { width: 36px; padding: 10px 4px; }
  .ranking-table thead th.col-rank { padding: 10px 4px; }
  .scroll-top { width: 40px; height: 40px; font-size: 0.9rem; }
}
