:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-soft: #f0f2f3;
  --text: #202427;
  --muted: #727a80;
  --border: #dfe3e6;
  --accent: #0f775e;
  --accent-dark: #095744;
  --route: #e74c3c;
  --shadow: 0 8px 30px rgba(20, 28, 34, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", Meiryo, sans-serif;
}

body {
  padding: 24px 14px 40px;
}

button,
.file-button {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.route-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(22px, 2.4vw, 32px);
  line-height: 1.15;
}

h2 {
  margin-bottom: 4px;
  font-size: 21px;
}

h2 small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.file-button,
.toolbar button,
.subtle-btn {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  transition: background 0.15s ease, transform 0.15s ease;
}

.file-button:hover,
.toolbar button:hover,
.subtle-btn:hover {
  background: var(--surface-soft);
}

.file-button:active,
.toolbar button:active,
.subtle-btn:active {
  transform: translateY(1px);
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  min-width: 0;
  padding: 11px 13px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.stat-label {
  display: block;
  min-height: 30px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.stat-label small {
  display: block;
  font-size: 10px;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(20px, 2.5vw, 29px);
  line-height: 1;
  letter-spacing: -0.025em;
}

.stat-card strong span {
  margin-left: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.map-panel,
.profile-panel,
.waypoint-panel,
.drop-zone {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.map-panel {
  overflow: hidden;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.toolbar button {
  min-height: 38px;
  padding: 0 14px;
}

#map {
  width: 100%;
  height: min(58vh, 650px);
  min-height: 390px;
  background: #dbe2e6;
}

.map-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.map-footer a[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.45;
}

.status-text {
  color: var(--muted);
}

.profile-panel,
.waypoint-panel {
  margin-top: 14px;
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}

.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.subtle-btn {
  padding: 7px 12px;
}

.profile-wrap {
  position: relative;
  width: 100%;
  height: 260px;
  margin-top: 15px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background:
    linear-gradient(to right, rgba(115,125,132,0.08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(115,125,132,0.08) 1px, transparent 1px);
  background-size: 48px 48px;
}

#profileCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.profile-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 130px;
  padding: 7px 9px;
  border-radius: 7px;
  background: rgba(25, 28, 30, 0.9);
  color: white;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  transform: translate(10px, -100%);
}

.gradient-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.gradient-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend {
  width: 24px;
  height: 4px;
  border-radius: 99px;
}

.legend.downhill { background: #5797d1; }
.legend.flat { background: #6dbe76; }
.legend.mild { background: #e1c34c; }
.legend.medium { background: #e28a44; }
.legend.steep { background: #cf4b40; }

.empty-message {
  margin: 14px 0 0;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.waypoint-list {
  display: grid;
  gap: 8px;
}

.waypoint-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: pointer;
}

.waypoint-item:hover {
  background: #e7ebed;
}

.waypoint-item strong {
  font-size: 14px;
}

.waypoint-item small {
  color: var(--muted);
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 26px 16px;
  border-style: dashed;
  color: var(--muted);
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.drop-zone strong {
  color: var(--text);
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: #eaf4f1;
}

footer {
  padding: 16px 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.start-marker,
.goal-marker,
.position-marker,
.hover-marker {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 3px solid white;
  border-radius: 50%;
  color: white;
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 2px 9px rgba(0,0,0,0.3);
}

.start-marker { background: #1a9b63; }
.goal-marker { background: #d84f43; }
.position-marker { background: #2476d2; }
.hover-marker {
  width: 18px;
  height: 18px;
  border-width: 2px;
  background: #222;
}

@media (max-width: 760px) {
  body {
    padding: 12px 8px 28px;
  }

  .route-header {
    align-items: stretch;
  }

  .route-header {
    flex-direction: column;
  }

  .file-button {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #map {
    min-height: 420px;
    height: 58vh;
  }

  .map-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-wrap {
    height: 220px;
  }
}

@media (max-width: 420px) {
  .stat-label {
    min-height: 45px;
  }

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

  .toolbar button {
    padding: 0 7px;
    font-size: 12px;
  }
}


.header-actions { display: flex; gap: 8px; }
.primary-button { min-height: 42px; padding: 0 18px; border: 1px solid var(--accent); border-radius: 9px; background: var(--accent); color: #fff; font-weight: 700; }
.share-panel { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; margin-bottom: 10px; padding: 9px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.share-panel input { width: 100%; min-width: 0; padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; background: #fafafa; }
.share-panel button { padding: 7px 11px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); font-weight: 700; }
@media (max-width: 760px) {
  .header-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .share-panel { grid-template-columns: 1fr auto; }
  .share-panel strong { grid-column: 1 / -1; }
}

.map-panel:fullscreen {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

.map-panel:fullscreen #map {
  flex: 1;
  height: auto;
  min-height: 0;
}

.map-panel:fullscreen .toolbar,
.map-panel:fullscreen .map-footer {
  flex: 0 0 auto;
}
