:root {
  color-scheme: light;
  --ink: #17231f;
  --muted: #66736e;
  --line: #d9e0dc;
  --paper: #f7f8f5;
  --panel: #ffffff;
  --accent: #e45a2a;
  --accent-dark: #b94019;
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--ink); background: var(--paper); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { height: 100vh; height: 100dvh; min-height: 0; display: grid; grid-template-columns: minmax(300px, 370px) 1fr; overflow: hidden; }
.sidebar { z-index: 500; display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; padding: 32px 28px 20px; overflow: hidden; background: rgba(255,255,255,.97); box-shadow: 12px 0 36px rgba(23,35,31,.12); }
.eyebrow { margin: 0 0 8px; color: var(--accent-dark); font-size: .78rem; font-weight: 800; letter-spacing: .15em; text-transform: uppercase; }
.brand-block h1 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(2rem, 4vw, 3.1rem); line-height: 1; letter-spacing: -.04em; }
.brand-block h1.brand-title-japanese { font-size: clamp(1.7rem, 3vw, 2.4rem); white-space: nowrap; }
.brand-block > p:last-child { margin: 18px 0 0; color: var(--muted); line-height: 1.75; }
.sidebar-actions { display: flex; align-items: center; gap: 12px; margin: 28px 0 14px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.master-toggle { display: flex; align-items: center; gap: 9px; min-height: 42px; font-size: .9rem; font-weight: 800; cursor: pointer; }
.master-toggle input, .track-checkbox, .admin-track-checkbox { width: 19px; height: 19px; flex: 0 0 auto; accent-color: var(--accent); cursor: pointer; }
.secondary-button { min-height: 42px; padding: 9px 13px; border: 1px solid var(--ink); border-radius: 8px; color: var(--ink); background: transparent; font-weight: 700; }
.sidebar-actions .secondary-button { width: 100%; }
.secondary-button:hover { color: white; background: var(--ink); }
.secondary-button:disabled { cursor: not-allowed; opacity: .45; }
.status-message { padding: 18px 0; color: var(--muted); line-height: 1.6; }
.sort-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: 0 0 12px; border-bottom: 1px solid var(--line); }
.sort-tab { min-height: 42px; padding: 9px 10px 7px; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; font-size: .875rem; font-weight: 800; }
.sort-tab:hover { color: var(--ink); background: #f4f7f4; }
.sort-tab.active { border-bottom-color: var(--accent); color: var(--ink); }
.sort-tab:disabled { cursor: not-allowed; opacity: .45; }
.track-list { flex: 1 1 auto; min-height: 0; display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; overflow: auto; }
.track-scroll-spacer { pointer-events: none; }
.track-card { display: grid; grid-template-columns: 17px 7px minmax(0, 1fr); align-items: center; gap: 6px; padding-left: 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); transition: border-color .2s, transform .2s; }
.track-card:hover { border-color: #aebbb5; transform: translateY(-1px); }
.track-card.active { border-color: var(--ink); background: #f1f5f2; box-shadow: inset 3px 0 var(--ink); }
.track-card a { display: block; min-width: 0; padding: 3px 8px 3px 0; color: inherit; text-decoration: none; }
.track-checkbox { width: 15px; height: 15px; }
.track-swatch { width: 7px; height: 24px; border-radius: 99px; background: var(--track-color); }
.track-copy { min-width: 0; display: grid; gap: 0; }
.track-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; line-height: 1.25; }
.track-copy small { color: var(--muted); font-size: .68rem; line-height: 1.2; }
.sidebar-footer { margin-top: auto; padding-top: 20px; color: var(--muted); font-size: .75rem; line-height: 1.5; }
.map-stage { position: relative; min-width: 0; height: 100vh; height: 100dvh; min-height: 0; }
#map { position: absolute; inset: 0; background: #dce5df; }
.map-title-card { position: absolute; z-index: 450; left: 22px; bottom: 22px; display: grid; gap: 2px; min-width: 115px; padding: 12px 16px; border: 1px solid rgba(255,255,255,.75); border-radius: 10px; background: rgba(23,35,31,.9); color: white; box-shadow: 0 8px 24px rgba(23,35,31,.18); }
.map-title-card span { font-size: .72rem; opacity: .75; }
.map-title-card strong { font-size: 1rem; }
.profile-visible .map-title-card { bottom: 222px; }
.elevation-profile { position: absolute; z-index: 650; right: 18px; bottom: 18px; left: 18px; padding: 12px 14px 10px; border: 1px solid rgba(255,255,255,.85); border-radius: 12px; background: rgba(255,255,255,.96); box-shadow: 0 12px 34px rgba(23,35,31,.22); backdrop-filter: blur(6px); }
.profile-header { display: grid; grid-template-columns: minmax(0, 1fr) auto 34px; align-items: center; gap: 14px; margin-bottom: 5px; }
.profile-header > div { display: grid; gap: 2px; min-width: 0; }
.profile-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.profile-summary { color: var(--muted); font-size: .78rem; }
.profile-live { min-width: 150px; font-size: .82rem; text-align: right; }
.profile-close { width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: white; font-size: 1.25rem; line-height: 1; }
.profile-close:hover { color: white; background: var(--ink); }
.profile-canvas { display: block; width: 100%; height: 125px; cursor: crosshair; touch-action: none; }
.profile-canvas:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, white); outline-offset: 2px; }
.profile-empty { margin: 20px 0; color: var(--muted); text-align: center; }
.leaflet-control-layers, .leaflet-bar { border: 0 !important; box-shadow: 0 5px 18px rgba(23,35,31,.2) !important; }
.leaflet-control-attribution { font-size: 11px; }
.route-popup { display: grid; gap: 7px; min-width: 210px; }
.route-popup-title { font-size: 1rem; }
.route-popup-meta { color: var(--muted); font-size: .78rem; }
.route-popup-description { margin: 5px 0; line-height: 1.6; white-space: pre-wrap; }
.route-popup a { color: var(--accent-dark); font-weight: 700; }
.route-hit-area:focus { outline: none; }

