:root {
  --sheets-header: 62px;
  --sheets-rail: 238px;
  --sheets-inspector: 292px;
  --sheets-surface: color-mix(in srgb, var(--surface) 76%, transparent);
  --sheets-panel: color-mix(in srgb, var(--surface2) 72%, transparent);
  --sheets-line: color-mix(in srgb, var(--line) 72%, transparent);
  --sheets-accent: #72d9a7;
  --sheets-grid-line: color-mix(in srgb, var(--ink) 11%, transparent);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { background: var(--bg); color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }
body {
  min-height: 100svh;
  display: grid;
  grid-template-rows: var(--sheets-header) auto minmax(0, 1fr);
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 14%, rgba(var(--accent-rgb), .1), transparent 34%),
    radial-gradient(circle at 86% 84%, rgba(114, 217, 167, .07), transparent 38%),
    var(--bg);
  color: var(--ink);
  font-family: "DM Sans", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button, summary, select, label { -webkit-tap-highlight-color: transparent; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sheets-header {
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--sheets-line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px);
}
.sheets-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}
.sheets-brand img { width: 38px; height: 38px; }
.sheets-brand span { display: grid; line-height: 1; }
.sheets-brand b { font: 700 11px/1 var(--sans); letter-spacing: .08em; }
.sheets-brand small {
  margin-top: 4px;
  color: var(--muted);
  font: 7px/1 var(--mono);
  letter-spacing: .16em;
}
.sheets-title-block {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}
.workbook-title {
  width: min(360px, 38vw);
  min-width: 0;
  height: 34px;
  padding: 4px 9px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: 500 13px var(--sans);
  text-align: center;
}
.workbook-title:focus {
  border-color: var(--accent);
  outline: none;
  background: var(--sheets-panel);
}
.save-state { color: var(--muted); font: 7px var(--mono); white-space: nowrap; }
.sheets-header-actions { display: flex; align-items: center; gap: 6px; }
.mirror-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font: 7px var(--mono);
}
.mirror-label select {
  min-height: 34px;
  max-width: 145px;
  padding: 5px 8px;
  border: 1px solid var(--sheets-line);
  border-radius: 9px;
  background: var(--sheets-panel);
  color: var(--ink);
  font: 8px var(--mono);
}
.header-icon,
.export-button,
.add-sheet-button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--sheets-line);
  border-radius: 9px;
  background: var(--sheets-panel);
  color: var(--ink);
  font: 8px var(--mono);
  cursor: pointer;
}
.header-icon { width: 34px; padding: 0; font-size: 15px; }
.add-sheet-button {
  border-color: color-mix(in srgb, var(--sheets-accent) 42%, var(--sheets-line));
  background: color-mix(in srgb, var(--sheets-accent) 86%, #fff);
  color: #07110f;
  font-weight: 700;
}
.header-icon:is(:hover, :focus-visible),
.export-button:is(:hover, :focus-visible),
.add-sheet-button:is(:hover, :focus-visible) {
  border-color: var(--accent);
  outline: none;
}

.sheets-ribbon {
  min-width: 0;
  display: block;
  border-bottom: 1px solid var(--sheets-line);
  background: color-mix(in srgb, var(--surface) 92%, #20241f);
}

body[data-sheet-skin="excel"] .sheets-ribbon {
  background: color-mix(in srgb, var(--surface) 91%, #173f2f);
}

body[data-sheet-skin="numbers"] .sheets-ribbon {
  background: color-mix(in srgb, var(--surface) 90%, #3b352c);
}

body[data-sheet-skin="libreoffice"] .sheets-ribbon {
  background: color-mix(in srgb, var(--surface) 92%, #3b4038);
}

body[data-sheet-skin="nyarindo"] .sheets-ribbon {
  background:
    radial-gradient(circle at 88% 0, color-mix(in srgb, #72d9a7 12%, transparent), transparent 28%),
    color-mix(in srgb, var(--surface) 88%, transparent);
}

.sheets-ribbon-tabs {
  min-width: 0;
  min-height: 31px;
  display: flex;
  align-items: end;
  gap: 1px;
  padding: 0 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--sheets-line);
  background: color-mix(in srgb, var(--surface2) 92%, #1e211d);
  scrollbar-width: none;
}

.sheets-ribbon-tabs::-webkit-scrollbar {
  display: none;
}

.sheets-ribbon-tabs button {
  min-width: max-content;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 5px 5px 0 0;
  background: transparent;
  color: color-mix(in srgb, var(--ink) 78%, transparent);
  font: 8px var(--mono);
  cursor: pointer;
}

.sheets-ribbon-tabs button:is(:hover, :focus-visible) {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  outline: none;
}

.sheets-ribbon-tabs button[aria-selected="true"] {
  border-bottom-color: var(--sheets-accent);
  background: color-mix(in srgb, var(--surface) 92%, #20241f);
  color: var(--ink);
}

.sheets-ribbon-panels {
  min-height: 82px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.sheets-ribbon-panel {
  min-width: max-content;
  min-height: 82px;
  display: none;
  align-items: stretch;
  padding: 6px 9px 4px;
}

.sheets-ribbon-panel.is-active {
  display: flex;
}

.sheet-ribbon-group {
  min-width: max-content;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 3px;
  padding: 2px 10px 3px;
  border-right: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
}

.sheet-ribbon-group:last-child {
  border-right: 0;
}

.sheet-ribbon-group > small {
  color: color-mix(in srgb, var(--ink) 52%, transparent);
  font: 7px var(--mono);
  text-align: center;
}

.sheet-ribbon-command-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 3px;
}

.sheets-ribbon :is(button, .sheet-ribbon-colour) {
  min-width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  font: 9px var(--mono);
  cursor: pointer;
}

.sheets-ribbon :is(button, .sheet-ribbon-colour):is(:hover, :focus-visible) {
  border-color: color-mix(in srgb, var(--sheets-accent) 42%, var(--sheets-line));
  background: color-mix(in srgb, var(--sheets-accent) 10%, transparent);
  outline: none;
}

.sheet-ribbon-colour {
  position: relative;
}

.sheet-ribbon-colour input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.sheets-ribbon .sheet-ribbon-large {
  width: 62px;
  height: 54px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  padding: 4px;
  text-align: center;
}

.sheets-ribbon .sheet-ribbon-large b {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  font: 700 18px/1 var(--sans);
}

.sheets-ribbon .sheet-ribbon-large span {
  font: 7px/1.1 var(--mono);
}

body[data-sheet-skin="numbers"] .sheets-ribbon-tabs {
  padding-inline: 14px;
}

body[data-sheet-skin="numbers"] .sheets-ribbon-tabs button {
  border-radius: 999px;
  border-bottom: 0;
}

body[data-sheet-skin="numbers"] .sheets-ribbon-tabs button[aria-selected="true"] {
  background: color-mix(in srgb, var(--sheets-accent) 17%, transparent);
}

body[data-sheet-skin="libreoffice"] .sheets-ribbon-panels,
body[data-sheet-skin="libreoffice"] .sheets-ribbon-panel {
  min-height: 76px;
}

.sheets-workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sheets-rail) minmax(320px, 1fr) var(--sheets-inspector);
  gap: 9px;
  padding: 9px;
  overflow: hidden;
}
.sheets-rail,
.sheets-inspector,
.sheets-stage-shell {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--sheets-line);
  border-radius: 18px;
  background: var(--sheets-surface);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .14), inset 0 1px rgba(255, 255, 255, .045);
}
.sheets-rail { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.rail-head,
.workbook-row,
.rail-actions { padding: 10px; }
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--sheets-line);
}
.rail-head > div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font: 7px var(--mono);
}
.rail-head strong {
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
}
.rail-head button,
.workbook-row button,
.rail-actions button {
  border: 1px solid var(--sheets-line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.rail-head button { width: 28px; height: 28px; }
.workbook-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px 30px;
  gap: 5px;
  border-bottom: 1px solid var(--sheets-line);
}
.workbook-row select {
  min-width: 0;
  height: 31px;
  padding: 4px 7px;
  border: 1px solid var(--sheets-line);
  border-radius: 8px;
  background: var(--sheets-panel);
  color: var(--ink);
  font: 8px var(--mono);
}
.sheet-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 7px;
  padding: 9px;
  overflow: auto;
  scrollbar-width: thin;
}
.sheet-thumb {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--sheets-line);
  border-radius: 11px;
  background: var(--sheets-panel);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.sheet-thumb.is-active {
  border-color: var(--sheets-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sheets-accent) 10%, transparent);
}
.sheet-thumb b {
  color: var(--sheets-accent);
  font: 9px var(--mono);
  text-align: center;
}
.sheet-thumb span { display: grid; gap: 4px; min-width: 0; }
.sheet-thumb strong {
  overflow: hidden;
  font: 500 11px/1.25 var(--sans);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-thumb small {
  color: var(--muted);
  font: 8px var(--mono);
}
.rail-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  border-top: 1px solid var(--sheets-line);
}
.rail-actions button { min-height: 32px; }

.sheets-stage-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 9px;
}
.formula-panel {
  min-width: 0;
  display: grid;
  grid-template-columns: 58px 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
}
.active-cell-name {
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--sheets-line);
  border-radius: 9px;
  background: var(--sheets-panel);
  color: var(--sheets-accent);
  font: 700 9px var(--mono);
}
.formula-mark {
  color: var(--sheets-accent);
  font: italic 15px Georgia, serif;
  text-align: center;
}
#formulaInput {
  min-width: 0;
  height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--sheets-line);
  border-radius: 9px;
  background: var(--sheets-panel);
  color: var(--ink);
  font: 10px/1.3 var(--mono);
  outline: none;
}
#formulaInput:focus {
  border-color: var(--sheets-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sheets-accent) 10%, transparent);
}
#commitFormula {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--sheets-accent) 54%, var(--sheets-line));
  border-radius: 9px;
  background: color-mix(in srgb, var(--sheets-accent) 12%, transparent);
  color: var(--sheets-accent);
  cursor: pointer;
}
.grid-wrap {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--sheets-line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  scrollbar-width: thin;
}
.sheet-grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  min-width: 760px;
  width: max-content;
  color: var(--ink);
}
.sheet-grid th,
.sheet-grid td {
  width: 86px;
  min-width: 86px;
  height: 30px;
  padding: 0;
  border-right: 1px solid var(--sheets-grid-line);
  border-bottom: 1px solid var(--sheets-grid-line);
}
.sheet-grid thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  height: 29px;
  background: color-mix(in srgb, var(--surface2) 94%, transparent);
  color: var(--muted);
  font: 7px var(--mono);
}
.sheet-grid tbody th {
  position: sticky;
  left: 0;
  z-index: 3;
  width: 38px;
  min-width: 38px;
  background: color-mix(in srgb, var(--surface2) 94%, transparent);
  color: var(--muted);
  font: 7px var(--mono);
}
.sheet-grid thead th:first-child {
  left: 0;
  z-index: 5;
  width: 38px;
  min-width: 38px;
}
.sheet-cell {
  width: 100%;
  height: 100%;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 3px 7px;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  appearance: none;
  background: transparent;
  color: inherit;
  font: 9px/1.25 var(--sans);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: cell;
}
.sheet-cell.is-range {
  background: color-mix(in srgb, var(--sheets-accent) 8%, transparent);
}
.sheet-cell.is-active {
  position: relative;
  z-index: 2;
  background: color-mix(in srgb, var(--sheets-accent) 13%, transparent);
  outline: 2px solid var(--sheets-accent);
  outline-offset: -2px;
}
.sheet-cell.has-error { color: #ff8b8b; }
.cell-editor {
  width: 100%;
  height: 28px;
  padding: 2px 6px;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  outline: 2px solid var(--sheets-accent);
  outline-offset: -2px;
  font: 9px var(--sans);
}
.stage-status {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 3px 0;
  color: var(--muted);
  font: 7px var(--mono);
  letter-spacing: .04em;
}
.stage-status > span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-status strong { color: var(--sheets-accent); }
.formula-mobile-card { display: none; }

.sheets-inspector { overflow: auto; scrollbar-width: thin; }
.inspector-module { border-bottom: 1px solid var(--sheets-line); }
.inspector-module > summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
}
.inspector-module > summary::-webkit-details-marker { display: none; }
.inspector-module > summary::before {
  content: "›";
  color: var(--accent);
  transition: transform .18s ease;
}
.inspector-module[open] > summary::before { transform: rotate(90deg); }
.inspector-module > summary span { color: var(--accent); font: 7px var(--mono); }
.inspector-module > summary strong { color: var(--muted); font: 400 9px var(--mono); }
.inspector-body {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}
.inspector-body label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font: 7px var(--mono);
}
.inspector-body input,
.inspector-body select {
  width: 100%;
  min-height: 34px;
  padding: 7px 8px;
  border: 1px solid var(--sheets-line);
  border-radius: 8px;
  background: var(--sheets-panel);
  color: var(--ink);
  font-size: 10px;
}
.format-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
}
.format-grid button {
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--sheets-line);
  border-radius: 8px;
  background: var(--sheets-panel);
  color: var(--ink);
  cursor: pointer;
}
.format-grid button[aria-pressed="true"] {
  border-color: var(--sheets-accent);
  background: color-mix(in srgb, var(--sheets-accent) 14%, var(--sheets-panel));
  color: var(--sheets-accent);
}
.colour-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.colour-row input[type="color"] {
  height: 36px;
  padding: 3px;
}
.primary-action,
.secondary-action {
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--sheets-line);
  border-radius: 8px;
  background: var(--sheets-panel);
  color: var(--ink);
  font: 8px var(--mono);
  cursor: pointer;
}
.primary-action {
  border-color: var(--sheets-accent);
  background: var(--sheets-accent);
  color: #07110f;
  font-weight: 700;
}
.secondary-action.is-danger { color: #ff9a9a; }
.module-note {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.5;
}
.chart-frame {
  min-height: 190px;
  display: grid;
  place-items: center;
  padding: 8px;
  overflow: hidden;
  border: 1px solid var(--sheets-line);
  border-radius: 11px;
  background:
    linear-gradient(color-mix(in srgb, var(--ink) 6%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--ink) 6%, transparent) 1px, transparent 1px),
    var(--sheets-panel);
  background-size: 24px 24px;
}
.chart-frame p {
  max-width: 210px;
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.5;
  text-align: center;
}
.chart-frame svg {
  display: block;
  width: 100%;
  max-width: 290px;
  height: auto;
  overflow: visible;
}

