:root {
  --em-bg: #ffffff;
  --em-surface: #f4f7f4;
  --em-header: #e9efea;
  --em-border: #d4ded5;
  --em-text: #1c2820;
  --em-muted: #55685a;
  --em-brand: #2d5a3f;
  --em-brand-hover: #21442f;
  --em-brand-soft: #e2efe5;
  --em-ref-0: #2563eb;
  --em-ref-1: #16a34a;
  --em-ref-2: #9333ea;
  --em-ref-3: #d97706;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--em-text);
  background: var(--em-bg);
}
body.theme-dark {
  --em-bg: #161a17;
  --em-surface: #1f2521;
  --em-header: #262e28;
  --em-border: #344037;
  --em-text: #edf3ee;
  --em-muted: #9cb0a1;
  --em-brand: #4da36d;
  --em-brand-hover: #5eb57e;
  --em-brand-soft: #22382a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--em-bg); color: var(--em-text); }
.embed-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 240px;
  background: var(--em-bg);
  overflow: hidden;
}
.embed-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--em-surface);
  border-bottom: 1px solid var(--em-border);
  flex-shrink: 0;
}
.embed-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.embed-sheet-icon {
  color: var(--em-brand);
  font-weight: 700;
  font-size: 16px;
}
.embed-topbar h1 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.embed-mode-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--em-brand-soft);
  color: var(--em-brand);
  white-space: nowrap;
}
.embed-top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.embed-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--em-border);
  background: var(--em-bg);
  color: var(--em-text);
  cursor: pointer;
  white-space: nowrap;
}
.embed-btn:hover { border-color: var(--em-brand); }
.embed-btn-play {
  background: var(--em-brand);
  color: #ffffff;
  border-color: var(--em-brand);
}
body.theme-dark .embed-btn-play { color: #111612; }
.embed-btn-play:hover { background: var(--em-brand-hover); }

.embed-fx-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--em-border);
  background: var(--em-bg);
  flex-shrink: 0;
}
.embed-cell-ref {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--em-surface);
  border: 1px solid var(--em-border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.embed-fx-symbol {
  font-style: italic;
  font-weight: 700;
  color: var(--em-brand);
  font-size: 13px;
  user-select: none;
}
.embed-fx-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
#embed-fx-input {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--em-border);
  background: var(--em-bg);
  color: var(--em-text);
}
#embed-fx-input:focus {
  outline: 2px solid var(--em-brand);
  outline-offset: 0;
}
.embed-fx-tokens {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.embed-ref-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid currentColor;
}

.embed-player-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--em-surface);
  border-bottom: 1px solid var(--em-border);
  flex-shrink: 0;
}
.embed-player-btn, .embed-speed-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--em-border);
  background: var(--em-bg);
  color: var(--em-text);
  cursor: pointer;
}
.embed-scrubber {
  flex: 1;
  accent-color: var(--em-brand);
  cursor: pointer;
}
.embed-step-counter {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--em-muted);
  min-width: 48px;
  text-align: right;
}
.embed-narration {
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 500;
  background: var(--em-brand-soft);
  color: var(--em-text);
  border-bottom: 1px solid var(--em-border);
  flex-shrink: 0;
}

