:root {
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --paper: #fffcf7;
  --panel: #ffffff;
  --accent: #b45309;
  --accent-ink: #fff7ed;
  --good: #3f6212;
  --danger: #b91c1c;
  --sel: #fef3c7;
  --sel-line: #d97706;
  --head: #f5f0e8;
  --shadow: 0 18px 50px rgba(68, 46, 18, 0.12);
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --sans: "Manrope", "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #fde7c7 0%, transparent 55%),
    radial-gradient(900px 400px at 110% 0%, #f3e8d6 0%, transparent 50%),
    var(--paper);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.86);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; font-weight: 750; letter-spacing: -0.03em; font-size: 20px;
}
.mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--ink); color: #fff8ee;
  display: grid; place-items: center; font-family: var(--serif); font-weight: 650;
}
.topbar .spacer { flex: 1; }
.ghost, .solid, .iconbtn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 12px;
}
.solid { background: var(--ink); color: #fff8ee; border-color: var(--ink); }
.ghost:hover, .iconbtn:hover { border-color: #d6d3d1; background: #fff; }
.solid:hover { background: #292524; }
.iconbtn { padding: 6px 8px; line-height: 1; }
.iconbtn[aria-pressed="true"] { background: var(--sel); border-color: #fcd34d; }

.drive { display: grid; grid-template-columns: 232px 1fr; gap: 26px; max-width: 1240px; margin: 0 auto; padding: 26px 22px 80px; width: 100%; }
.side { position: sticky; top: 78px; align-self: start; display: flex; flex-direction: column; gap: 18px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-link {
  text-align: left; border: 0; background: transparent; border-radius: 999px;
  padding: 10px 16px; font-size: 14.5px; color: #44403c;
}
.side-link:hover { background: #fff5e8; }
.side-link.active { background: #fde9cd; color: #7c2d12; font-weight: 750; }
.side-foot { border-top: 1px solid var(--line); padding-top: 14px; }
.ghost.block { display: block; text-align: center; cursor: pointer; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 2px 0; }

.drive-head { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.drive-head .search { flex: 1; min-width: 200px; }
.drive-head select { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: white; }
.view-switch { display: flex; gap: 4px; }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 26px; }
.quick-card {
  text-align: left; border: 1px solid var(--line); background: var(--panel);
  border-radius: 14px; padding: 14px 16px; display: grid; gap: 4px;
}
.quick-card:hover { border-color: #d6d3d1; transform: translateY(-1px); }
.quick-card b { font-size: 16px; letter-spacing: -0.02em; }
.quick-mark {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-size: 11px; font-weight: 800; margin-bottom: 4px;
}
.quick-mark.doc { background: #ffedd5; color: #9a3412; }
.quick-mark.sheet { background: #ecfccb; color: #3f6212; }
.quick-note { color: var(--muted); font-size: 13px; }

.drive-title { font-size: 15px; margin: 0 0 12px; color: #57534e; }
.files.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 14px; }
.files.list { display: flex; flex-direction: column; gap: 6px; }

.file-card {
  position: relative; text-decoration: none; border: 1px solid var(--line);
  background: var(--panel); border-radius: 14px; overflow: hidden; display: block;
}
.file-card:hover { border-color: #d6d3d1; box-shadow: 0 8px 24px rgba(68, 46, 18, 0.08); }
.thumb { height: 104px; display: grid; place-items: center; }
.thumb span { font-size: 15px; font-weight: 800; letter-spacing: 0.08em; }
.thumb.doc { background: linear-gradient(#fff7ed, #ffedd5); color: #9a3412; }
.thumb.sheet { background: linear-gradient(#f7fee7, #ecfccb); color: #3f6212; }
.file-body { padding: 10px 12px 12px; }
.file-card .name { font-weight: 700; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.more {
  position: absolute; top: 8px; right: 8px; border: 0; background: rgba(255, 255, 255, 0.86);
  border-radius: 8px; width: 28px; height: 26px; line-height: 1; font-size: 15px; color: #57534e;
}
.more:hover { background: white; }

.files.list .file-card { display: grid; grid-template-columns: 54px 1fr; align-items: center; }
.files.list .thumb { height: 44px; border-radius: 0; }
.files.list .thumb span { font-size: 11px; }
.files.list .file-body { padding: 8px 12px; }
.files.list .more { top: 50%; transform: translateY(-50%); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #fff8ee; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 40; box-shadow: var(--shadow);
}

.home { max-width: 1080px; margin: 0 auto; padding: 42px 22px 80px; width: 100%; }
.hero h1 {
  font-family: var(--serif); font-weight: 650; font-size: clamp(40px, 6vw, 68px);
  letter-spacing: -0.035em; margin: 0 0 10px; line-height: 0.95;
}
.lede { font-size: 18px; color: #44403c; max-width: 640px; margin: 0 0 26px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 34px; }
.card {
  text-align: left; border: 1px solid var(--line); background: var(--panel);
  border-radius: 18px; padding: 18px 18px 16px; box-shadow: var(--shadow);
  min-height: 148px;
}
.card:hover { transform: translateY(-2px); }
.card b { display: block; font-size: 22px; margin: 8px 0 6px; letter-spacing: -0.03em; }
.card span { color: var(--muted); }
.kicker { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); font-weight: 700; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-head h2 { font-size: 18px; margin: 0; }
.files { display: grid; gap: 8px; margin-top: 12px; }
.file {
  display: grid; grid-template-columns: 42px 1fr auto; gap: 12px; align-items: center;
  background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
  text-decoration: none;
}
.file:hover { border-color: #d6d3d1; }
.badge {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  font-size: 12px; font-weight: 800; letter-spacing: 0.04em;
}
.badge.doc { background: #ffedd5; color: #9a3412; }
.badge.sheet { background: #ecfccb; color: #3f6212; }
.file .name { font-weight: 700; }
.file .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.empty { color: var(--muted); padding: 18px 0; }
.row-actions { display: flex; gap: 6px; }

.editor-shell { display: flex; flex-direction: column; height: 100vh; background: #f6f1ea; }
.doc-wrap { flex: 1; overflow: auto; padding: 28px 16px 80px; }
.doc-page {
  max-width: 820px; margin: 0 auto; background: white; min-height: calc(100vh - 150px);
  border: 1px solid var(--line); border-radius: 4px 14px 14px 4px;
  box-shadow: var(--shadow); padding: 64px 72px 90px;
}
.doc-page:focus { outline: none; }
.doc-page h1 { font-family: var(--serif); font-weight: 650; letter-spacing: -0.03em; font-size: 34px; }
.doc-page h2 { font-family: var(--serif); font-weight: 650; font-size: 24px; }
.doc-page p { font-family: var(--serif); font-size: 18.5px; line-height: 1.55; margin: 0 0 0.7em; }
.doc-page ul, .doc-page ol { font-family: var(--serif); font-size: 18px; line-height: 1.5; }
.doc-page blockquote {
  margin: 0.6em 0; padding: 0.2em 0 0.2em 16px; border-left: 3px solid #fdba74; color: #44403c;
}
.doc-page a { color: #9a3412; }
.doc-page hr {
  border: 0; border-top: 2px solid var(--line); margin: 1.4em 0;
}
.doc-page img {
  max-width: 100%; height: auto; border-radius: 8px; display: block;
}
.doc-page table {
  border-collapse: collapse; width: 100%; margin: 0.8em 0;
  font-family: var(--sans); font-size: 15.5px;
}
.doc-page th, .doc-page td {
  border: 1px solid #d6d3d1; padding: 7px 10px; vertical-align: top; min-width: 40px;
}
.doc-page th { background: var(--head); font-weight: 700; text-align: left; }
.doc-page td:focus, .doc-page th:focus { outline: 2px solid var(--sel-line); outline-offset: -2px; }

.table-tools { background: #fffaf2; }
.tools-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.modal .field { display: block; margin: 10px 0; font-size: 13px; color: #44403c; }
.modal .field input { display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
.modal .check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 14px; }
.modal .check input { width: 16px; height: 16px; }
.grid-pick { display: flex; gap: 10px; }
.grid-pick label { flex: 1; font-size: 13px; color: #44403c; }
.grid-pick input { display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
.title-input {
  border: 0; background: transparent; font-weight: 750; font-size: 16px; letter-spacing: -0.02em;
  min-width: 180px; max-width: 420px; padding: 6px 8px; border-radius: 8px;
}
.title-input:hover, .title-input:focus { background: white; outline: none; }

.toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--line); background: #fffdf9; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.status { margin-left: auto; color: var(--muted); font-size: 13px; }
.peers { display: flex; gap: 6px; align-items: center; }
.peer {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--peer, #b45309); color: white; font-size: 12px; font-weight: 800;
  border: 2px solid white; box-shadow: 0 0 0 1px color-mix(in srgb, var(--peer, #b45309) 50%, white);
}
.peer.me { cursor: pointer; }
.remote-caret {
  position: absolute; width: 2px; background: var(--peer, #b45309); pointer-events: none; z-index: 15;
}
.remote-label {
  position: absolute; left: 0; top: -16px; background: var(--peer, #b45309); color: white;
  font-size: 11px; line-height: 16px; padding: 0 5px; border-radius: 6px; white-space: nowrap;
  font-family: var(--sans);
}

.sheet-shell { height: 100vh; display: grid; grid-template-rows: auto auto auto auto 1fr auto auto; background: #f3eee6; }
.formula-bar { display: grid; grid-template-columns: 92px 28px 1fr auto; gap: 8px; align-items: center; padding: 8px 12px; background: white; border-bottom: 1px solid var(--line); }
.addr {
  font-family: var(--mono); font-size: 13px; background: var(--head); border-radius: 8px; padding: 7px 8px; text-align: center;
}
.fx { font-family: var(--serif); font-style: italic; color: var(--muted); }
#formulaInput {
  border: 1px solid transparent; border-radius: 8px; padding: 7px 8px; background: #fff; width: 100%;
  font-family: var(--mono); font-size: 13.5px;
}
#formulaInput:focus { outline: none; border-color: #fdba74; }

.grid-scroll { overflow: auto; position: relative; background:
  linear-gradient(#f3eee6, #f3eee6); }
.grid { border-collapse: separate; border-spacing: 0; min-width: 100%; background: white; }
.grid th, .grid td {
  border-right: 1px solid #efeae3; border-bottom: 1px solid #efeae3;
  height: 28px; padding: 0; position: relative; background: white;
}
.grid th {
  position: sticky; background: var(--head); font-weight: 650; font-size: 12px; color: #57534e;
  z-index: 2; text-align: center; user-select: none;
}
.grid thead th { top: 0; z-index: 3; height: 28px; }
.grid th.corner { left: 0; z-index: 4; width: 48px; min-width: 48px; }
.grid tbody th { left: 0; z-index: 2; width: 48px; min-width: 48px; }
.grid td.sel { box-shadow: inset 0 0 0 1.5px var(--sel-line); background: #fffbeb; }
.grid td.fill { background: #fef3c7; }
.grid td .v {
  display: block; padding: 3px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 13.5px; line-height: 20px; min-height: 26px; font-variant-numeric: tabular-nums;
}
.grid td.num .v { text-align: right; font-family: var(--mono); font-size: 12.5px; }
.grid td.err .v { color: var(--danger); }
.grid td.bold .v { font-weight: 750; }
.grid td.center .v { text-align: center; }
.cell-editor {
  position: absolute; inset: 0; border: 0; padding: 3px 6px; font: inherit; font-size: 13.5px;
  background: white; width: 100%; height: 100%; z-index: 5;
}
.cell-editor:focus { outline: 2px solid var(--sel-line); }

.sheet-tabs { display: flex; gap: 4px; align-items: center; padding: 6px 10px; background: #fffdf9; border-top: 1px solid var(--line); overflow-x: auto; }
.tab {
  border: 1px solid transparent; background: transparent; border-radius: 8px 8px 0 0; padding: 6px 10px; color: #57534e;
}
.tab.active { background: white; border-color: var(--line); color: var(--ink); font-weight: 700; }
.help-drawer, .modal-back {
  position: fixed; inset: 0; background: rgba(28, 25, 23, 0.28); z-index: 30;
  display: flex; justify-content: flex-end;
}
.drawer {
  width: min(460px, 100%); background: var(--paper); height: 100%; overflow: auto; padding: 18px 18px 40px;
  box-shadow: var(--shadow);
}
.fn { border-bottom: 1px solid var(--line); padding: 10px 0; }
.fn b { font-family: var(--mono); font-size: 13px; }
.fn .also { color: var(--muted); font-size: 12px; margin-left: 6px; }
.fn p { margin: 4px 0; color: #44403c; }
.fn code { font-family: var(--mono); font-size: 12px; background: white; padding: 2px 5px; border-radius: 6px; }
.group-title { margin: 16px 0 0; font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.search {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: white;
}

.modal-back { align-items: center; justify-content: center; }
.modal {
  width: min(440px, calc(100% - 28px)); background: white; border-radius: 16px; padding: 18px;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 8px; }
.modal p { color: #44403c; margin-top: 0; }
.modal input[type="password"], .modal input[type="text"] {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px;
}
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.hidden { display: none !important; }
.menu {
  position: fixed; z-index: 25; background: white; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); min-width: 210px; padding: 6px;
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 8px; padding: 8px 10px; }
.menu button:hover { background: #fff7ed; }
.warn { color: var(--danger); font-size: 13px; }

@media (max-width: 860px) {
  .drive { grid-template-columns: 1fr; gap: 16px; }
  .side { position: static; }
  .side-nav { flex-direction: row; overflow-x: auto; }
  .quick { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .cards { grid-template-columns: 1fr; }
  .doc-page { padding: 28px 18px 60px; }
  .title-input { max-width: 46vw; }
  .status { display: none; }
}
