:root{
  --dock-split: 8px;
  --dock-min-pane: 220px;
  --dock-left: 60%;
  --dock-top: 60%;

  --page-pad: clamp(10px, 1.4vw, 18px);
  --radius: 18px;
  --radius-sm: 12px;

  --bg0: #060913;
  --bg1: #0b1430;
  --appTop: #0b1633;
  --appBot: #060913;

  --panelTop: #0a1531;
  --panelBot: #070f24;

  --fg: #e6edf3;
  --muted: rgba(166,179,199,.9);

  --stroke: rgba(148,163,184,.16);
  --stroke2: rgba(148,163,184,.10);

  --accent: #6d5ef7;
  --accent2: #22d3ee;
  --red: #ef4444;
  --green: #22c55e;
  --blue: #60a5fa;

  --shadow-app: 0 18px 42px rgba(0,0,0,.45);
}

*{ box-sizing: border-box; }

html, body{
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body{
  padding: var(--page-pad);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft Yahei", Arial, sans-serif;
  background:
    radial-gradient(900px 520px at 18% -10%, rgba(34,211,238,.10), transparent 60%),
    radial-gradient(900px 520px at 85% 0%, rgba(109,94,247,.12), transparent 62%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
}

.app{
  width: calc(100vw - var(--page-pad) * 2);
  height: calc(100vh - var(--page-pad) * 2);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  border-radius: var(--radius);
  border: 1px solid rgba(148,163,184,.14);
  box-shadow: var(--shadow-app);
  background: linear-gradient(180deg, var(--appTop) 0%, var(--appBot) 100%);
}

.topbar{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;

  padding: 14px 16px;
  user-select: none;
  background: linear-gradient(180deg, #0c1938 0%, #081127 100%);
  border-bottom: 1px solid rgba(148,163,184,.14);
}

.brand{
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-dot{
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  box-shadow: 0 8px 18px rgba(0,0,0,.35);
  flex: 0 0 auto;
}

.brand-text{
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-title{
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub{
  font-size: 12px;
  color: rgba(166,179,199,.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-mark{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  position: relative;
  flex: 0 0 auto;

  background: linear-gradient(135deg, rgba(34,211,238,.22), rgba(109,94,247,.20));
  border: 1px solid rgba(148,163,184,.18);
  box-shadow: 0 8px 18px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.06);
  overflow: hidden;
}

.brand-mark .mark-wave{
  position: absolute;
  left: 8px;
  bottom: 8px;
  width: 3px;
  height: 8px;
  border-radius: 999px;
  background: rgba(230,237,243,.92);
  box-shadow:
    6px  -4px 0 rgba(230,237,243,.92),
    12px  2px 0 rgba(230,237,243,.92),
    18px -7px 0 rgba(230,237,243,.92);
  opacity: .95;
}

.brand-mark .mark-wave::after{
  content: "";
  position: absolute;
  left: -6px;
  top: -10px;
  width: 28px;
  height: 28px;
  background:
    linear-gradient(90deg, rgba(34,211,238,.0) 0%,
                           rgba(34,211,238,.18) 35%,
                           rgba(109,94,247,.0) 70%);
  transform: rotate(-18deg);
  pointer-events: none;
}

.brand-mark .mark-bolt{
  position: absolute;
  right: 6px;
  top: 7px;
  width: 14px;
  height: 18px;
  background: linear-gradient(180deg, rgba(34,211,238,.95), rgba(109,94,247,.95));
  clip-path: polygon(45% 0%, 100% 0%, 62% 45%, 95% 45%, 35% 100%, 52% 56%, 20% 56%);
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.35));
}

@media (prefers-reduced-motion: no-preference){
  .brand-mark .mark-wave::after{
    animation: waveSweep 1.2s linear infinite;
  }
  @keyframes waveSweep{
    from{ transform: translateX(-6px) rotate(-18deg); opacity:.65; }
    to  { transform: translateX(10px) rotate(-18deg); opacity:.95; }
  }
}

.controls{
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

select{
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  background: rgba(0,0,0,.18);
  color: var(--fg);
  border: 1px solid rgba(148,163,184,.20);
  border-radius: 999px;
  padding: 6px 28px 6px 10px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

button{
  border: 1px solid rgba(148,163,184,.18);
  color: rgba(230,237,243,.95);
  background: rgba(255,255,255,.06);
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
}

button:hover{
  background: rgba(255,255,255,.10);
}

button:disabled{
  opacity: .55;
  cursor: not-allowed;
}

#btnSettingsRandom .icon-rotate{
  display: inline-block;
  transform-origin: 50% 50%;
}

@media (prefers-reduced-motion: no-preference){
  #btnSettingsRandom.loading .icon-rotate{
    animation: settingsSpin 0.85s linear infinite;
  }
}

@keyframes settingsSpin{
  from{ transform: rotate(0deg); }
  to  { transform: rotate(360deg); }
}

#btnSettingsRandom.loading .btn-text{
  opacity: 0.85;
}

.btn-group{
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.btn-cluster{
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.btn-sep{
  width: 1px;
  height: 26px;
  background: rgba(148,163,184,.28);
  border-radius: 999px;
  align-self: center;
}

#btnCall{
  background: linear-gradient(135deg, rgba(109,94,247,.95), rgba(34,211,238,.55));
  border-color: rgba(109,94,247,.35);
}

#btnHang{
  background: linear-gradient(135deg, rgba(239,68,68,.95), rgba(239,68,68,.55));
  border-color: rgba(239,68,68,.45);
}

button.ghost{
  background: rgba(255,255,255,.05);
  border-color: rgba(148,163,184,.16);
}

main.dock{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;

  display: grid;
  grid-template-columns: var(--dock-left) var(--dock-split) 1fr;
  grid-template-rows: var(--dock-top) var(--dock-split) 1fr;

  padding: 12px;
  gap: 0;
  overflow: hidden;
}

section.pane{
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;

  border-radius: 14px;
  border: 1px solid var(--stroke2);
  background: linear-gradient(180deg, var(--panelTop) 0%, var(--panelBot) 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
  contain: layout paint;
}

.pane-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;

  padding: 10px 12px;
  border-bottom: 1px solid rgba(148,163,184,.10);
}

.pane-header h3{
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .2px;
  color: rgba(230,237,243,.92);
}

.hdr-actions{
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-body{
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 10px 12px;

  display: flex;
  flex-direction: column;
}

.splitter{
  background: rgba(148,163,184,.08);
  border-left: 1px solid rgba(148,163,184,.10);
  border-top: 1px solid rgba(148,163,184,.10);
  z-index: 5;
}
.splitter:hover{ background: rgba(148,163,184,.14); }
.splitter.v{ cursor: col-resize; }
.splitter.h{ cursor: row-resize; }
.splitter.c{ cursor: nwse-resize; }

.bubbles{
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 6px;

  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble{
  max-width: 70%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.55;
  border: 1px solid rgba(148,163,184,.14);
  background: rgba(255,255,255,.04);
}

.bubble.user{
  align-self: flex-end;
  background: rgba(109,94,247,.10);
  border-color: rgba(109,94,247,.22);
}

.bubble.assistant{
  align-self: flex-start;
  background: rgba(34,211,238,.08);
  border-color: rgba(34,211,238,.18);
}

.bubble-text{
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.bubble-text-chunk{
  opacity: 0;
  animation: bubbleTextFadeIn .26s ease forwards;
  will-change: opacity;
}

@keyframes bubbleTextFadeIn{
  from{ opacity: 0; }
  to{ opacity: 1; }
}

.bubble small{
  display: block;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(166,179,199,.88);
}

.wave-body{
  padding: 10px 12px 12px;
}

.wave-container{
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 140px;

  overflow-x: auto;
  overflow-y: hidden;

  border-radius: 12px;
  border: 1px solid rgba(148,163,184,.18);
  background: rgba(0,0,0,.16);
}

#waveCanvas{
  display: block;
  height: 100%;
  max-width: none;
}

.wave-tooltip{
  position: absolute;
  bottom: 6px;
  transform: translate(-50%, -120%);
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 12px;
  background: rgba(6,9,19,.95);
  border: 1px solid rgba(148,163,184,.35);
  color: rgba(230,237,243,.95);
  pointer-events: none;
  white-space: nowrap;
  display: none;
}

.keydata-wrap{
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.perf-card{
  flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid rgba(148,163,184,.12);
  background: rgba(255,255,255,.03);
  padding: 10px 12px;
}

.perf-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}

.perf-title{
  font-size: 13px;
  font-weight: 700;
  color: rgba(230,237,243,.92);
}

.perf-unit{
  font-size: 12px;
  color: rgba(166,179,199,.90);
}

.perf-grid{
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px 10px;
  margin-top: 8px;
}

.kv{
  display:flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(148,163,184,.12);
  font-size: 12px;
  color: rgba(230,237,243,.90);
}

.kv b{
  font-weight: 700;
  color: rgba(230,237,243,.95);
}

.kv span{
  font-variant-numeric: tabular-nums;
  color: rgba(166,179,199,.95);
}

.nice-scroll{
  scrollbar-width: thin;
  scrollbar-color: rgba(148,163,184,.40) rgba(0,0,0,0);
}

.nice-scroll::-webkit-scrollbar{
  width: 10px;
  height: 10px;
}

.nice-scroll::-webkit-scrollbar-track{
  background: rgba(0,0,0,0);
  border-radius: 999px;
}

.nice-scroll::-webkit-scrollbar-thumb{
  background: rgba(148,163,184,.30);
  border-radius: 999px;
  border: 2px solid rgba(6,9,19,.55);
}

.nice-scroll::-webkit-scrollbar-thumb:hover{
  background: rgba(148,163,184,.45);
}

#player{
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#btnSettings{
  background: linear-gradient(135deg, rgba(148,163,184,.22), rgba(148,163,184,.08));
  border-color: rgba(148,163,184,.28);
  color: rgba(230,237,243,.92);
}
#btnSettings:hover{
  background: linear-gradient(135deg, rgba(148,163,184,.28), rgba(148,163,184,.12));
}

.modal-backdrop{
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,.55);
  z-index: 999;
}
.modal-backdrop.open{
  display: flex;
}

.modal-card{
  width: min(760px, 94vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  border-radius: 16px;
  border: 1px solid rgba(148,163,184,.18);
  background: linear-gradient(180deg, #0a1531 0%, #070f24 100%);
  box-shadow: 0 24px 60px rgba(0,0,0,.55);
}

.modal-head{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(148,163,184,.12);
}

.modal-title{
  font-size: 13px;
  font-weight: 800;
  color: rgba(230,237,243,.92);
  letter-spacing: .2px;
}

.modal-close{
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
  font-size: 18px;
  line-height: 1;
}

.modal-body{
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-grid{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  flex: 1 1 auto;
  min-height: 0;
  grid-template-rows: auto auto auto 1fr;
}

.form-field{
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field.span2{
  grid-column: 1 / span 2;
}

.form-label{
  font-size: 12px;
  color: rgba(166,179,199,.92);
}

.form-grid input,
.form-grid textarea{
  width: 100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid rgba(148,163,184,.18);
  background: rgba(0,0,0,.18);
  color: rgba(230,237,243,.92);
  outline: none;
  font-size: 12px;
}

.form-grid textarea{
  resize: none;
  min-height: 70px;
  padding-right: 14px;
  padding-bottom: 14px;
}

.ta-wrap{
  position: relative;
  min-height: 0;
}

.ta-resizer{
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 16px;
  height: 16px;
  border-radius: 8px;

  background: rgba(148,163,184,.30);
  border: 2px solid rgba(6,9,19,.55);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10);

  cursor: nwse-resize;
  touch-action: none;
  user-select: none;
}

.ta-resizer::after{
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 6px;
  background: repeating-linear-gradient(
    135deg,
    rgba(2,6,23,.00) 0 2px,
    rgba(2,6,23,.35) 2px 3px,
    rgba(2,6,23,.00) 3px 6px
  );
  opacity: .9;
}

.ta-resizer:hover{
  background: rgba(148,163,184,.45);
  border-color: rgba(148,163,184,.35);
}

.form-field.call-bg{
  min-height: 0;
}
.form-field.call-bg .ta-wrap{
  flex: 1 1 auto;
  min-height: 0;
}
.form-field.call-bg textarea{
  height: 100%;
}

.modal-actions{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid rgba(148,163,184,.12);
}

.modal-actions-right{
  display: inline-flex;
  gap: 10px;
}

.btn-subtle{
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  border: 1px dashed rgba(148,163,184,.22);
  color: rgba(166,179,199,.88);
  opacity: .90;
}
.btn-subtle:hover{
  background: rgba(255,255,255,.06);
  opacity: 1;
}

#btnSettingsRandom{
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#btnSettingsRandom .icon-rotate{
  display: inline-block;
  transform-origin: 50% 50%;
}

#btnSettingsRandom.loading{
  cursor: wait;
}

#btnSettingsRandom.loading:disabled{
  opacity: .90;
}

#btnSettingsRandom.loading .icon-rotate{
  animation: spin 0.9s linear infinite;
}

@keyframes spin{
  to{ transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce){
  #btnSettingsRandom.loading .icon-rotate{ animation: none; }
  .bubble-text-chunk{ animation: none; opacity: 1; }
}

.btn-primary{
  background: linear-gradient(135deg, rgba(109,94,247,.70), rgba(34,211,238,.28));
  border-color: rgba(109,94,247,.28);
}

#btnNew{
  background: linear-gradient(135deg, rgba(148,163,184,.18), rgba(148,163,184,.06));
  border-color: rgba(148,163,184,.24);
}
#btnNew:hover{
  background: linear-gradient(135deg, rgba(148,163,184,.24), rgba(148,163,184,.10));
}

.form-row{
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.form-row > input{
  flex: 1 1 auto;
  min-width: 0;
}

.gender-select{
  flex: 0 0 86px;
  min-width: 86px;
  text-align: center;
  padding-right: 26px;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(230,237,243,.75) 50%),
    linear-gradient(135deg, rgba(230,237,243,.75) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 50%,
    calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}