/* 各页面共用：颜色、字体、缓动、层级变量，导航栏和行程栏 */

:root {
  --ink: #100c0a;
  --light: #f3eee8;
  --light-dim: rgba(243, 238, 232, .72);
  --light-mute: rgba(243, 238, 232, .5);
  --hairline: rgba(243, 238, 232, .2);
  --glass: rgba(243, 238, 232, .1);
  --glass-edge: rgba(243, 238, 232, .3);
  --blue: #88a3d8;
  --button-ink: #17120f;

  --serif: "Newsreader", "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  --sans: "Geist", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  /* 层级（首页）：背景 < 遮罩 < 颗粒 < 转盘 < 文案 < 顶部控件 < 行程栏 < 搜索 */
  --z-backdrop: 0;
  --z-scrim: 1;
  --z-grain: 2;
  --z-wheel: 3;
  --z-intro: 4;
  --z-chrome: 5;
  --z-panel: 6;
  --z-search: 7;
}

*, *::before, *::after { box-sizing: border-box; }

/* ---------- 导航栏：顶部居中的玻璃胶囊（参考 archive/nav-reference.png） ---------- */

.topbar {
  position: fixed;
  z-index: var(--z-chrome);
  top: calc(12px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  width: min(720px, 100% - 2 * clamp(16px, 4vw, 48px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 8px 8px 20px;
  border: 1px solid var(--glass-edge);
  border-radius: 999px;
  background: var(--glass);
  box-shadow: inset 0 1px 0 var(--glass-edge); /* 顶边高光 */
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
          backdrop-filter: blur(16px) saturate(1.2);
  pointer-events: none; /* 只有按钮可点，不挡住下面的转盘 */
}

.brand {
  display: flex;
  align-items: center;
  gap: .45em;
  margin: 0;
  font: 600 15px/1.2 var(--sans);
}

/* 站名随语言切换；放不下时英文在词间折成两行，中文不拆开 */
.brand-name { word-break: keep-all; }

/* 站标：沿用转盘上城市标记的方块加圆点 */
.brand-mark {
  position: relative;
  flex: none;
  width: 1.05em;
  height: 1.05em;
  border-radius: .16em;
  background: var(--blue);
}

.brand-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: .3em;
  height: .3em;
  border-radius: 50%;
  background: rgba(16, 12, 10, .85);
  transform: translate(-50%, -50%);
}

/* 行程入口：心形加已加入的数量，和语言切换同高 */
.topbar-tools {
  flex: none; /* 空间不够时只让站名折行 */
  display: flex;
  align-items: center;
  gap: 8px;
}

.trip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--glass);
  color: var(--light);
  font: 500 12px/1 var(--sans);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  pointer-events: auto;
  transition: background-color .2s;
}

.trip-toggle:hover,
.trip-toggle[aria-expanded="true"] { background: var(--glass-edge); }

.trip-toggle svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

/* 登录 / 退出：和行程入口一样的小胶囊，cloud.js 连上 Supabase 后才显示 */
.auth {
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: var(--glass);
  color: var(--light);
  font: 500 12px/1 var(--sans);
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  transition: background-color .2s;
}

.auth:hover { background: var(--glass-edge); }

/* 攻略页的站名是回首页的链接 */
a.brand {
  color: inherit;
  text-decoration: none;
  pointer-events: auto;
}

/* ---------- 语言切换 ---------- */

/* 分段切换：半透明轨道里的圆形选项，选中项是实心浅色圆。首页是按钮，攻略页是去另一种语言那一页的链接 */
.lang {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: var(--glass);
  pointer-events: auto;
}

.lang > * {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--light-dim);
  font: 500 11px/1 var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: background-color .2s, color .2s;
}

.lang > :hover { color: var(--light); }

.lang > [aria-pressed="true"],
.lang > [aria-current="page"] {
  background: var(--light);
  color: var(--button-ink);
}

.trip-toggle:focus-visible,
.auth:focus-visible,
.trip-close:focus-visible,
.trip-edit:focus-visible,
.trip-jump:focus-visible,
.trip-grip:focus-visible,
.trip-remove:focus-visible,
.lang > :focus-visible,
a.brand:focus-visible {
  outline: 2px solid var(--light);
  outline-offset: 3px;
}

/* ---------- 行程栏：右侧悬浮的玻璃面板（参考 archive/trip-panel-reference.png） ---------- */

