/* server/static/style.css */
/* 双端布局：>= 900px 桌面双栏；< 760px 手机单栏 + 底部切换坞 */
:root {
  --bg: #0b0d10;
  --card: #14181d;
  --line: #232a33;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4cc2ff;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --dock-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 80% -10%, #16222c 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 14px/1.5 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---------------------------------------------------------------- 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 13, 16, .82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { font-weight: 700; letter-spacing: .12em; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 400; letter-spacing: 0; margin-left: 8px; }

.panel-tabs { display: flex; gap: 8px; }
.panel-tabs a {
  width: 40px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  transition: .15s;
}
.panel-tabs a:hover { color: var(--text); border-color: #38434f; }
.panel-tabs a.active { color: #06121a; background: var(--accent); border-color: var(--accent); }

/* 底部坞的重启/播放键只在手机端出现 */
.dock-play, .dock-btn { display: none; }

.conn {
  margin-left: auto;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.conn[data-state="on"] { color: var(--ok); border-color: rgba(63,185,80,.4); background: rgba(63,185,80,.08); }
.conn[data-state="off"] { color: var(--err); border-color: rgba(248,81,73,.4); background: rgba(248,81,73,.08); }
.conn[data-state="wait"] { color: var(--warn); border-color: rgba(210,153,34,.4); background: rgba(210,153,34,.08); }

/* ---------------------------------------------------------------- 主布局 */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 1.1fr) minmax(360px, 1fr);
  gap: 18px;
  padding: 22px;
  align-items: start;
  max-width: 1480px;
  margin: 0 auto;
  min-width: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  min-width: 0;
}
.card.global { grid-column: 1 / -1; }

/* 手机端首屏的快捷素材卡：桌面端不出现 */
.quick { display: none; }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-head h2 { margin-bottom: 12px; }
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.card h2 span { color: var(--accent); }

.hint-inline { color: var(--muted); font-size: 11.5px; }

/* ---------------------------------------------------------------- 全局设置 */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.segmented button {
  border: 0;
  border-radius: 0;
  background: #0f1318;
  color: var(--muted);
  padding: 9px 16px;
  font-weight: 600;
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.active { background: var(--accent); color: #06121a; }

/* ---------------------------------------------------------------- 概览表 */
.grid-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.grid-table th, .grid-table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); }
.grid-table th { color: var(--muted); font-weight: 500; }
.grid-table tbody tr { cursor: pointer; }
.grid-table tbody tr:hover td { background: rgba(76,194,255,.06); }
.grid-table tbody tr.active td { background: rgba(76,194,255,.12); color: #fff; }
.grid-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }

/* ---------------------------------------------------------------- 表单 */
.field { margin-bottom: 16px; min-width: 0; }
.field > label { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; margin-bottom: 7px; }
.field output {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  background: rgba(76,194,255,.1);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
}

.row { display: flex; gap: 8px; align-items: center; margin-top: 7px; min-width: 0; }
.row:first-child { margin-top: 0; }
.row-wrap { flex-wrap: wrap; }
.row.actions { margin-top: 20px; flex-wrap: wrap; }
.row.player-row { margin-top: 0; flex-wrap: wrap; }
/* 音频元素只用于出声，不显示原生控件（控制由页面按钮完成） */
#audio-player { display: none; }

select, button {
  font: inherit;
  color: var(--text);
  background: #0f1318;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
}
select {
  flex: 1;
  min-width: 0;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) calc(50% - 2px), calc(100% - 12px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

button { cursor: pointer; transition: .15s; }
button, .panel-tabs a, input[type="range"] { touch-action: manipulation; }
button { user-select: none; -webkit-user-select: none; }
button:hover { border-color: #3a4653; }
button:disabled { opacity: .55; cursor: progress; }
button.ghost { background: #101922; border-color: #22303c; }
button.primary, #copy-all { background: var(--accent); color: #06121a; border-color: var(--accent); font-weight: 600; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 滑杆：统一两套内核的轨道与拇指，增强手机上的可点面积 */
input[type="range"] {
  width: 100%;
  height: 34px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: #1d2630;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  border: 2px solid #06121a;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(76,194,255,.16);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: #1d2630;
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid #06121a;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(76,194,255,.16);
}

/* ---------------------------------------------------------------- 编辑器（宽屏两列） */
@media (min-width: 1180px) {
  .editor-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 20px;
  }
  .editor-grid .span-2 { grid-column: 1 / -1; }
  .editor-grid .actions { margin-top: 4px; }
}

.muted { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 14px 0 0; }

/* 全局提示条：固定在右下，不依赖折叠区是否展开 */
#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 44px));
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(20, 24, 29, .97);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
#toast:not(:empty) { opacity: 1; }

/* ---------------------------------------------------------------- 折叠区 */
/* 桌面端素材区就是普通字段，折叠壳不参与布局；手机端才显示可点的标题栏 */
.fold { display: contents; }
.fold > summary { display: none; }

/* ---------------------------------------------------------------- 平板窄屏 */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- 手机端
   目标：第一屏只放「马上要点的东西」——节奏、播放、滑杆；
   素材与概览收进折叠区/隐藏，避免展示信息挤占操作区。 */
@media (max-width: 760px) {
  /* backdrop-filter 会让 fixed 子元素以顶栏为定位基准，手机端必须关掉，底部坞才能钉在视口 */
  .topbar {
    gap: 10px;
    padding: calc(8px + var(--safe-top)) 14px 8px;
    background: rgba(10, 13, 16, .96);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .brand { font-size: 13px; letter-spacing: .08em; }
  .brand span { margin-left: 4px; }
  .conn { padding: 4px 10px; font-size: 11px; }

  /* 底部操作坞：A/B/C/D + 从头播放 + 播放暂停，全部落在拇指区 */
  .panel-tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) 52px 62px;
    gap: 6px;
    padding: 8px 10px calc(8px + var(--safe-bottom));
    background: rgba(11, 13, 16, .96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .35);
  }
  .panel-tabs a {
    width: auto;
    height: 50px;
    border-radius: 12px;
    font-size: 16px;
  }
  .dock-btn {
    display: grid;
    place-items: center;
    height: 50px;
    min-height: 50px;
    padding: 0;
    border: 1px solid #22303c;
    border-radius: 12px;
    background: #101922;
    color: var(--text);
    font-size: 19px;
    line-height: 1;
  }
  .dock-play {
    display: grid;
    place-items: center;
    height: 50px;
    min-height: 50px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--accent);
    color: #06121a;
    font-size: 19px;
    font-weight: 700;
    line-height: 1;
  }
  .dock-btn:active, .dock-play:active { transform: scale(.95); }

  .layout {
    display: flex;
    flex-direction: column;
    /* 桌面 grid 上的 align-items:start 会沿用到 flex 子项，导致卡片按内容收缩；
       手机端必须显式拉伸，卡片才是整屏宽 */
    align-items: stretch;
    gap: 10px;
    padding: 10px 12px calc(var(--dock-h) + 34px + var(--safe-bottom));
  }
  .card { padding: 14px; border-radius: 13px; }

  /* ---------- 快捷素材卡：首屏主操作 ---------- */
  .card.quick { display: block; padding: 12px; }
  .quick-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .quick-head h2 { margin: 0; font-size: 14px; }
  .quick-head h2 span { color: var(--accent); }
  .quick-play {
    flex: 0 0 auto;
    width: 56px;
    min-height: 46px;
    padding: 0;
    border-radius: 12px;
    font-size: 18px;
    line-height: 1;
  }
  .quick-sub {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 10px 0 6px;
    font-size: 12px;
    color: var(--muted);
  }
  .quick-sub b {
    color: var(--text);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .quick-refresh { min-height: 34px; padding: 3px 10px; font-size: 12px; border-radius: 8px; }

  .thumb-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 8px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .thumb {
    position: relative;
    flex: 0 0 84px;
    height: 86px;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #0f1318;
    scroll-snap-align: start;
  }
  .thumb img {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    object-fit: cover;
    display: block;
    background: #0a0d10;
  }
  .thumb span {
    flex: 0 0 auto;
    padding: 2px 5px;
    font-size: 10px;
    line-height: 1.4;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .thumb.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
  .thumb.active span { color: var(--text); }
  .thumb.active::after {
    content: '✓';
    position: absolute;
    top: 3px;
    right: 4px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: var(--accent);
    color: #06121a;
    font-size: 11px;
    font-weight: 700;
    line-height: 17px;
    text-align: center;
  }
  .thumb.no-preview {
    background: repeating-linear-gradient(45deg, #12171d, #12171d 6px, #0f1318 6px, #0f1318 12px);
    justify-content: flex-end;
  }
  .thumb.no-preview::before {
    content: '无预览';
    margin: auto;
    color: var(--muted);
    font-size: 11px;
  }

  /* 音频也用横向按钮条：mp3 变多时横向滑动，不占首屏高度 */
  .audio-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 8px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .audio-item {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 7px;
    max-width: 66vw;
    min-height: 44px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #0f1318;
    font-size: 13px;
    scroll-snap-align: start;
  }
  .audio-item .audio-icon { flex: 0 0 auto; color: var(--muted); font-size: 12px; line-height: 1; }
  .audio-item .audio-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .audio-item.active { border-color: rgba(76,194,255,.7); background: rgba(76,194,255,.12); }
  .audio-item.active .audio-icon { color: var(--accent); }
  .audio-item.playing .audio-icon { color: var(--ok); }
  .audio-strip .empty { flex: 0 0 auto; }
  .empty { margin: 0; padding: 6px 2px; color: var(--muted); font-size: 12px; }

  /* 节奏模式压成一行，不占首屏 */
  .card.global { padding: 10px; }
  .card.global h2, .card.global .hint, #restart-btn { display: none; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; min-height: 44px; padding: 6px; }

  /* 概览默认不展示：手机端靠底部坞切换分屏即可 */
  .overview { display: none; }

  /* 编辑区在手机端变成两张折叠卡：素材管理 + 更多参数 */
  .card.editor { padding: 0; border: 0; background: transparent; }
  .card.editor h2 { display: none; }
  .editor-grid { display: flex; flex-direction: column; }
  .field-player { display: none; }
  .fold-media { order: 1; }
  .fold-adv { order: 2; }
  .fold > .actions { padding: 0 12px 12px; margin-top: 0; }

  .field { margin-bottom: 10px; }
  .field > label { font-size: 12.5px; margin-bottom: 0; }
  .field output { font-size: 12px; }

  /* 手机端隐藏解释性文案，只留控件 */
  .hint { display: none; }

  /* 素材折叠区：默认收起，一点展开 */
  .fold {
    display: block;
    margin: 4px 0 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #10151b;
    overflow: hidden;
  }
  .fold > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 46px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    list-style: none;
  }
  .fold > summary::-webkit-details-marker { display: none; }
  .fold > summary::after {
    content: '▾';
    color: var(--muted);
    font-size: 13px;
  }
  .fold[open] > summary { border-bottom: 1px solid var(--line); }
  .fold[open] > summary::after { content: '▴'; }
  .fold > .field { padding: 12px 12px 0; margin-bottom: 12px; }
  .fold > .field:last-child { margin-bottom: 0; padding-bottom: 12px; }
  .fold .row { flex-wrap: wrap; }
  .fold .row > select { flex: 1 1 100%; }
  .fold .row > button { flex: 1 1 0; }

  /* 控件统一放大，命中区域 >= 44px；input 字号 16px 防止 iOS 聚焦自动放大 */
  select, button { min-height: 44px; font-size: 16px; border-radius: 10px; }
  .row { gap: 8px; }
  .row.actions { flex-direction: column; align-items: stretch; gap: 8px; }
  #copy-all { width: 100%; min-height: 46px; }
  /* 提示条固定在操作坞上方，滚到哪都能看到结果 */
  #toast {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--dock-h) + 16px + var(--safe-bottom));
    z-index: 40;
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(20, 24, 29, .97);
    border: 1px solid var(--line);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
    text-align: center;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s;
  }
  #toast:not(:empty) { opacity: 1; }

  input[type="range"] { height: 40px; }
  input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -10px; }
  input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; }

  .only-desktop { display: none; }
}

/* 很窄的安卓机 / 分屏多窗口 */
@media (max-width: 380px) {
  .brand span { display: none; }
  .panel-tabs { grid-template-columns: repeat(4, minmax(0, 1fr)) 46px 56px; }
}

/* 触屏设备：按钮/滑杆再抬高一点，避免误触 */
@media (hover: none) and (pointer: coarse) {
  button { min-height: 44px; }
  input[type="range"] { height: 42px; }
}
