/* CalcStory 7.3 palette. The shared section is mirrored in the Android enhancement CSS. */
:root {
  color-scheme: light;
  --cs-system-font: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --cs-key-radius: 14px;
  --cs-control-radius: 12px;
  --cs-card-radius: 18px;
  --cs-panel-radius: 24px;
  --cs-glass-filter: blur(18px) saturate(1.35);
  --motion-press: 90ms;
  --motion-fast: 160ms;
  --motion-normal: 220ms;

  --bg-color: #f2f2f7;
  --card-bg: #fff;
  --input-bg: #f8f8fc;
  --surface-sunken: #ececf3;
  --cs-glass-bg: rgb(255 255 255 / 94%);
  --toast-bg: var(--card-bg);
  --overlay-scrim: rgb(0 0 0 / 28%);
  --overlay-scrim-strong: rgb(0 0 0 / 50%);
  --overlay-scrim-max: rgb(0 0 0 / 64%);

  --text: #17171c;
  --text-strong: #101014;
  --text-secondary: #3d3d48;
  --timestamp: #555562;
  --text-muted: var(--timestamp);
  --text-disabled: #5f5f6d;
  --primary: #005ebb;
  --primary-hover: #004b97;
  --primary-contrast: #fff;
  --focus-ring-dim: var(--primary);
  --danger: #b9253a;
  --danger-hover: #a51d30;
  --cs-success: #16733d;

  --border: #d5d5e0;
  --divider-soft: rgb(0 0 0 / 10%);
  --divider-faint: rgb(0 0 0 / 6%);
  --control-neutral: #e2e2eb;
  --control-neutral-strong: var(--control-neutral);
  --control-disabled-bg: var(--surface-sunken);
  --key-active-bg: #d4d4e1;
  --key-hold-bg: var(--surface-sunken);
  --key-longpress-bg: var(--key-active-bg);
  --cs-connector-bg: #deeafe;
  --cs-connector-pressed: #cadffc;
  --cs-equals-bg: #f6a13a;
  --cs-equals-pressed: #ea8c25;
  --cs-equals-text: #241506;
  --checkbox-bg: var(--input-bg);
  --checkbox-border: #737380;
  --checkbox-bg-checked: var(--primary);
  --checkbox-border-checked: var(--primary);
  --checkbox-tick: var(--primary-contrast);
  --scrollbar-thumb: var(--checkbox-border);
  --scrollbar-track: var(--surface-sunken);

  --shadow-card-color: rgb(0 0 0 / 7%);
  --shadow-modal: 0 12px 32px rgb(0 0 0 / 16%);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg-color: #101014;
    --card-bg: #1c1c22;
    --input-bg: #24242b;
    --surface-sunken: #2b2b34;
    --cs-glass-bg: rgb(28 28 34 / 92%);
    --overlay-scrim: rgb(0 0 0 / 55%);
    --overlay-scrim-strong: rgb(0 0 0 / 72%);
    --overlay-scrim-max: rgb(0 0 0 / 84%);

    --text: #f5f5fa;
    --text-strong: #fff;
    --text-secondary: #d5d5e0;
    --timestamp: #b4b4c3;
    --text-disabled: #a1a1b1;
    --primary: #80baff;
    --primary-hover: #a5cfff;
    --primary-contrast: #101e35;
    --danger: #ff8690;
    --danger-hover: #ffa1a9;
    --cs-success: #63d891;

    --border: #40404d;
    --divider-soft: rgb(255 255 255 / 10%);
    --divider-faint: rgb(255 255 255 / 8%);
    --control-neutral: #3a3a46;
    --control-disabled-bg: #303039;
    --key-active-bg: #454553;
    --cs-connector-bg: #243c5c;
    --cs-connector-pressed: #294466;
    --cs-equals-bg: #ff9f0a;
    --cs-equals-pressed: #e88909;
    --checkbox-border: #8c8c9c;

    --shadow-card-color: rgb(0 0 0 / 28%);
    --shadow-modal: 0 12px 32px rgb(0 0 0 / 42%);
  }
}

