/*  zest — Apple Liquid Glass · 人文的冷清  */

:root {
  /* Surface */
  --canvas:       #f0ede8;
  --surface:      #fff;

  /* Text */
  --ink:          #1d1d1f;
  --ink2:         #86868b;
  --ink3:         rgba(60, 60, 67, 0.25);

  /* Accent */
  --accent:       #007aff;
  --accent-bg:    rgba(0, 122, 255, 0.08);

  /* Status */
  --green:        #34c759;
  --red:          #ff3b30;

  /* Interactive states */
  --hover:        rgba(0, 0, 0, 0.05);
  --pressed:      rgba(0, 0, 0, 0.03);

  /* Glass */
  --glass-bg:     rgba(255, 255, 255, 0.42);
  --glass-border: rgba(255, 255, 255, 0.55);
  --glass-blur:   blur(40px) saturate(1.8);
  --glass-shine:  inset 0 0.5px 0 rgba(255, 255, 255, 0.7);
  --glass-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.06);

  /* Separators */
  --sep:          rgba(0, 0, 0, 0.06);

  /* Layout */
  --nav-w:        220px;
  --r:            10px;
  --r-btn:        7px;
  --gap:          6px;
  --gap-lg:       20px;
  --pad:          14px;

  /* Typography */
  --font:         -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  --fs:           13px;
  --fs-sm:        11px;
  --fs-lg:        15px;
  --fs-editor:    16px;

  /* Motion */
  --speed:        0.15s;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs);
  -webkit-font-smoothing: antialiased;
}

/* ── Shell ────────────────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ── Glass ────────────────────────────────────────────────────────────── */

.nav,
.ime {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shine), var(--glass-shadow);
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */

.nav {
  display: flex;
  flex-direction: column;
  border-right: 0.5px solid var(--glass-border);
  padding: var(--pad);
  padding-bottom: max(var(--pad), env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

.nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--gap-lg);
}

.logo {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.nav-status {
  display: flex;
  align-items: center;
  gap: var(--gap);
  font-size: var(--fs-sm);
  color: var(--ink2);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink3);
  transition: background var(--speed);
}
.dot.ok  { background: var(--green); }
.dot.err { background: var(--red); }

.nav-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--gap-lg);
}

.nav-switches {
  display: flex;
  gap: var(--gap);
}

.nav-foot {
  padding-top: var(--pad);
  border-top: 0.5px solid var(--sep);
  margin-top: var(--pad);
}

.nav-hint {
  font-size: var(--fs-sm);
  color: var(--ink3);
  line-height: 1.8;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */

.sw {
  height: 28px;
  padding: 0 10px;
  border: none;
  border-radius: var(--r-btn);
  background: var(--pressed);
  font-family: var(--font);
  font-size: var(--fs);
  font-weight: 500;
  color: var(--ink2);
  cursor: default;
  transition: background var(--speed), color var(--speed);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.sw:hover { background: var(--hover); }

.sw.sw--on {
  color: var(--accent);
  background: var(--accent-bg);
}

.sw--sm {
  height: 22px;
  padding: 0 8px;
  font-size: var(--fs-sm);
}

/* ── Main area ───────────────────────────────────────────────────────── */

.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--r) 0 0 var(--r);
}

/* ── Loading ─────────────────────────────────────────────────────────── */

.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: var(--fs);
  color: var(--ink2);
  pointer-events: none;
  transition: opacity 0.3s;
}

.loading.done {
  opacity: 0;
}

/* ── Editor ──────────────────────────────────────────────────────────── */

.editor-wrap {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  justify-content: center;
  padding: 48px 18px 100px;
  position: relative;
}

#ed {
  width: 100%;
  max-width: 680px;
}

lexxy-editor {
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  font-size: var(--fs-editor);
  line-height: 1.9;
  color: var(--ink);
}

#ed:not(.toolbar-visible) lexxy-toolbar { display: none !important; }

lexxy-editor [contenteditable] {
  outline: none;
  caret-color: var(--accent);
}

/* ── Bottom bar ──────────────────────────────────────────────────────── */

.botbar {
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  border-top: 0.5px solid var(--sep);
  flex-shrink: 0;
  gap: var(--gap);
}

.botbar-spacer { flex: 1; }

.botbar-wc {
  font-size: var(--fs-sm);
  color: var(--ink3);
  font-variant-numeric: tabular-nums;
}

/* ── IME popup ───────────────────────────────────────────────────────── */