.admin-map-page { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; background: var(--paper); }
.admin-app-shell { display: grid; grid-template-columns: minmax(340px, 410px) 1fr; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.admin-sidebar { z-index: 500; display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; padding: 24px; overflow: hidden; background: rgba(255,255,255,.98); box-shadow: 12px 0 36px rgba(23,35,31,.12); }
.admin-brand { position: relative; margin-bottom: 20px; }
.admin-brand h1 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: 1.85rem; }
.admin-brand .text-link { display: inline-block; margin-top: 10px; }
.admin-new-button { width: 100%; min-height: 52px; margin: 18px 0; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--accent-dark); background: #fafbf9; font-weight: 800; text-align: left; }
.admin-new-button::before { content: "＋ "; }
.admin-new-button:hover { border-color: var(--accent); background: #fff7f3; }
.admin-form { display: grid; gap: 13px; padding: 16px; }
.admin-form label { display: grid; gap: 6px; font-size: .86rem; font-weight: 700; }
.admin-form input[type="text"], .admin-form input[type="file"], .admin-form textarea { width: 100%; min-height: 42px; padding: 9px 10px; border: 1px solid #aebbb5; border-radius: 8px; background: white; }
.admin-form input[type="color"] { width: 70px; height: 42px; padding: 3px; border: 1px solid #aebbb5; border-radius: 8px; background: white; }
.admin-form textarea { resize: vertical; line-height: 1.55; }
.admin-form small { color: var(--muted); font-weight: 400; }
.admin-form button { min-height: 44px; border: 0; border-radius: 8px; color: white; background: var(--accent); font-weight: 800; }
.admin-form button:hover { background: var(--accent-dark); }
.admin-menu { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; margin-top: 22px; }
.admin-menu h2 { margin: 0; font-size: 1.05rem; }
.admin-sort-tabs { margin-top: 10px; }
.admin-master-toggle { margin: 2px 0 8px; padding: 8px 9px; border-bottom: 1px solid var(--line); }
.admin-track-list { flex: 1 1 auto; min-height: 0; margin-top: 10px; overflow-y: auto; }
.admin-track-scroll-spacer { pointer-events: none; border: 0 !important; }
.admin-track-link { display: grid; grid-template-columns: 10px 1fr; align-items: center; gap: 12px; padding: 11px 9px; border-radius: 9px; color: inherit; text-decoration: none; }
.admin-track-link:hover, .admin-track-link.active { background: #eef3ef; }
.admin-track-link.active { box-shadow: inset 3px 0 var(--ink); }
.admin-track-link > span:last-child { display: grid; gap: 3px; min-width: 0; }
.admin-track-link strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-track-link small { color: var(--muted); font-size: .78rem; }
.admin-editor { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.admin-editor h2 { margin: 0; font-size: 1.05rem; }
.admin-editor .admin-form { padding-right: 0; padding-left: 0; }
.direct-link { display: inline-block; color: var(--accent-dark); font-size: .88rem; font-weight: 700; }
.direct-link-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.copy-link-button { min-height: 34px; padding: 6px 11px; border: 1px solid var(--accent-dark); border-radius: 8px; color: var(--accent-dark); background: white; font-size: .82rem; font-weight: 700; }
.copy-link-button:hover { color: white; background: var(--accent-dark); }
.copy-link-button:disabled { cursor: wait; opacity: .65; }
.copy-link-status { min-height: 1em; color: var(--muted); font-size: .8rem; }
.admin-map-stage { position: relative; min-width: 0; min-height: 100vh; }
.admin-map-stage #map { position: absolute; inset: 0; }
.map-status { position: absolute; z-index: 450; top: 14px; left: 50%; margin: 0; padding: 10px 14px; border-radius: 8px; background: rgba(255,255,255,.94); box-shadow: 0 4px 16px rgba(23,35,31,.14); transform: translateX(-50%); }

.admin-page { min-height: 100vh; padding: 36px 20px 64px; background: linear-gradient(135deg, #edf2ee, #f9f7f1); }
.admin-shell { width: min(820px, 100%); margin: 0 auto; }
.admin-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.admin-header h1 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(1.8rem, 5vw, 2.8rem); }
.text-link { color: var(--accent-dark); font-weight: 700; }
.admin-card { margin-top: 18px; padding: clamp(20px, 4vw, 32px); border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.96); box-shadow: 0 12px 34px rgba(23,35,31,.08); }
.admin-card h2 { margin: 0 0 8px; font-size: 1.28rem; }
.admin-card > p { margin: 0 0 24px; color: var(--muted); line-height: 1.7; }
.upload-form { display: grid; grid-template-columns: 1fr 110px; gap: 18px; }
.upload-form label { display: grid; gap: 8px; font-weight: 700; }
.upload-form label:nth-of-type(3) { grid-column: 1 / -1; }
.upload-form input[type="text"], .upload-form input[type="file"] { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #aebbb5; border-radius: 8px; background: white; }
.upload-form input[type="color"] { width: 100%; height: 46px; padding: 3px; border: 1px solid #aebbb5; border-radius: 8px; background: white; }
.upload-form small { color: var(--muted); font-size: .8rem; font-weight: 400; line-height: 1.5; }
.upload-form button { grid-column: 1 / -1; min-height: 50px; border: 0; border-radius: 9px; color: white; background: var(--accent); font-weight: 800; }
.upload-form button:hover { background: var(--accent-dark); }
.notice { padding: 14px 18px; border-radius: 10px; font-weight: 700; }
.notice.success { border: 1px solid #8dc6a3; background: #e8f6ed; color: #165a31; }
.notice.error { border: 1px solid #e3a29b; background: #fff0ee; color: #8a241b; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading span { color: var(--muted); font-size: .9rem; }
.admin-track-list { display: grid; align-content: start; gap: 4px; margin-right: 0; margin-bottom: 0; margin-left: 0; padding: 0; list-style: none; }
.color-chip { width: 8px; height: 38px; border-radius: 99px; background: var(--track-color); }
.admin-track-list div { display: grid; gap: 4px; }
.admin-track-list small { color: var(--muted); font-size: .82rem; }
.empty-copy { color: var(--muted); }

.admin-track-card { display: grid; grid-template-columns: 17px 7px minmax(0, 1fr); align-items: center; gap: 6px; padding-left: 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); transition: border-color .2s, transform .2s; }
.admin-track-card:hover { border-color: #aebbb5; transform: translateY(-1px); }
.admin-track-card.active { border-color: var(--ink); background: #f1f5f2; box-shadow: inset 3px 0 var(--ink); }
.admin-track-checkbox { width: 15px; height: 15px; margin: 0; }
.admin-track-button { width: 100%; min-width: 0; min-height: 0; padding: 3px 8px 3px 0; overflow-wrap: anywhere; border: 0; border-radius: 0 7px 7px 0; color: var(--ink); background: transparent; font-weight: 800; text-align: left; }
.admin-track-button { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.admin-track-list .track-copy small { font-size: .68rem; line-height: 1.2; }
.publication-badge { padding: 3px 7px; border-radius: 99px; background: #dff4e6; color: #17643a; font-size: .68rem; white-space: nowrap; }
.track-unpublished .publication-badge { background: #ecefed; color: #59635e; }
.track-unpublished .admin-track-button { color: #66706b; }
.admin-track-button:hover { background: rgba(255,255,255,.55); }
.admin-track-button.active { background: transparent; }
.track-editor { width: min(560px, calc(100% - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: white; box-shadow: 0 24px 70px rgba(14,25,20,.3); }
.track-editor::backdrop { background: rgba(13,24,20,.55); backdrop-filter: blur(3px); }
.track-editor-form { gap: 18px; padding: 24px; }
.track-editor-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.track-editor-header h2 { margin: 0; font-size: 1.35rem; }
.track-editor .dialog-close { width: 42px; min-height: 42px; padding: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: white; font-size: 1.5rem; line-height: 1; }
.track-editor .dialog-close:hover { color: white; background: var(--ink); }
.publication-toggle { grid-template-columns: 22px minmax(0, 1fr); align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #f7f9f7; }
.publication-toggle input { width: 19px; height: 19px; margin: 0; accent-color: var(--accent); }
.publication-toggle > span { display: grid; gap: 2px; }
.publication-toggle small { color: var(--muted); font-weight: 400; }
.private-link-note { grid-column: 1 / -1; color: var(--muted); font-size: .85rem; }
.direct-link[hidden], .copy-link-button[hidden], .private-link-note[hidden] { display: none !important; }
.track-editor-actions { display: grid; grid-template-columns: 1fr 110px; gap: 10px; }
.track-editor-actions .secondary-button { border: 1px solid var(--ink); color: var(--ink); background: white; }
.track-editor-actions .secondary-button:hover { color: white; background: var(--ink); }
.track-editor-actions .danger-button { grid-column: 1 / -1; border: 1px solid #b42318; color: #a51d13; background: white; }
.track-editor-actions .danger-button:hover { color: white; background: #b42318; }

@media (max-width: 780px) {
  .app-shell { display: block; height: auto; min-height: 100vh; overflow: visible; }
  .sidebar { height: auto; min-height: auto; padding: 22px 18px 16px; overflow: visible; box-shadow: 0 10px 24px rgba(23,35,31,.12); }
  .brand-block h1 { font-size: 2.25rem; }
  .brand-block > p:last-child { margin-top: 11px; line-height: 1.55; }
  .sidebar-actions { margin-top: 18px; }
  .track-list { flex: none; max-height: 210px; }
  .sidebar-footer { display: none; }
  .map-stage, #map { height: auto; min-height: 58vh; }
  #map { position: relative; height: 58vh; }
  .map-title-card { left: 12px; bottom: 12px; }
  .profile-visible .map-title-card { display: none; }
  .elevation-profile { right: 8px; bottom: 8px; left: 8px; padding: 10px; }
  .profile-header { grid-template-columns: minmax(0, 1fr) 32px; gap: 8px; }
  .profile-live { grid-column: 1 / -1; grid-row: 2; min-width: 0; text-align: left; }
  .profile-close { grid-column: 2; grid-row: 1; }
  .profile-canvas { height: 112px; }
  .admin-header { align-items: flex-start; flex-direction: column; }
  .upload-form { grid-template-columns: 1fr; }
  .upload-form label:nth-of-type(3), .upload-form button { grid-column: auto; }
  .admin-map-page { height: auto; min-height: 100vh; overflow: auto; }
  .admin-app-shell { display: block; height: auto; min-height: 100vh; overflow: visible; }
  .admin-sidebar { height: auto; max-height: none; padding: 20px 18px; overflow: visible; box-shadow: 0 10px 24px rgba(23,35,31,.12); }
  .admin-menu { display: block; }
  .admin-track-list { max-height: 50vh; overflow-y: auto; }
  .admin-map-stage, .admin-map-stage #map { min-height: 58vh; }
  .admin-map-stage #map { position: relative; height: 58vh; }
  .track-editor-form { padding: 20px; }
  .track-editor-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

