:root {
  --bg0: #160c22;
  --bg1: #2a1544;
  --purple: #7b3fb0;
  --purple-2: #c084fc;
  --glass: rgba(255, 255, 255, 0.1);
  --glass-2: rgba(255, 255, 255, 0.16);
  --stroke: rgba(255, 255, 255, 0.22);
  --text: #f6f0ff;
  --muted: rgba(246, 240, 255, 0.68);
  --paper: #fbfaf7;
  --ink: #1c1430;
  --shadow: 0 18px 50px rgba(10, 4, 18, 0.45);
  --radius: 18px;
  --font-ui: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --font-doc: "Georgia", "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(168, 85, 247, 0.35), transparent 55%),
    radial-gradient(700px 400px at 90% 10%, rgba(236, 72, 153, 0.18), transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 55%, #12091c);
  overflow: hidden;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(22, 12, 34, 0.45);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--stroke);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand img { width: 28px; height: 28px; }

.title-wrap {
  flex: 1;
  min-width: 0;
}
.title-wrap input {
  width: 100%;
  max-width: 520px;
  background: var(--glass);
  border: 1px solid var(--stroke);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
}
.title-wrap input:focus { border-color: var(--purple-2); }

.status {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.win-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.win-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--stroke);
  background: var(--glass);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.win-btn:hover { background: var(--glass-2); }
.win-btn.close:hover { background: rgba(248, 113, 113, 0.35); }

.home {
  width: min(720px, 100%);
  margin: 24px auto;
  background: rgba(28, 16, 46, 0.45);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 28px;
  backdrop-filter: blur(16px);
}
.home h2 { margin: 0 0 8px; }
.home-actions { display: flex; gap: 8px; margin: 16px 0; }

.doc-dock {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 18;
}
.doc-dock button {
  border: 1px solid var(--stroke);
  background: rgba(28, 16, 46, 0.9);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.app.doc-closed .sheet,
.app.doc-min .sheet { display: none; }
.app.doc-closed .title-wrap input { opacity: 0.45; pointer-events: none; }

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

.btn {
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--glass);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(10px);
}
.btn:hover { background: var(--glass-2); }
.btn.primary {
  background: linear-gradient(180deg, #8b4cc4, #6b2d9b);
  border-color: rgba(255,255,255,0.25);
}
.btn.danger { border-color: rgba(248, 113, 113, 0.45); color: #fecaca; }

.workspace {
  position: relative;
  overflow: auto;
  padding: 28px 16px 80px;
}

.sheet {
  width: min(820px, 100%);
  min-height: calc(100vh - 140px);
  margin: 0 auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 72px 80px 96px;
}

.sheet[contenteditable="true"] { outline: none; }
.sheet h1, .sheet h2, .sheet h3 { font-family: var(--font-ui); color: #2a1544; margin: 0 0 12px; }
.sheet h1 { font-size: 28px; }
.sheet h2 { font-size: 20px; }
.sheet p { font-family: var(--font-doc); font-size: 16px; line-height: 1.55; margin: 0 0 12px; }
.sheet ul, .sheet ol { margin: 0 0 12px; padding-left: 1.4em; font-family: var(--font-doc); }
.sheet table { border-collapse: collapse; width: 100%; margin: 0 0 12px; }
.sheet td, .sheet th { border: 1px solid #c9c1d6; padding: 6px 8px; font-family: var(--font-doc); }

.toolbar {
  position: fixed;
  z-index: 20;
  left: 24px;
  top: 92px;
  width: min(300px, calc(100vw - 24px));
  max-height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  background: rgba(28, 16, 46, 0.72);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  padding: 8px;
  user-select: none;
}
.toolbar.hidden { display: none; }

.toolbar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 8px;
  cursor: grab;
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
}
.toolbar-head:active { cursor: grabbing; }

.toolbar-scroll {
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  max-height: min(58vh, 440px);
}
.toolbar-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.toolbar-scroll::-webkit-scrollbar-thumb {
  background: rgba(192, 132, 252, 0.45);
  border-radius: 99px;
}

.tsec { margin-bottom: 8px; }
.tsec h4 {
  margin: 0 0 4px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 0 8px;
}
.tbtn {
  min-width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  padding: 0 8px;
}
.tbtn.wide { flex: 1 1 42%; }
.tbtn:hover, .tbtn.on { background: rgba(192, 132, 252, 0.22); }
.tbtn[disabled] { opacity: 0.35; cursor: default; }
.tbtn.swatch {
  position: relative;
  overflow: hidden;
}
.tbtn.swatch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drawer {
  position: fixed;
  top: 58px;
  right: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - 80px);
  overflow: auto;
  background: rgba(28, 16, 46, 0.86);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 30;
}
.drawer.hidden { display: none; }
.drawer h3 { margin: 0 0 10px; font-size: 15px; }
.doc-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
}
.doc-item:hover { background: var(--glass); }
.doc-item small { display: block; color: var(--muted); font-size: 11px; }

.menu {
  position: fixed;
  z-index: 40;
  background: rgba(28, 16, 46, 0.94);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 6px;
  min-width: 180px;
  box-shadow: var(--shadow);
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.menu button:hover { background: var(--glass); }
.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 16, 46, 0.92);
  border: 1px solid var(--stroke);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
}

.show-bar {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 15;
}

@media (max-width: 720px) {
  .sheet { padding: 36px 22px 64px; min-height: 70vh; }
  .status { display: none; }
  .brand span { display: none; }
}
