:root {
  --bg: #f5f5f5;
  --text: #3c3c3c;
  --muted: #6b6b6b;
  --supermuted: #d6d6d6;
  --theme: #158349;
  --mutedtheme: rgba(21, 131, 73, 0.1);
  --white: #ffffff;
  --black: #000000;
  --radius: 12px;
  font-size: 14px;
}

html,
body {
  margin: 0 10px;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0;
  font-family: "Aptos Narrow", "Segoe UI", Calibri, Thonburi, Arial;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.topbar-icon {
  height: 2rem;
  width: 2rem;
}

.header-icon .topbar-icon {
  height: 2.5rem;
  width: 2.5rem;
}

.save-btn {
  display: flex;
  align-items: center;
}

.document-title {
  display: flex;
  align-items: center;
}

.header,
.ribbon,
.ribbon-options,
.formula-bar {
  width: 100%;
}

.header {
  height: 3.5rem;
  display: flex;
  background-color: var(--bg);
  align-items: center;
}

.header-left {
  display: flex;
  gap: 1.5rem;
  margin-right: auto;
}

.header-right {
  display: flex;
  gap: 1.5rem;
}

.help-btn,
.setting-btn {
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--supermuted);
  border-radius: 6px;
  background: var(--white);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.help-btn {
  font-size: 1rem;
}

.setting-btn {
  cursor: not-allowed;
}

.avatar {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--text);
  border-radius: 50%;
  background-color: var(--bg);
  box-sizing: border-box;
}

.ribbon {
  display: flex;
  height: 2rem;
  gap: 1.5rem;
  background-color: var(--bg);
}

#ribbon-home {
  font-weight: 700;
  border-bottom: 2px solid var(--theme);
}

.ribbon-options {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  border-radius: var(--radius);
  background-color: var(--white);
  border: 1px solid var(--white);
  height: 2rem;

  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  padding: 0 0.75rem;
  -webkit-overflow-scrolling: touch;
}

#restart-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.formula-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background-color: var(--bg);
  height: 2rem;
}

#formula-bar-input {
  flex: 1;
}

#formula-bar-input input {
  width: 100%;
  color: #6b7280;
  font-style: italic;
}

.grid {
  overflow-x: auto;
  overflow-y: auto;
  margin: 0 -20px;
}

.row {
  display: flex;
}

.row .row1,
.row>div:first-child {
  background-color: var(--bg);
}

.row .row1 {
  display: flex;
  align-items: center;
  justify-content: center;
}

.row>div:first-child {
  display: flex;
  align-items: center;
  justify-content: right;
}

.row>div:not(:first-child) {
  width: 7rem;
}

.row>div {
  border: 1px solid var(--supermuted);
  background-color: var(--white);
  min-height: 1.5rem;
  height: auto;
  width: 3rem;
  flex-shrink: 0;
}

.row>div:focus {
  outline: 2px solid var(--theme);
  outline-offset: -2px;
}

.selected-primary {
  outline: 2px solid var(--theme);
  outline-offset: -2px;
}

.selected {
  background-color: var(--mutedtheme) !important;
  outline: 1px solid var(--theme);
  outline-offset: -1px;
}

.sheets {
  display: flex;
  align-items: center;
  height: 2rem;
  background-color: var(--bg);
  gap: 1.5rem;
  margin-top: auto;
  border-bottom: 1px solid var(--supermuted);
}

#sheet1 {
  font-weight: 700;
  border-bottom: 2px solid var(--theme);
}

.footer {
  display: flex;
  align-items: center;
  height: 1.5rem;
  font-size: 0.8rem;
  background-color: var(--bg);
  color: var(--text);
}

.footer-left {
  display: flex;
  gap: 16px;
}

.copyrighted,
.footer-link {
  color: var(--muted);
}

.footer-right {
  margin-left: auto;
  display: flex;
  gap: 16px;
}

.footer-link {
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  cursor: pointer;
}

.footer-link:visited,
.footer-link:hover,
.footer-link:focus,
.footer-link:active {
  color: var(--muted);
  text-decoration: none;
}

.help-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.help-dialog-overlay[hidden] {
  display: none;
}

.help-dialog {
  width: min(760px, calc(100vw - 2rem));
  max-height: 80vh;
  background: var(--white);
  border: 1px solid #94a3b8;
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.25);
  overflow: hidden;
}