body, button, input, textarea, select, #custom-keyboard .op-key {
  font-family: var(--cs-system-font);
}

#expressionInput, #foldedOverlay, #result, .history-entry,
#current-numbers-list, #wide-current-numbers-list, #bookBarCount,
#custom-keyboard .key {
  font-variant-numeric: tabular-nums;
}

.card {
  border-radius: var(--cs-card-radius);
  box-shadow: 0 0 0 1px var(--divider-faint), 0 5px 18px var(--shadow-card-color);
}

#history-container, .portrait-current-panel, .wide-current-panel {
  border-radius: var(--cs-card-radius);
  clip-path: inset(0 round var(--cs-card-radius));
}

button, input[type="text"], #remarkTextarea, .remarks-input,
#appDialogActions button, #bookModalActions button, .book-item-actions button,
#closeSettingsBtn, .settings-legal-links button, .legal-language-select,
.legal-viewer-tab, #usageGuideLanguageSelect, #adjustKeyboardBtn,
#kbAdjustToolbar button, .touch-fx-preview {
  border-radius: var(--cs-control-radius);
}

button:not(.key) { font-weight: 600; }
input[type="range"] { accent-color: var(--primary); }
#expressionInput:focus { box-shadow: inset 0 0 0 1px var(--focus-ring-dim); }

#bookBar {
  border-radius: 0 0 var(--cs-card-radius) var(--cs-card-radius);
  box-shadow: 0 3px 12px var(--shadow-card-color);
}

#bookBarName { color: var(--text-strong); }
#bookBarCount { font-weight: 500; }

#custom-keyboard {
  transition-duration: var(--motion-normal);
}

#custom-keyboard .key {
  --cs-key-fill: var(--surface-sunken);
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  font-weight: 550;
  transition: color var(--motion-press) ease-out;
}

/* The painted keycap can round off without narrowing the button's hit area. */
#custom-keyboard .key::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  border-radius: var(--cs-key-radius);
  background: var(--cs-key-fill);
  box-shadow: inset 0 0 0 1px var(--divider-faint);
  transition: background-color var(--motion-press) ease-out;
}

#custom-keyboard .cs-coach-target { box-shadow: none !important; }
#custom-keyboard .cs-coach-target::before { box-shadow: inset 0 0 0 3px var(--primary); }

@media (hover: hover) and (pointer: fine) {
  #custom-keyboard .key:hover { filter: none; }
  #custom-keyboard .key:not(.cs-coach-target):hover::before {
    box-shadow: inset 0 0 0 1px var(--checkbox-border);
  }
}

#custom-keyboard .op-key {
  --cs-key-fill: var(--control-neutral);
  color: var(--text);
}

#custom-keyboard .op-key.active, #custom-keyboard #custom-equals-key {
  --cs-key-fill: var(--cs-connector-bg);
  color: var(--primary);
}

#custom-keyboard #long-equals-key {
  --cs-key-fill: var(--cs-equals-bg);
  color: var(--cs-equals-text);
  font-weight: 700;
}

#custom-keyboard .key.key-hold-ready,
#custom-keyboard .key.key-long-press {
  background-image: none;
  animation: none;
}

#custom-keyboard .key:is(:active, .key-active, .key-hold-ready, .key-long-press) {
  --cs-key-fill: var(--key-active-bg);
}
#custom-keyboard .op-key.active:is(:active, .key-active, .key-hold-ready, .key-long-press),
#custom-keyboard #custom-equals-key:is(:active, .key-active, .key-hold-ready, .key-long-press) {
  --cs-key-fill: var(--cs-connector-pressed);
}
#custom-keyboard #long-equals-key:is(:active, .key-active, .key-hold-ready, .key-long-press) {
  --cs-key-fill: var(--cs-equals-pressed);
}