.ime {
  position: fixed;
  z-index: 9999;
  border: 0.5px solid var(--glass-border);
  border-radius: var(--r);
  padding: 5px 0;
  min-width: 200px;
  max-width: 360px;
}

.ime[hidden] { display: none; }

.ime-pre {
  padding: var(--gap) var(--pad);
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.03em;
  border-bottom: 0.5px solid var(--sep);
}
.ime-pre:empty { display: none; }

.ime-cands {
  list-style: none;
  padding: 4px 5px;
}

.ime-c {
  display: flex;
  align-items: baseline;
  gap: var(--gap);
  padding: 4px 9px;
  border-radius: var(--r-btn);
  cursor: default;
  transition: background var(--speed);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

@media (pointer: coarse) {
  .ime-c { padding: var(--gap) 9px; min-height: 44px; }
}

.ime-c:hover { background: var(--hover); }

.ime-c.hl {
  background: var(--accent);
  color: var(--surface);
}
.ime-c.hl:hover { background: var(--accent); }

.ime-n {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink3);
  min-width: 12px;
  font-variant-numeric: tabular-nums;
}
.ime-c.hl .ime-n { color: rgba(255, 255, 255, 0.5); }

.ime-t { font-size: var(--fs-lg); }
.ime-c.hl .ime-t { color: var(--surface); }

.ime-m {
  font-size: var(--fs-sm);
  color: var(--ink2);
  margin-left: auto;
}
.ime-c.hl .ime-m { color: rgba(255, 255, 255, 0.45); }

.ime-pg {
  padding: 3px var(--pad);
  font-size: var(--fs-sm);
  color: var(--ink3);
  text-align: right;
}
.ime-pg[hidden] { display: none; }

/* ── Settings panel ──────────────────────────────────────────────────── */

.nav-settings-btn {
  width: 100%;
  font-size: var(--fs-sm);
}

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--speed);
}

.settings-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.06);
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  transform: scale(0.97);
  transition: transform var(--speed);
}

.settings-overlay.open .settings-panel {
  transform: scale(1);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 0.5px solid var(--sep);
}

.settings-title {
  font-size: var(--fs);
  font-weight: 600;
}

.settings-close {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--r-btn);
  background: var(--pressed);
  font-size: var(--fs-lg);
  color: var(--ink2);
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--speed);
  -webkit-tap-highlight-color: transparent;
}

.settings-close:hover { background: var(--hover); }

.settings-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: var(--gap-lg);
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.settings-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink3);
}

.settings-select {
  width: 100%;
  height: 32px;
  padding: 0 28px 0 10px;
  border: none;
  border-radius: var(--r-btn);
  background: var(--pressed);
  font-family: var(--font);
  font-size: var(--fs);
  color: var(--ink);
  cursor: default;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2386868b'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: background var(--speed);
}

.settings-select:hover { background: var(--hover); }
.settings-select:focus { outline: none; background: var(--accent-bg); }

.settings-toggle {
  height: 32px;
  padding: 0 14px;
  border: none;
  border-radius: var(--r-btn);
  background: var(--pressed);
  font-family: var(--font);
  font-size: var(--fs);
  font-weight: 500;
  color: var(--ink2);
  cursor: default;
  transition: background var(--speed), color var(--speed);
  -webkit-tap-highlight-color: transparent;
}

.settings-toggle:hover { background: var(--hover); }
.settings-toggle.sw--on { color: var(--accent); background: var(--accent-bg); }

.settings-row {
  display: flex;
  gap: var(--gap);
}

.settings-row .sw {
  flex: 1;
  height: 32px;
}

.settings-debug {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 10px;
  line-height: 1.5;
  color: var(--ink2);
  background: var(--pressed);
  border-radius: var(--r-btn);
  padding: 8px 10px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre;
  margin: 0;
  -webkit-overflow-scrolling: touch;
}

.settings-footer {
  padding: 12px 18px 16px;
  border-top: 0.5px solid var(--sep);
}

.settings-footer .nav-hint {
  font-size: var(--fs-sm);
  color: var(--ink3);
  line-height: 1.8;
}

/* ── Mobile ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .nav { display: none; }
  .main { border-radius: 0; }
  .editor-wrap {
    padding: 24px 16px 80px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .botbar {
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }
  lexxy-editor { font-size: var(--fs-editor); }
  .ime {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    max-width: none;
    width: auto;
  }
}