.trip {
  position: fixed;
  z-index: var(--z-panel);
  top: calc(var(--bar-bottom, 60px) + 12px); /* 贴着导航栏下方，--bar-bottom 由 site.js 量出 */
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: clamp(232px, 22vw, 288px); /* 1024 宽起不挡住“下一站”旁的心形 */
  display: flex;
  flex-direction: column;
  border: 1px solid var(--glass-edge);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--glass) 0%, rgba(16, 12, 10, .7) 100%);
  box-shadow: inset 0 1px 0 var(--glass-edge), 0 24px 60px rgba(10, 7, 6, .4);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
          backdrop-filter: blur(20px) saturate(1.2);
}

.trip[hidden] { display: none; }
.trip:focus { outline: none; }

.trip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 20px;
  padding: 10px 0 8px;
  border-bottom: 1px solid var(--hairline);
}

.trip-title {
  margin: 0;
  font: 500 11px/1.2 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
}

.trip-close,
.trip-grip,
.trip-remove {
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--light-mute);
  cursor: pointer;
  transition: color .2s, opacity .2s;
}

.trip-close {
  width: 32px;
  height: 32px;
  margin-right: -8px;
  color: var(--light-dim);
}

.trip-close:hover,
.trip-grip:hover,
.trip-remove:hover { color: var(--light); }

.trip-close svg,
.trip-remove svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.trip-body {
  position: relative; /* 拖动时按 offsetTop 计算位移 */
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 20px 20px;
  scroll-padding-block: 16px; /* 滚到新加的那一行时不贴着边 */
  touch-action: pan-y;
}

.trip-empty {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--light-dim);
}

.trip-empty strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
  color: var(--light);
}

.trip-list,
.trip-spots {
  margin: 0;
  padding: 0;
  list-style: none;
}

.trip-group,
.trip-spot {
  margin: 0 -8px;
  padding: 0 8px;
  border-radius: 8px;
}

.trip-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 30px;
}

.trip-grip {
  width: 20px;
  height: 30px;
  margin-left: -4px;
  border-radius: 6px;
  cursor: grab;
  touch-action: none; /* 触屏按住把手直接拖动，不滚动列表 */
}

.trip-grip svg {
  width: 10px;
  height: 14px;
  fill: currentColor;
}

.trip-name {
  flex: 1;
  min-width: 0;
  margin: 0;
  font: 400 13px/1.3 var(--sans);
  color: var(--light);
}

/* 名字可点：首页转盘跳到这个地方，攻略页去它的攻略。景点名稍暗，首页正在显示的那一项变亮并带圆点 */
.trip-jump {
  display: block;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: color .2s;
}

span.trip-jump { cursor: auto; } /* 攻略页上的酒店没有攻略，名字不可点 */

.trip-spot .trip-jump { color: var(--light-dim); }

.trip-jump[aria-current="location"] { color: var(--light); }
.trip-spot .trip-jump[aria-current="location"] { font-weight: 500; }

.trip-jump[aria-current="location"]::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--blue);
  vertical-align: .15em;
}

@media (hover: hover) and (pointer: fine) {
  .trip-jump:not(span):hover {
    color: var(--light);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
  }
}

/* 编辑按钮只在竖屏出现 */
.trip-edit {
  display: none;
  margin-left: auto;
  height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--light-dim);
  font: 500 12px/1 var(--sans);
  cursor: pointer;
  transition: color .2s;
}

.trip-edit:hover,
.trip.is-editing .trip-edit { color: var(--light); }

/* 树状层级：城市是一级（大号加粗），景点是二级，缩进并用左侧竖线连在城市下面 */
.trip-row.is-city .trip-name {
  font-size: 15px;
  font-weight: 600;
}

.trip-spots {
  margin-left: 6px; /* 竖线对齐城市把手的中线 */
  padding-left: 10px;
  border-left: 1px solid var(--hairline);
}

/* 新加入的那一行短暂高亮 */
.trip-row {
  border-radius: 6px;
  transition: background-color .6s, box-shadow .6s;
}

.trip-row.is-new {
  background: var(--hairline);
  box-shadow: 0 0 0 4px var(--hairline);
}

.trip-remove {
  width: 28px;
  height: 28px;
  margin-right: -6px;
}

/* 鼠标设备上删除按钮悬停才显示，触屏上常显 */
@media (hover: hover) and (pointer: fine) {
  .trip-remove { opacity: 0; }
  .trip-row:hover .trip-remove,
  .trip-remove:focus-visible { opacity: 1; }
}