/* Keep small hints legible on both the neutral and the highlighted key states. */
#custom-keyboard .key[data-cs-hint]::after {
  color: var(--text-muted);
  opacity: 1;
}
#custom-keyboard #custom-equals-key[data-cs-hint]::after {
  color: var(--primary);
}

:is(#remarkModalContent, #searchModalContent, #editModalContent, #settingsContent,
    #appDialogPanel, #bookModalContent, #usageGuidePanel, #legalConsentPanel,
    #legalViewerPanel, #disclaimerPanel, #csCoach) {
  border-radius: var(--cs-panel-radius);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-modal);
  background: var(--card-bg);
}

#bookModalContent, #appDialogPanel { animation: modal-panel-in var(--motion-fast) ease-out; }
.book-item { border-radius: var(--cs-control-radius); }
.book-item.active { background: var(--cs-connector-bg); }

.legal-toolbar, .usage-guide-toolbar, .legal-actions {
  background: var(--surface-sunken);
}

#csCoach { color: var(--text); }
#csCoach .cs-step, #csCoach .cs-pc, #csCoach .cs-skip {
  color: var(--text-muted);
  opacity: 1;
}
#csCoach button { border-radius: var(--cs-control-radius); }
#csCoach .cs-next { background: var(--primary); color: var(--primary-contrast); }
#csCoach .cs-arrow {
  background: var(--card-bg);
  clip-path: polygon(0 50%, 100% 50%, 50% 100%);
  transform: none;
}
#csTip, #toast {
  border-radius: var(--cs-card-radius);
  color: var(--text-strong);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-modal);
}

#kbAdjustToolbar {
  border-radius: var(--cs-card-radius);
  border-color: var(--border);
  box-shadow: var(--shadow-modal);
}
#kbAdjustOverlay .kb-line::after { background: var(--danger); }
#kbAdjustOverlay .kb-line.active::after { background: var(--primary); }
.touch-fx-setting { border-color: var(--border); }

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :is(#bookBar, #remarkModalContent, #searchModalContent, #editModalContent,
      #settingsContent, #appDialogPanel, #bookModalContent, #usageGuidePanel,
      #legalConsentPanel, #legalViewerPanel, #disclaimerPanel,
      #csCoach, #csTip, #toast, #kbAdjustToolbar) {
    background: var(--cs-glass-bg);
    -webkit-backdrop-filter: var(--cs-glass-filter);
    backdrop-filter: var(--cs-glass-filter);
  }
}

#bottom-bar { background-color: var(--bg-color); }
.store-link {
  border-radius: 999px;
  color: var(--text);
  background: var(--control-neutral);
  border-color: var(--divider-faint);
}

body { transition: filter var(--motion-normal) ease; }

@media (prefers-reduced-transparency: reduce) {
  :root { --cs-glass-bg: var(--card-bg); --cs-glass-filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  :root { --motion-press: 0ms; --motion-fast: 0ms; --motion-normal: 0ms; }
  #custom-keyboard .key:active, .store-link:active { scale: none; }
}

/* Website introduction, visitor counter and install links. */
#seoIntro h1 { color: var(--text-strong); letter-spacing: -0.02em; }
#seoIntro p, #seoIntro ul { color: var(--text-secondary); opacity: 1; }
#seoIntro .cs-demo-tag { color: var(--text-strong); }
#seoIntro .cs-demo-box {
  border-radius: var(--cs-card-radius);
  background: var(--input-bg);
  border-color: var(--border);
}
#seoIntro a, #seoIntro summary { text-underline-offset: 3px; }

#visitorStats { color: var(--text-muted); opacity: 1; }
#visitorStats .vs-dot {
  background: var(--cs-success);
  box-shadow: none;
  animation: none;
}
#visitorStats .vs-info { opacity: 1; }
#visitorStats .vs-info:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.vs-optout { border-radius: var(--cs-control-radius); }

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .store-dock .store-link {
    background: var(--cs-glass-bg);
    -webkit-backdrop-filter: var(--cs-glass-filter);
    backdrop-filter: var(--cs-glass-filter);
  }
}
