:root {
  --bg: #0d1017;
  --panel: #151a22;
  --panel2: #1b222c;
  --line: #263040;
  --fg: #e7edf5;
  --muted: #8d9aab;
  --accent: #6c4bff;
  --accent-soft: #2a2350;
  --ok: #35c98a;
  --warn: #f0a04b;
  --danger: #ff6b6b;
  --radius: 12px;
  --tap: 46px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, "PingFang SC", "Helvetica Neue", system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

/* ---------------- 顶部栏 ---------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + var(--safe-t)) calc(10px + var(--safe-r)) 6px calc(10px + var(--safe-l));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

#topbar .grp {
  display: flex;
  align-items: center;
  gap: 6px;
}

#topbar .grp.center {
  margin: 0 auto;
}

.btn {
  height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  background: var(--panel2);
  border: 1px solid var(--line);
  font-size: 14px;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn.ghost {
  background: transparent;
}

.btn.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #d9d0ff;
}

.icon {
  min-width: 34px;
  height: 34px;
  padding: 0 9px;
  border-radius: 9px;
  background: var(--panel2);
  border: 1px solid var(--line);
  line-height: 1;
}

.title {
  max-width: 26vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.pageinfo {
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ---------------- 主体 ---------------- */

#body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

#tools {
  flex: 0 0 auto;
  width: 62px;
  padding: 8px 6px calc(8px + var(--safe-b)) calc(6px + var(--safe-l));
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.tool {
  height: 52px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid transparent;
}

.tool .g {
  font-size: 19px;
  line-height: 1;
}

.tool.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #ddd6ff;
}

#tools .sep {
  height: 1px;
  background: var(--line);
  margin: 6px 4px;
  flex: 0 0 auto;
}

#tools input[type="color"] {
  width: 100%;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
}

#tools input[type="range"] {
  width: 100%;
  margin: 4px 0;
}

#stage {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(1200px 600px at 50% 0%, #171d27 0%, var(--bg) 70%);
  display: flex;
  align-items: center;
  justify-content: center;
}

#pageWrap {
  position: relative;
  transform-origin: 0 0;
  background: #fff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  border-radius: 4px;
  overflow: hidden;
}

#pageWrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#bg {
  z-index: 1;
}

#ink {
  z-index: 2;
}

#notes {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

#notes > * {
  pointer-events: auto;
}

#selRect {
  position: absolute;
  z-index: 4;
  border: 1.5px dashed var(--accent);
  background: rgba(108, 75, 255, .16);
  border-radius: 4px;
  display: none;
  pointer-events: none;
}

.note-box {
  position: absolute;
  min-width: 60px;
  padding: 14px 8px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .96);
  color: #12161d;
  border: 1px solid rgba(0, 0, 0, .12);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
  font-size: calc(15px * var(--s, 1));
  line-height: 1.35;
}

.note-box .body {
  outline: none;
  min-height: 1.2em;
}

.note-box .bar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 13px;
  border-radius: 8px 8px 0 0;
  background: repeating-linear-gradient(90deg, rgba(0, 0, 0, .18) 0 2px, transparent 2px 6px);
  background-size: 26px 4px;
  background-repeat: repeat-x;
  background-position: 6px 5px;
  cursor: grab;
  touch-action: none;
}

.note-box .del {
  position: absolute;
  right: 2px;
  top: 0;
  width: 20px;
  height: 16px;
  line-height: 14px;
  font-size: 15px;
  color: rgba(0, 0, 0, .45);
  background: transparent;
  border: 0;
}

.note-box.sticky {
  background: #ffe89a;
  border-color: #e6cd6a;
  min-width: 120px;
  min-height: 90px;
}

.note-box .rst {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  opacity: .7;
  touch-action: none;
  cursor: nwse-resize;
}

.note-box.sel {
  outline: 2px solid var(--accent);
}

#hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(21, 26, 34, .92);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s;
  max-width: 80vw;
  text-align: center;
}

#hint.show {
  opacity: 1;
}

/* ---------------- 侧栏面板 ---------------- */

#panel {
  flex: 0 0 auto;
  width: 390px;
  max-width: 46vw;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transform: translateX(100%);
  margin-right: calc(-390px - 2px);
  transition: transform .22s ease, margin-right .22s ease;
}

#panel.open {
  transform: none;
  margin-right: 0;
}

#panel .tabs {
  display: flex;
  gap: 4px;
  padding: 8px calc(8px + var(--safe-r)) 8px 8px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

#panel .tab {
  flex: 1 1 0;
  height: 34px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--muted);
}

#panel .tab.active {
  background: var(--panel2);
  color: var(--fg);
}

.tabpane {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) 12px;
  -webkit-overflow-scrolling: touch;
}

.tabpane.active {
  display: block;
}

.field {
  display: block;
  margin-bottom: 10px;
}

.field > span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  background: var(--panel2);
  border: 1px solid var(--line);
  outline: none;
  resize: vertical;
}

textarea {
  min-height: 74px;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row > * {
  flex: 1 1 auto;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.chip {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel2);
  font-size: 13px;
  color: var(--muted);
}

.chip:active {
  background: var(--accent-soft);
  color: #ddd6ff;
}

.card {
  border: 1px solid var(--line);
  background: var(--panel2);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}

.card h4 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.card .meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.answer {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14.5px;
}

.answer strong {
  color: #cfc4ff;
}

.outline-item {
  display: flex;
  gap: 8px;
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
  text-align: left;
}

.outline-item:active {
  background: var(--panel2);
}

.outline-item .pg {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.thumb {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  margin-bottom: 6px;
}

.empty {
  color: var(--muted);
  font-size: 13.5px;
  padding: 14px 4px;
  line-height: 1.7;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: -2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------- 底部栏 ---------------- */

#bottombar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px calc(12px + var(--safe-r)) calc(7px + var(--safe-b)) calc(12px + var(--safe-l));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

#recDot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4a5462;
  flex: 0 0 auto;
}

#recDot.live {
  background: var(--danger);
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  50% {
    opacity: .25;
  }
}

#recTime {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  min-width: 52px;
}

#timeline {
  flex: 1 1 auto;
  position: relative;
  height: 30px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

#playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--danger);
  left: 0;
  display: none;
}

.mk {
  position: absolute;
  top: 5px;
  width: 8px;
  height: 20px;
  margin-left: -4px;
  border-radius: 3px;
  background: var(--accent);
  opacity: .85;
}

.mk.seg {
  top: 22px;
  height: 5px;
  background: var(--ok);
  opacity: .7;
}

/* ---------------- 弹层 ---------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 6, 10, .62);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.open {
  display: flex;
}

.sheet {
  width: min(560px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.sheet h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(64px + var(--safe-b));
  transform: translateX(-50%) translateY(10px);
  background: #222b38;
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  max-width: 80vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%);
}

/* 录音回顾卡片 */
#card {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(520px, 88vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
  display: none;
  z-index: 20;
}

#card.open {
  display: block;
}

#card .hdr {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

/* 窄屏（iPad 竖屏）适配 */

@media (max-width: 820px) {
  #panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(92vw, 400px);
    max-width: none;
    margin-right: 0;
    transform: translateX(102%);
    z-index: 30;
    box-shadow: -18px 0 40px rgba(0, 0, 0, .5);
  }

  #panel.open {
    transform: none;
  }

  #tools {
    width: 56px;
  }

  .title {
    display: none;
  }
}
