:root {
  --bg: #f6f7f9; --paper: #ffffff; --ink: #1d2129; --muted: #69707d; --line: #e3e6ea; --line-strong: #c9ced6;
  --accent: #b91c1c; --accent-ink: #ffffff; --accent-soft: #fde8e8; --hdr: #f1f3f6; --warn: #b4232c; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 2px 8px rgba(16,24,40,.06);
  --radius: 10px; color-scheme: light;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Yu Gothic UI", "Meiryo UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #16181d; --paper: #1f2228; --ink: #e8eaed; --muted: #9aa1ad; --line: #2e323a; --line-strong: #444a55; --accent: #f87171; --accent-ink: #0b1020; --accent-soft: #3b1a1a; --hdr: #262a31; --warn: #ff7a80; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #16181d; --paper: #1f2228; --ink: #e8eaed; --muted: #9aa1ad; --line: #2e323a; --line-strong: #444a55; --accent: #f87171; --accent-ink: #0b1020; --accent-soft: #3b1a1a; --hdr: #262a31; --warn: #ff7a80; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); display: flex; flex-direction: column; font-size: 15px; line-height: 1.6; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); min-height: 52px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .2px; }
.brand img { border-radius: 6px; }
.docname { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.docname b { color: var(--ink); font-weight: 600; }
.actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.btn { border: 1px solid var(--line-strong); background: var(--paper); padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; line-height: 1.4; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .link:focus-visible, .drop:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { padding: 10px 22px; font-size: 15px; border-radius: 10px; }
.btn.icon { padding: 6px 8px; display: inline-flex; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; font-size: 13px; }
.menuwrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(16,24,40,.16); min-width: 240px; padding: 6px; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.menu button small { display: block; color: var(--muted); font-size: 12px; }
.menu button:hover, .menu button:focus-visible { background: var(--accent-soft); outline: none; }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px 40px; position: relative; }
.empty { max-width: 760px; margin: 4vh auto 0; }
.drop { border: 2px dashed var(--line-strong); border-radius: 16px; background: var(--paper); padding: 40px 24px 28px; text-align: center; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop h1 { font-size: 22px; margin: 12px 0 4px; font-weight: 650; }
.drop .sub { color: var(--muted); margin: 0 0 18px; }
.drop .small { margin: 14px 0 0; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.points { list-style: none; padding: 0; margin: 22px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.points li { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; font-size: 13.5px; color: var(--muted); }
.points b { display: block; color: var(--ink); font-size: 14.5px; margin-bottom: 2px; }
@media (max-width: 720px) { .points { grid-template-columns: 1fr; } }

.busy { position: fixed; inset: 0; display: flex; gap: 12px; align-items: center; justify-content: center; background: color-mix(in srgb, var(--bg) 70%, transparent); z-index: 20; font-weight: 600; }
.spin { width: 22px; height: 22px; border: 3px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: s .8s linear infinite; }
@keyframes s { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 30; max-width: min(560px, 92vw); font-size: 14px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 10px; display: flex; gap: 6px; justify-content: center; }
.foot a { color: var(--muted); }

/* document chrome */
.kind { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); margin-right: 8px; vertical-align: 2px; }
.note { background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; margin: 0 0 16px; font-size: 13.5px; color: var(--muted); }
.note.warn { border-left-color: var(--warn); }
.errorcard { max-width: 640px; margin: 8vh auto; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 28px; text-align: center; box-shadow: var(--shadow); }
.errorcard h2 { margin: 0 0 8px; font-size: 19px; }
.errorcard p { color: var(--muted); margin: 0 0 18px; }
h2.sec { font-size: 15px; margin: 28px 0 10px; color: var(--muted); font-weight: 650; text-transform: none; letter-spacing: .2px; }

/* Pages */
.paper { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); max-width: 820px; margin: 0 auto; padding: 56px 64px; }
.paper p { margin: 0 0 .9em; white-space: pre-wrap; overflow-wrap: anywhere; }
.paper p.title { font-size: 1.5em; font-weight: 650; line-height: 1.3; margin-bottom: .8em; }
.paper p.gap { margin: 0 0 .6em; min-height: .4em; }
.wrapw { max-width: 820px; margin: 0 auto; }
.boxes { display: grid; gap: 10px; }
.boxes div { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
details.preview { max-width: 820px; margin: 0 auto 16px; }
details.preview summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
details.preview img { display: block; max-width: 100%; margin-top: 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
@media (max-width: 700px) { .paper { padding: 28px 22px; } }

/* images */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.gallery img { display: block; width: 100%; height: 130px; object-fit: contain; background: repeating-conic-gradient(#0000000d 0 25%, #0000 0 50%) 50% / 16px 16px; cursor: zoom-in; }
.gallery figcaption { font-size: 11.5px; color: var(--muted); padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.82); z-index: 40; display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 24px; }
.lightbox img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 4px; }

/* Numbers */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { border: 0; background: none; padding: 8px 14px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tablecard { margin: 0 0 26px; }
.tablecard h3 { font-size: 15px; margin: 0 0 8px; display: flex; gap: 10px; align-items: baseline; }
.tablecard h3 small { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.tablecard h3 .link { margin-left: auto; }
.scroller { overflow: auto; max-height: 72vh; width: fit-content; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 13.5px; font-variant-numeric: tabular-nums; }
table.grid td, table.grid th { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 10px; white-space: pre-wrap; vertical-align: top; max-width: 420px; overflow-wrap: anywhere; text-align: left; font-weight: 400; }
table.grid td.n { text-align: right; white-space: nowrap; }
table.grid tr.h td, table.grid td.hc { background: var(--hdr); font-weight: 600; }
table.grid tr.h td { position: sticky; top: 0; z-index: 1; }
table.grid th.rn { position: sticky; left: 0; background: var(--hdr); color: var(--muted); font-size: 11.5px; text-align: right; min-width: 36px; z-index: 2; }
table.grid thead th { position: sticky; top: 0; background: var(--hdr); color: var(--muted); font-size: 11.5px; text-align: center; z-index: 3; }
.more { margin: 8px 0 0; }

/* Keynote */
.slides { display: grid; gap: 16px; }
.slide { display: grid; grid-template-columns: minmax(220px, 360px) 1fr; gap: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.slide .thumb { position: relative; }
.slide .thumb img { width: 100%; display: block; border-radius: 6px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; }
.slide .thumb .ph { aspect-ratio: 16/9; border-radius: 6px; border: 1px dashed var(--line-strong); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.slide .num { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.62); color: #fff; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }
.slide h3 { margin: 0 0 6px; font-size: 17px; line-height: 1.35; }
.slide ul { margin: 0; padding-left: 1.2em; }
.slide li { white-space: pre-wrap; overflow-wrap: anywhere; margin: 2px 0; }
.slide .notes { margin-top: 10px; background: var(--hdr); border-radius: 8px; padding: 8px 12px; font-size: 13.5px; white-space: pre-wrap; }
.slide .notes b { display: block; font-size: 12px; color: var(--muted); }
.slide .meta { font-size: 12px; color: var(--muted); margin-top: 8px; }
.slide .gallery { margin-top: 10px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.slide .gallery img { height: 80px; }
.slide.skipped { opacity: .62; }
.slide .tables { margin-top: 10px; }
@media (max-width: 760px) { .slide { grid-template-columns: 1fr; } }

/* print */
@media print {
  .bar, .foot, .tabs .tab:not([aria-selected="true"]), .link, .more, details.preview, .note { display: none !important; }
  body { background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
  .paper { box-shadow: none; border: 0; padding: 0; max-width: none; }
  .slide { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
  .scroller { max-height: none; overflow: visible; border: 0; }
  table.grid tr.h td, table.grid th.rn, table.grid thead th { position: static; }
  .tablecard { break-inside: auto; }
}
/* Pro */
.menu .mi { display: flex; align-items: center; gap: 8px; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
a.btn { display: inline-block; text-decoration: none; color: inherit; }
a.btn.primary { color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); margin-top: 6px; }
.modal-back { position: fixed; inset: 0; background: rgba(10,14,22,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); max-width: 440px; width: 100%; padding: 22px 22px 14px; }
.modal h2 { margin: 0 0 8px; font-size: 19px; }
.modal p { margin: 0 0 10px; line-height: 1.6; font-size: 14px; }
.modal .small { color: var(--muted); font-size: 12.5px; }
.modal .row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-start; margin: 12px 0 8px; }
.pro-msg { color: var(--warn); min-height: 1em; }
.pro-mark { margin-left: 6px; font-weight: 700; color: var(--accent); }
/* shared app pages */
.card { max-width: 760px; margin: 4vh auto 0; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; font-size: 20px; }
.card label { display: flex; gap: 8px; align-items: center; margin: 8px 0; cursor: pointer; }
.card fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; margin: 12px 0; }
.card legend { color: var(--muted); font-size: 13px; padding: 0 6px; }
.stats { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.stats li { background: var(--hdr); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; }
.stats b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: 13px; }
.tag { text-align: center; color: var(--muted); margin-top: 18px; }
.msg { max-width: 760px; margin: 0 auto 12px; background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; }
.busy progress { width: min(420px, 80vw); height: 10px; accent-color: var(--accent); }
.busy { flex-direction: column; }
.drop .row { justify-content: center; gap: 10px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 12px 0; }
.grid figure { margin: 0; background: var(--hdr); border-radius: 8px; overflow: hidden; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; position: relative; }
.grid img { width: 100%; height: 100%; object-fit: cover; }
.grid figcaption { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; background: rgba(0,0,0,.55); color: #fff; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
select { font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); margin-left: 6px; }