.help-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #e2e8f0;
  color: #0f172a;
  border-bottom: 1px solid #cbd5e1;
  padding: 0.5rem 0.75rem;
  font-weight: 700;
}

.help-dialog-close {
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid #94a3b8;
  background: var(--white);
  color: #0f172a;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.help-dialog-body {
  padding: 0.85rem 1rem 1rem;
  overflow: auto;
  color: var(--text);
  background: #f8fafc;
}

.help-welcome-link,
.help-welcome-link:visited,
.help-welcome-link:hover,
.help-welcome-link:active {
  color: var(--muted);
  text-decoration: none;
}

.help-cookie-consent {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.85rem;
}

.help-cookie-title {
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.help-cookie-copy {
  color: #475569;
  line-height: 1.4;
}

.help-cookie-copy a,
.help-cookie-copy a:visited,
.help-cookie-copy a:hover,
.help-cookie-copy a:focus,
.help-cookie-copy a:active {
  color: var(--theme);
  text-decoration: underline;
}

.help-cookie-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.help-cookie-btn {
  border: 1px solid #94a3b8;
  border-radius: 6px;
  background: #ffffff;
  color: #0f172a;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
}

.help-cookie-btn-accept {
  background: var(--theme);
  border-color: #12683a;
  color: #ffffff;
}

.help-dialog-welcome {
  border: 1px dashed #94a3b8;
  background: #ffffff;
  color: #475569;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.85rem;
  line-height: 1.45;
}

.help-dialog-support {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 2.25rem;
  margin-bottom: 0.9rem;
}

.help-dialog-support .bmc-btn,
.help-dialog-support .bmc-button {
  transform: scale(0.95);
  transform-origin: center;
}

.help-dialog-support .bmc-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  border: 1px solid #12683a;
  background: #158349;
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
}

.help-dialog-support .bmc-fallback:hover,
.help-dialog-support .bmc-fallback:focus,
.help-dialog-support .bmc-fallback:visited {
  color: #ffffff;
  text-decoration: none;
}

.help-dialog-section {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  padding: 0.75rem;
}

.help-dialog-title {
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.help-dialog-list {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.35rem;
}

.policy-dialog-body {
  max-height: 65vh;
  overflow: auto;
}

.policy-dialog-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

@keyframes gentle-pulse {
  0%, 100% { background-color: rgba(21, 131, 73, 0.05); }
  50% { background-color: rgba(21, 131, 73, 0.12); }
}

.welcome-start-cell {
  animation: gentle-pulse 2s ease-in-out infinite;
}

/* ── Clippy (#REF! character) ── */

.clippy {
  position: fixed;
  bottom: 4rem;
  right: 1.5rem;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}

.clippy-bubble {
  background: var(--white);
  border: 2px solid var(--supermuted);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  max-width: 210px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.clippy-bubble.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.clippy-bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 16px;
  width: 10px;
  height: 10px;
  background: var(--white);
  border-right: 2px solid var(--supermuted);
  border-bottom: 2px solid var(--supermuted);
  transform: rotate(45deg);
}

.clippy-character {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  position: relative;
  animation: clippy-bounce 3s ease-in-out infinite;
  user-select: none;
}

.clippy-eyes {
  display: flex;
  gap: 18px;
  margin-bottom: -5px;
  position: relative;
  z-index: 1;
}

.clippy-eye {
  width: 8px;
  height: 8px;
  background: #0f4425;
  border-radius: 0;
  animation: clippy-blink 4s step-end infinite;
}

@keyframes clippy-blink {
  0%, 92% { height: 8px; }
  94%, 96% { height: 2px; margin-top: 4px; }
  98% { height: 8px; margin-top: 0; }
}

.clippy-label {
  font-family: "Press Start 2P";
  font-size: 1.4rem;
  font-weight: 900;
  color: #158349;
  letter-spacing: 0.05em;
  line-height: 1;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.15);
}

.clippy-mouth {
  width: 16px;
  height: 6px;
  border-bottom: 3px solid #0f4425;
  border-radius: 0 0 6px 6px;
  margin-top: -3px;
}

.clippy-error {
  position: fixed;
  bottom: 4rem;
  right: 1.5rem;
  z-index: 1500;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: #991b1b;
  opacity: 1;
  transition: opacity 0.5s ease;
}

.clippy-error.fade-out {
  opacity: 0;
}

@keyframes clippy-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes clippy-tickle-jump {
  0% { transform: translateY(0); }
  30% { transform: translateY(-10px); }
  60% { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}