/* 相邻两站的直线距离；第一站上面是机场和高铁站到它的距离，城市之间是高铁和飞机用时 */
.trip-leg {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
  margin: 0;
  padding: 2px 0 2px 6px;
  font-size: 11px;
  line-height: 1.2;
  color: var(--light-mute);
  font-variant-numeric: tabular-nums;
}

.trip-spot .trip-leg { padding-left: 20px; } /* 和景点名对齐 */

.trip-arrive { display: block; }

.trip-arrive p {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin: 0;
}

.trip-arrive p + p { margin-top: 2px; }

.trip-hub {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.trip-time { white-space: nowrap; } /* 一项用时不拆行 */

/* 机场、高铁站后面的几种用时作为一组，放不下时整组换行 */
.trip-modes {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px 10px;
}

.trip-icon {
  flex: none;
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.trip-group + .trip-group { margin-top: 10px; }

/* 城市名后面：从上一座城市过来的高铁和飞机用时，放不下时换到名字下面 */
.trip-row.is-city .trip-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
}

.trip-hop {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--light-mute);
  font-variant-numeric: tabular-nums;
}

/* 拖动中：被拖的项浮起，距离等放下后再重算 */
.trip-list.is-sorting { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.trip-list.is-sorting .trip-leg,
.trip-list.is-sorting .trip-hop { visibility: hidden; }
.trip-list.is-sorting .trip-grip { cursor: grabbing; }

.trip-list .is-dragging {
  position: relative;
  z-index: 1;
  background: rgba(16, 12, 10, .55);
  box-shadow: inset 0 0 0 1px var(--hairline), 0 10px 28px rgba(10, 7, 6, .45);
}

/* ---------- 竖屏 / 手机（断点和 home.css、site.js 里的一致） ---------- */

@media (max-width: 859px), (max-aspect-ratio: 11/10) {
  .topbar { top: calc(8px + env(safe-area-inset-top)); gap: 12px; padding: 4px 4px 4px 14px; }
  .brand { font-size: min(14px, 3.8vw); } /* 320px 宽的手机也放得下 */

  /* 行程栏靠右，宽 1/3（首页的高度见 home.css）；平时每行只有名字，点“编辑”加宽到 1/2 并显示把手和删除 */
  .trip {
    right: clamp(16px, 4vw, 48px);
    width: calc(100% / 3);
    transition: width .3s var(--ease-out);
  }

  .trip.is-editing { width: 50%; }
  .trip-head { margin: 0 12px; padding: 2px 0; } /* 竖屏收紧标题栏，多留地方给行程 */
  .trip-body { padding: 8px 12px 12px; }
  .trip-edit { display: block; }
  .trip-jump { white-space: normal; overflow-wrap: anywhere; }
  .trip.is-editing .trip-jump { cursor: default; }

  .trip:not(.is-editing) .trip-grip,
  .trip:not(.is-editing) .trip-remove { display: none; }
  .trip:not(.is-editing) .trip-spots { margin-left: 4px; padding-left: 8px; }
  .trip:not(.is-editing) .trip-spot .trip-leg { padding-left: 0; }

  /* 手机上 1/3 宽放不下标题、编辑和关闭，标题只留给读屏 */
  @media (max-width: 599px) {
    .trip-title {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }
  }
}

@media (pointer: coarse) {
  .lang > * { width: 38px; height: 38px; font-size: 12px; }
  .trip-toggle { height: 42px; padding: 0 15px 0 14px; font-size: 13px; }
  .auth { height: 42px; padding: 0 14px; font-size: 13px; }
  .trip-close { width: 36px; height: 36px; margin-right: -8px; }
  .trip-edit { height: 36px; padding: 0 10px; }
  .trip-row { min-height: 44px; }
  .trip-grip { width: 32px; height: 44px; margin-left: -10px; }
  .trip-spot .trip-leg { padding-left: 26px; }
  .trip-remove { width: 44px; height: 44px; margin-right: -14px; }
}

/* 最窄的手机上收紧导航栏的间距，英文的“Sign out”也放得下 */
@media (max-width: 374px) {
  .topbar { gap: 6px; padding-left: 12px; }
  .topbar-tools { gap: 4px; }
  .trip-toggle,
  .auth { padding: 0 10px; }
}

/* 再窄英文站名折两行也放不下，只留站标，站名留给读屏 */
@media (max-width: 339px) {
  .brand-name:lang(en) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* 系统要求降低透明度时，玻璃改成实底 */
@media (prefers-reduced-transparency: reduce) {
  .topbar,
  .trip {
    background: var(--ink);
    -webkit-backdrop-filter: none;
            backdrop-filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