body[data-sheet-skin="excel"] { --sheets-accent: #21a366; }
body[data-sheet-skin="numbers"] { --sheets-accent: #d6a86a; }
body[data-sheet-skin="libreoffice"] { --sheets-accent: #7dbb61; }
body[data-sheet-skin="nyarindo"] { --sheets-accent: #72d9a7; }

body[data-sheet-skin="excel"] .sheets-header {
  border-bottom-color: color-mix(in srgb, #21a366 46%, var(--sheets-line));
  background:
    linear-gradient(90deg, color-mix(in srgb, #21a366 9%, transparent), transparent 32%),
    color-mix(in srgb, var(--surface) 92%, transparent);
}
body[data-sheet-skin="numbers"] .sheets-header {
  background: color-mix(in srgb, #e8dfcf 8%, var(--surface));
}
body[data-sheet-skin="libreoffice"] .sheets-header {
  border-bottom: 3px solid color-mix(in srgb, #7dbb61 68%, var(--sheets-line));
  background: color-mix(in srgb, var(--surface) 96%, #d8ded4);
}
body[data-sheet-skin="nyarindo"] .sheets-header {
  background:
    radial-gradient(circle at 10% 0, color-mix(in srgb, #72d9a7 14%, transparent), transparent 35%),
    color-mix(in srgb, var(--surface) 88%, transparent);
}

.sheets-workspace[data-mirror="excel"] { --sheets-accent: #21a366; }
.sheets-workspace[data-mirror="excel"] .sheet-cell.is-active {
  outline-width: 2px;
  outline-color: #21a366;
}
.sheets-workspace[data-mirror="excel"] .sheets-rail,
.sheets-workspace[data-mirror="excel"] .sheets-inspector {
  border-radius: 10px;
}

.sheets-workspace[data-mirror="numbers"] { --sheets-accent: #d6a86a; }
.sheets-workspace[data-mirror="numbers"] .sheets-rail,
.sheets-workspace[data-mirror="numbers"] .sheets-stage-shell,
.sheets-workspace[data-mirror="numbers"] .sheets-inspector {
  border-radius: 24px;
  background: color-mix(in srgb, #efe4ce 7%, var(--sheets-surface));
  box-shadow: 0 22px 54px rgba(0, 0, 0, .17);
}
.sheets-workspace[data-mirror="numbers"] .sheet-thumb {
  border-radius: 18px;
  background: color-mix(in srgb, #efe4ce 10%, var(--sheets-panel));
}
.sheets-workspace[data-mirror="numbers"] .sheet-grid {
  background: color-mix(in srgb, #efe4ce 8%, var(--sheets-surface));
}

.sheets-workspace[data-mirror="libreoffice"] { --sheets-accent: #7dbb61; }
.sheets-workspace[data-mirror="libreoffice"] .sheets-rail,
.sheets-workspace[data-mirror="libreoffice"] .sheets-inspector,
.sheets-workspace[data-mirror="libreoffice"] .sheets-stage-shell {
  border-radius: 0;
  box-shadow: none;
}

.sheets-workspace[data-mirror="nyarindo"] { --sheets-accent: #72d9a7; }
.sheets-workspace[data-mirror="nyarindo"] .sheets-rail,
.sheets-workspace[data-mirror="nyarindo"] .sheets-inspector,
.sheets-workspace[data-mirror="nyarindo"] .sheets-stage-shell {
  background:
    radial-gradient(circle at 92% 4%, color-mix(in srgb, #72d9a7 8%, transparent), transparent 30%),
    var(--sheets-surface);
  border-radius: 22px;
}
.sheets-workspace[data-mirror="nyarindo"] .sheet-cell.is-active {
  box-shadow: inset 0 0 18px color-mix(in srgb, #72d9a7 9%, transparent);
}

@media (min-width: 821px) {
  .sheets-workspace[data-mirror="numbers"] {
    grid-template-columns: minmax(0, 1fr) var(--sheets-inspector);
    grid-template-rows: 112px minmax(0, 1fr);
  }
  .sheets-workspace[data-mirror="numbers"] .sheets-rail {
    grid-column: 1 / -1;
    grid-row: 1;
    grid-template-columns: auto 248px minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
  }
  .sheets-workspace[data-mirror="numbers"] .rail-head,
  .sheets-workspace[data-mirror="numbers"] .workbook-row,
  .sheets-workspace[data-mirror="numbers"] .rail-actions {
    border: 0;
    border-right: 1px solid var(--sheets-line);
  }
  .sheets-workspace[data-mirror="numbers"] .rail-head {
    min-width: 88px;
    align-content: center;
  }
  .sheets-workspace[data-mirror="numbers"] .workbook-row {
    align-self: center;
    margin: 11px;
  }
  .sheets-workspace[data-mirror="numbers"] .sheet-list {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .sheets-workspace[data-mirror="numbers"] .sheet-thumb {
    width: 172px;
    min-width: 172px;
    min-height: 70px;
  }
  .sheets-workspace[data-mirror="numbers"] .rail-actions {
    min-width: 118px;
    align-self: stretch;
    align-content: center;
    padding: 10px;
    border-right: 0;
    border-left: 1px solid var(--sheets-line);
  }
  .sheets-workspace[data-mirror="numbers"] .sheets-stage-shell {
    grid-column: 1;
    grid-row: 2;
  }
  .sheets-workspace[data-mirror="numbers"] .sheets-inspector {
    grid-column: 2;
    grid-row: 2;
  }
}

.sheets-toast {
  position: fixed;
  z-index: 1300;
  left: 50%;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 30px));
  padding: 9px 12px;
  border: 1px solid var(--sheets-line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: 8px var(--mono);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity .2s, transform .2s;
}
.sheets-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.sheets-mobile-menu,
.sheets-mobile-context-bar {
  display: none;
}

@media (max-width: 1100px) {
  :root { --sheets-rail: 205px; --sheets-inspector: 245px; }
  .mirror-label { display: none; }
}

@media (max-width: 820px) {
  :root { --sheets-header: 58px; }
  body { grid-template-rows: 58px minmax(0, 1fr); }
  .sheets-ribbon { display: none; }
  .sheets-header {
    grid-template-columns: auto minmax(80px, 1fr) auto;
    gap: 7px;
    padding: 6px 8px;
  }
  .sheets-brand span,
  .save-state,
  .sheets-header .export-button,
  .sheets-header .add-sheet-button { display: none !important; }
  .workbook-title { width: 100%; font-size: 11px; }
  .sheets-mobile-menu {
    min-height: 0;
    display: grid;
    align-content: start;
    gap: 7px;
    padding: 14px 10px 28px;
    overflow: auto;
  }
  .sheets-mobile-menu > p {
    margin: 3px 5px 8px;
    color: var(--muted);
    font: 7px var(--mono);
    letter-spacing: .12em;
  }
  .sheets-mobile-menu > button {
    min-height: 66px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: 3px 11px;
    padding: 11px 13px;
    border: 1px solid var(--sheets-line);
    border-radius: 13px;
    background:
      radial-gradient(circle at 8% 50%, color-mix(in srgb, var(--sheets-accent) 14%, transparent), transparent 24%),
      var(--sheets-panel);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
  }
  .sheets-mobile-menu > button > span {
    grid-row: 1 / span 2;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--sheets-accent) 54%, transparent);
    border-radius: 50%;
    color: var(--sheets-accent);
    font-size: 13px;
  }
  .sheets-mobile-menu > button strong {
    align-self: end;
    font: 500 12px var(--sans);
  }
  .sheets-mobile-menu > button small {
    align-self: start;
    overflow: hidden;
    color: var(--muted);
    font: 8px/1.3 var(--sans);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .sheets-mobile-context-bar {
    min-height: 42px;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 5px 10px;
    border-bottom: 1px solid var(--sheets-line);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
  }
  .sheets-mobile-context-bar button {
    min-height: 30px;
    padding: 5px 9px;
    border: 1px solid color-mix(in srgb, var(--sheets-accent) 52%, var(--sheets-line));
    border-radius: 999px;
    background: color-mix(in srgb, var(--sheets-accent) 8%, transparent);
    color: var(--sheets-accent);
    font: 8px var(--mono);
  }
  .sheets-mobile-context-bar strong {
    color: var(--ink);
    font: 500 15px var(--serif);
  }
  body[data-mobile-sheets-context] .sheets-mobile-menu { display: none; }
  body[data-mobile-sheets-context] .sheets-mobile-context-bar { display: grid; }
  body[data-mobile-sheets-context] {
    grid-template-rows: 58px 42px minmax(0, 1fr);
  }
  body:not([data-mobile-sheets-context]) .sheets-workspace { display: none; }
  body[data-mobile-sheets-context] .sheets-workspace {
    display: block;
    padding: 8px;
    overflow: auto;
  }
  body[data-mobile-sheets-context] .sheets-rail,
  body[data-mobile-sheets-context] .sheets-stage-shell,
  body[data-mobile-sheets-context] .sheets-inspector {
    display: none;
  }
  body[data-mobile-sheets-context="sheets"] .sheets-rail {
    min-height: calc(100vh - 124px);
    display: grid;
  }
  body[data-mobile-sheets-context="workbook"] .sheets-stage-shell,
  body[data-mobile-sheets-context="formula"] .sheets-stage-shell {
    min-height: calc(100vh - 124px);
    display: grid;
  }
  body[data-mobile-sheets-context="format"] .sheets-inspector,
  body[data-mobile-sheets-context="charts"] .sheets-inspector {
    min-height: calc(100vh - 124px);
    display: block;
  }
  body[data-mobile-sheets-context="format"] .inspector-module:not(:nth-child(1)),
  body[data-mobile-sheets-context="charts"] .inspector-module:not(:nth-child(2)) {
    display: none;
  }
  body[data-mobile-sheets-context="format"] .inspector-module:nth-child(1),
  body[data-mobile-sheets-context="charts"] .inspector-module:nth-child(2) {
    display: block;
  }
  body[data-mobile-sheets-context="workbook"] .sheet-grid {
    min-width: 730px;
  }
  body[data-mobile-sheets-context="formula"] .sheets-stage-shell {
    grid-template-rows: auto auto minmax(0, 1fr);
    padding: 12px;
  }
  body[data-mobile-sheets-context="formula"] .formula-panel {
    grid-template-columns: 60px 36px minmax(0, 1fr) 36px;
  }
  body[data-mobile-sheets-context="formula"] .grid-wrap,
  body[data-mobile-sheets-context="formula"] .stage-status {
    display: none;
  }
  body[data-mobile-sheets-context="formula"] .formula-mobile-card {
    min-height: 170px;
    display: grid;
    align-content: center;
    gap: 10px;
    padding: 22px;
    border: 1px solid var(--sheets-line);
    border-radius: 15px;
    background:
      radial-gradient(circle at 90% 10%, color-mix(in srgb, var(--sheets-accent) 18%, transparent), transparent 34%),
      var(--sheets-panel);
  }
  .formula-mobile-card span {
    color: var(--muted);
    font: 7px var(--mono);
    letter-spacing: .12em;
  }
  .formula-mobile-card b { color: var(--sheets-accent); }
  .formula-mobile-card p {
    max-width: 310px;
    margin: 0;
    font: 400 19px/1.3 var(--serif);
    letter-spacing: -.025em;
  }
  .stage-status > span:nth-child(2) { display: none; }
  .sheet-grid th,
  .sheet-grid td {
    width: 78px;
    min-width: 78px;
  }
}

@media (max-width: 390px) {
  .sheets-mobile-menu { padding-inline: 8px; }
  .format-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