.embed-stage {
  position: relative;
  flex: 1;
  overflow: auto;
  background: var(--em-bg);
}
.embed-status {
  padding: 24px;
  font-size: 13px;
  color: var(--em-muted);
}
.embed-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.embed-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--em-header);
  color: var(--em-muted);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  padding: 5px 8px;
  border: 1px solid var(--em-border);
  user-select: none;
}
.embed-table th[scope="row"] {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 36px;
  min-width: 36px;
}
.embed-table td {
  border: 1px solid var(--em-border);
  padding: 0;
  min-width: 96px;
  height: 30px;
  position: relative;
  background: var(--em-bg);
}
.embed-cell-input {
  width: 100%;
  height: 100%;
  min-height: 29px;
  border: 0;
  padding: 5px 8px;
  font: inherit;
  font-size: 13px;
  background: transparent;
  color: var(--em-text);
}
.embed-cell-input.is-num { text-align: right; font-variant-numeric: tabular-nums; }
.embed-cell-input.is-bold { font-weight: 700; }
.embed-cell-input.is-formula { color: var(--em-brand); font-weight: 600; }
.embed-cell-input:focus {
  outline: 2px solid var(--em-brand);
  outline-offset: -2px;
  background: var(--em-brand-soft);
}
td.is-selected {
  outline: 2px solid var(--em-brand);
  outline-offset: -2px;
}
td.is-result-pulse {
  background: var(--em-brand-soft);
  transition: background 0.25s ease;
}
td.ref-hl-0 { box-shadow: inset 0 0 0 2px var(--em-ref-0); background: rgba(37, 99, 235, 0.08); }
td.ref-hl-1 { box-shadow: inset 0 0 0 2px var(--em-ref-1); background: rgba(22, 163, 74, 0.08); }
td.ref-hl-2 { box-shadow: inset 0 0 0 2px var(--em-ref-2); background: rgba(147, 51, 234, 0.08); }
td.ref-hl-3 { box-shadow: inset 0 0 0 2px var(--em-ref-3); background: rgba(217, 119, 6, 0.08); }

.embed-cursor {
  position: absolute;
  top: 20px;
  left: 20px;
  pointer-events: none;
  z-index: 10;
  transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}
@media (prefers-reduced-motion: reduce) {
  .embed-cursor { transition: none; }
}

.embed-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  background: var(--em-surface);
  border-top: 1px solid var(--em-border);
  flex-shrink: 0;
  font-size: 12px;
}
.embed-brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  color: var(--em-text);
  min-width: 0;
}
.embed-brand span {
  color: var(--em-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.embed-open-cta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--em-brand);
  color: #ffffff;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
body.theme-dark .embed-open-cta { color: #111612; }
.embed-open-cta:hover { background: var(--em-brand-hover); }

/* Clean Calculator Mode (headers=0 / view=clean — no A,B,C or 1,2,3 grid headers) */
body.mode-clean .embed-stage {
  padding: 12px 14px;
}
body.mode-clean .embed-table {
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--em-border);
  border-radius: 10px;
  overflow: hidden;
}
body.mode-clean .embed-table thead th {
  position: static;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 9px 12px;
  background: var(--em-surface);
  color: var(--em-muted);
  border: 0;
  border-bottom: 1px solid var(--em-border);
}
body.mode-clean .embed-table thead th.is-num-col {
  text-align: right;
}
body.mode-clean .embed-table td {
  border: 0;
  border-bottom: 1px solid var(--em-border);
  height: 38px;
  padding: 4px 8px;
  vertical-align: middle;
}
body.mode-clean .embed-table tbody tr:last-child td {
  border-bottom: 0;
}
body.mode-clean .embed-table tbody tr.is-output-row td {
  background: var(--em-surface);
}
body.mode-clean .embed-cell-input.is-clean-label {
  font-weight: 500;
  color: var(--em-text);
  cursor: default;
  padding: 4px 6px;
}
body.mode-clean .embed-cell-input.is-clean-note {
  font-size: 12px;
  color: var(--em-muted);
  cursor: default;
  padding: 4px 6px;
}
body.mode-clean .embed-cell-input.is-clean-input {
  background: var(--em-bg);
  border: 1.5px solid var(--em-border);
  border-radius: 7px;
  padding: 5px 10px;
  font-weight: 600;
  min-height: 30px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
body.mode-clean.theme-dark .embed-cell-input.is-clean-input {
  background: rgba(255, 255, 255, 0.04);
}
body.mode-clean .embed-cell-input.is-clean-input:hover {
  border-color: var(--em-brand);
}
body.mode-clean .embed-cell-input.is-clean-input:focus {
  outline: none;
  border-color: var(--em-brand);
  box-shadow: 0 0 0 3px var(--em-brand-soft);
  background: var(--em-bg);
}
body.mode-clean .embed-cell-input.is-clean-output {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--em-brand);
  cursor: default;
  padding: 5px 10px;
}
body.mode-clean td.is-selected {
  outline: none;
}

@media (max-width: 520px) {
  .embed-brand span, .embed-mode-pill { display: none; }
  body.mode-clean .embed-stage { padding: 8px; }
}
