/* Study calculator — Focus-mode design (logic lives in js/calc). */

#hwCalc,
.sc-calc {
  --sc-bg: #fff;
  --sc-ink: #1a2332;
  --sc-mute: #64748b;
  --sc-line: rgba(26, 35, 50, 0.1);
  --sc-line-strong: rgba(26, 35, 50, 0.16);
  --sc-soft: #f1f4f8;
  --sc-accent: #2563eb;
  --sc-accent-dark: #1d4ed8;
  --sc-accent-soft: #e8eefb;
  --sc-danger: #dc2626;
  --sc-danger-soft: #fef2f2;
  --sc-warn: #c2410c;
  --sc-warn-soft: #fff7ed;
  --sc-mod: #a16207;
  --sc-mod-soft: #fffbeb;
  --sc-radius: 14px;
  --sc-ease: cubic-bezier(0.22, 0.8, 0.2, 1);
  --sc-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --sc-display-top: #fbfcfe;
  --sc-display-bot: #f4f6f9;
  --sc-card: #fbfcfe;
  --sc-modal-scrim: rgba(26, 35, 50, 0.28);
  --sc-modal-bg: #fff;
  --sc-history-bg: rgba(255, 255, 255, 0.97);
  --sc-btn-hover: #fafbfd;
  --sc-equals-text: #fff;
}

html[data-focus-theme="dark"] #hwCalc,
html[data-focus-theme="dark"] .sc-calc {
  --sc-bg: #1a222d;
  --sc-ink: #e8eef6;
  --sc-mute: #8b98a8;
  --sc-line: rgba(232, 238, 246, 0.1);
  --sc-line-strong: rgba(232, 238, 246, 0.18);
  --sc-soft: #121820;
  --sc-accent: #5b8def;
  --sc-accent-dark: #8bb0f5;
  --sc-accent-soft: rgba(91, 141, 239, 0.16);
  --sc-danger: #f87171;
  --sc-danger-soft: rgba(248, 113, 113, 0.14);
  --sc-warn: #fb923c;
  --sc-warn-soft: rgba(251, 146, 60, 0.14);
  --sc-mod: #fbbf24;
  --sc-mod-soft: rgba(251, 191, 36, 0.12);
  --sc-display-top: #151b24;
  --sc-display-bot: #121820;
  --sc-card: #151b24;
  --sc-modal-scrim: rgba(0, 0, 0, 0.55);
  --sc-modal-bg: #1a222d;
  --sc-history-bg: rgba(26, 34, 45, 0.98);
  --sc-btn-hover: #222b38;
  --sc-equals-text: #fff;
}

#hwCalc.hidden,
#hwCalc .hidden,
.sc-calc .hidden {
  display: none !important;
}

#hwCalc {
  position: relative;
  display: grid;
  gap: 12px;
  animation: portalPaneIn 460ms var(--ease-out, var(--sc-ease-out)) both;
}

.hw-panel-body:has(#hwCalc),
.hw-workspace-body.is-calc {
  max-height: none;
  min-height: 0;
  mask-image: none;
  overflow: auto;
  scrollbar-width: none;
}

.hw-panel-body:has(#hwCalc)::-webkit-scrollbar,
.hw-workspace-body.is-calc::-webkit-scrollbar {
  display: none;
}

.hw-shell.is-calc-tool {
  min-height: 0;
}

.hw-shell.is-multi-tools {
  min-height: min(70vh, 720px);
}

/* Header */
#hwCalc .sc-header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

#hwCalc .mode-switcher-bar {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--sc-line);
  border-radius: 999px;
  background: var(--sc-soft);
}

#hwCalc .mode-pill-btn {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--sc-mute);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition:
    color 220ms var(--sc-ease),
    background-color 220ms var(--sc-ease),
    transform 200ms var(--sc-ease-out);
}

#hwCalc .mode-pill-btn:hover {
  color: var(--sc-ink);
}

#hwCalc .mode-pill-btn.active {
  color: var(--sc-ink);
  background: var(--sc-bg);
  box-shadow: 0 1px 2px rgba(26, 35, 50, 0.06);
}

#hwCalc .header-tools {
  display: flex;
  gap: 8px;
  align-items: center;
}

#hwCalc .tool-btn,
#hwCalc .btn-small {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--sc-line);
  border-radius: 10px;
  color: var(--sc-ink);
  background: var(--sc-bg);
  font-size: 0.78rem;
  font-weight: 700;
  transition:
    border-color 200ms var(--sc-ease),
    background-color 200ms var(--sc-ease),
    transform 180ms var(--sc-ease-out);
}

#hwCalc .tool-btn:hover,
#hwCalc .btn-small:hover {
  border-color: var(--sc-line-strong);
  background: var(--sc-soft);
}

#hwCalc .tool-btn:active,
#hwCalc .btn-small:active,
#hwCalc .keypad-grid button:active {
  transform: scale(0.97);
}

#hwCalc .memory-badge {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  color: var(--sc-accent-dark);
  background: var(--sc-accent-soft);
  font-size: 0.72rem;
  font-weight: 800;
}

/* Display */
#hwCalc .sc-display {
  padding: 18px 18px 16px;
  border: 1px solid var(--sc-line);
  border-radius: var(--sc-radius);
  background: linear-gradient(180deg, var(--sc-display-top), var(--sc-display-bot));
  outline: none;
}

#hwCalc .expression-line {
  min-height: 1.25em;
  color: var(--sc-mute);
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  word-break: break-all;
  text-align: right;
}

#hwCalc .result-line {
  margin-top: 6px;
  color: var(--sc-ink);
  font-size: clamp(1.8rem, 4vw, 2.35rem);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1.1;
  text-align: right;
  word-break: break-all;
  transition: transform 280ms var(--sc-ease-out);
}

#hwCalc .result-line.pop {
  animation: scResultPop 320ms var(--sc-ease-out);
}

#hwCalc .result-line.error {
  color: var(--sc-danger);
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

@keyframes scResultPop {
  from { transform: scale(0.97); opacity: 0.7; }
  to { transform: none; opacity: 1; }
}

/* Memory */
#hwCalc .memory-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

#hwCalc .btn-mem {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--sc-mute);
  background: var(--sc-soft);
  font-size: 0.78rem;
  font-weight: 750;
  transition:
    color 200ms var(--sc-ease),
    background-color 200ms var(--sc-ease),
    border-color 200ms var(--sc-ease);
}

#hwCalc .btn-mem:hover {
  color: var(--sc-ink);
  border-color: var(--sc-line);
  background: var(--sc-bg);
}

/* Keypads */
#hwCalc .keypad-container {
  display: grid;
  gap: 10px;
}

#hwCalc .keypad-grid {
  display: grid;
  gap: 8px;
}

#hwCalc .sci-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

#hwCalc .mod-grid {
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
}

#hwCalc .main-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#hwCalc .keypad-grid button {
  min-height: 48px;
  border: 1px solid var(--sc-line);
  border-radius: 12px;
  color: var(--sc-ink);
  background: var(--sc-bg);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition:
    transform 180ms var(--sc-ease-out),
    background-color 200ms var(--sc-ease),
    border-color 200ms var(--sc-ease),
    box-shadow 220ms var(--sc-ease);
}

#hwCalc .keypad-grid button:hover {
  border-color: var(--sc-line-strong);
  background: var(--sc-btn-hover);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

#hwCalc .btn-num {
  font-variant-numeric: tabular-nums;
  font-size: 1.12rem;
}

#hwCalc .btn-op {
  color: var(--sc-accent-dark);
  background: var(--sc-accent-soft);
  border-color: color-mix(in srgb, var(--sc-accent) 18%, var(--sc-line));
}

#hwCalc .btn-sci {
  min-height: 40px;
  color: var(--sc-ink);
  background: var(--sc-soft);
  font-size: 0.82rem;
  font-weight: 650;
  opacity: 0.92;
}

#hwCalc .btn-mod {
  color: var(--sc-mod);
  background: var(--sc-mod-soft);
  border-color: #fde68a;
  font-size: 0.82rem;
}

#hwCalc .btn-danger {
  color: var(--sc-danger);
  background: var(--sc-danger-soft);
  border-color: #fecaca;
}

#hwCalc .btn-warn {
  color: var(--sc-warn);
  background: var(--sc-warn-soft);
  border-color: #fed7aa;
}

#hwCalc .btn-primary,
#hwCalc .btn-equals {
  color: var(--sc-equals-text);
  background: var(--sc-accent);
  border-color: var(--sc-accent);
}

#hwCalc .btn-primary:hover,
#hwCalc .btn-equals:hover {
  background: var(--sc-accent-dark);
  border-color: var(--sc-accent-dark);
  color: var(--sc-equals-text);
}

#hwCalc .btn-highlight {
  color: var(--sc-accent-dark);
  background: var(--sc-accent-soft);
  border-color: color-mix(in srgb, var(--sc-accent) 22%, var(--sc-line));
}

/* History drawer */
#hwCalc .history-panel {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  width: min(100%, 280px);
  height: 100%;
  border: 1px solid var(--sc-line);
  border-radius: var(--sc-radius);
  background: var(--sc-history-bg);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.18);
  animation: portalPaneIn 360ms var(--sc-ease-out) both;
}

#hwCalc .history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--sc-line);
}

#hwCalc .history-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

#hwCalc .history-actions {
  display: flex;
  gap: 6px;
}

#hwCalc .history-list {
  flex: 1;
  padding: 8px;
  overflow: auto;
  scrollbar-width: none;
}

#hwCalc .history-list::-webkit-scrollbar {
  display: none;
}

#hwCalc .history-empty {
  margin: 18px 8px;
  color: var(--sc-mute);
  font-size: 0.88rem;
  text-align: center;
}

#hwCalc .history-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 180ms var(--sc-ease);
}

#hwCalc .history-item:hover {
  background: var(--sc-soft);
}

#hwCalc .history-expr {
  color: var(--sc-mute);
  font-size: 0.8rem;
  word-break: break-all;
}

#hwCalc .history-res {
  margin-top: 2px;
  font-size: 0.95rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

/* Guide / mods modal */
#hwCalc .modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  padding: 8px;
  border-radius: var(--sc-radius);
  background: var(--sc-modal-scrim);
  animation: portalPaneIn 320ms var(--sc-ease-out) both;
}

#hwCalc .modal-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 100%;
  border: 1px solid var(--sc-line);
  border-radius: 14px;
  background: var(--sc-modal-bg);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

#hwCalc .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--sc-line);
}

#hwCalc .modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.03em;
}

#hwCalc .modal-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--sc-line);
  background: var(--sc-soft);
  overflow-x: auto;
  scrollbar-width: none;
}

#hwCalc .modal-tabs::-webkit-scrollbar {
  display: none;
}

#hwCalc .tab-btn {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--sc-mute);
  font-size: 0.78rem;
  font-weight: 700;
  transition:
    color 200ms var(--sc-ease),
    background-color 200ms var(--sc-ease);
}

#hwCalc .tab-btn:hover {
  color: var(--sc-ink);
}

#hwCalc .tab-btn.active {
  color: var(--sc-ink);
  background: var(--sc-bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

#hwCalc .modal-body {
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow: auto;
  scrollbar-width: none;
}

#hwCalc .modal-body::-webkit-scrollbar {
  display: none;
}

#hwCalc .tab-content {
  display: none;
}

#hwCalc .tab-content.active {
  display: block;
  animation: portalPaneIn 360ms var(--sc-ease-out) both;
}

#hwCalc .guide-intro h3,
#hwCalc .tab-content > h3,
#hwCalc .creator-header-row h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.03em;
}

#hwCalc .guide-intro p,
#hwCalc .subtitle {
  margin: 0 0 14px;
  color: var(--sc-mute);
  font-size: 0.9rem;
  line-height: 1.45;
}

#hwCalc .guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

#hwCalc .guide-card {
  padding: 14px;
  border: 1px solid var(--sc-line);
  border-radius: 12px;
  background: var(--sc-card);
}

#hwCalc .guide-card h4 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  font-weight: 750;
}

#hwCalc .guide-card p {
  margin: 0 0 6px;
  color: var(--sc-mute);
  font-size: 0.84rem;
  line-height: 1.4;
}

#hwCalc .guide-card code,
#hwCalc .tab-content code {
  padding: 1px 5px;
  border-radius: 6px;
  color: var(--sc-ink);
  background: var(--sc-soft);
  font-family: ui-monospace, "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.8em;
}

#hwCalc .btn-try {
  margin-top: 8px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--sc-accent) 22%, var(--sc-line));
  border-radius: 9px;
  color: var(--sc-accent-dark);
  background: var(--sc-accent-soft);
  font-size: 0.78rem;
  font-weight: 750;
}

#hwCalc .btn-try:hover {
  background: color-mix(in srgb, var(--sc-accent-soft) 70%, var(--sc-bg));
}

/* Forms — custom chrome, no native look */
#hwCalc .builder-form,
#hwCalc .form-group {
  display: grid;
  gap: 8px;
}

#hwCalc .form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

#hwCalc .form-group label {
  color: var(--sc-mute);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

#hwCalc .form-control,
#hwCalc .sc-select-wrap select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--sc-line);
  border-radius: 10px;
  color: var(--sc-ink);
  background: var(--sc-bg);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 200ms var(--sc-ease), box-shadow 200ms var(--sc-ease);
}

#hwCalc .form-control:focus,
#hwCalc .sc-select-wrap select:focus {
  border-color: color-mix(in srgb, var(--sc-accent) 45%, var(--sc-line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sc-accent) 16%, transparent);
}

#hwCalc .sc-select-wrap {
  position: relative;
}

#hwCalc .sc-select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 14px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--sc-mute);
  border-bottom: 2px solid var(--sc-mute);
  transform: translateY(-60%) rotate(45deg);
  pointer-events: none;
}

#hwCalc .sc-select-wrap select {
  padding-right: 34px;
  cursor: pointer;
}

#hwCalc .mod-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

#hwCalc .mod-action-row .btn-primary {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 11px;
  font-size: 0.88rem;
  font-weight: 750;
}

#hwCalc .status-msg {
  font-size: 0.84rem;
  font-weight: 600;
}

#hwCalc .status-msg.success { color: #15803d; }
#hwCalc .status-msg.error { color: var(--sc-danger); }

#hwCalc .mods-list {
  display: grid;
  gap: 10px;
}

#hwCalc .mod-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px;
  border: 1px solid var(--sc-line);
  border-radius: 12px;
  background: var(--sc-card);
}

#hwCalc .mod-info h4 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

#hwCalc .mod-info p {
  margin: 0;
  color: var(--sc-mute);
  font-size: 0.84rem;
}

#hwCalc .mod-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#hwCalc .creator-header-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

#hwCalc .creator-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* IDE */
#hwCalc .ide-container {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  min-height: 220px;
  border: 1px solid var(--sc-line);
  border-radius: 12px;
  background: #0f172a;
  overflow: hidden;
}

#hwCalc .editor-gutter {
  padding: 12px 8px;
  color: #64748b;
  background: #0b1220;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  text-align: right;
  user-select: none;
}

#hwCalc .editor-wrapper {
  position: relative;
  min-width: 0;
}

#hwCalc .editor-highlight,
#hwCalc .editor-textarea {
  margin: 0;
  padding: 12px;
  border: 0;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre;
  word-wrap: normal;
  overflow: auto;
  tab-size: 2;
}

#hwCalc .editor-highlight {
  position: absolute;
  inset: 0;
  color: #e2e8f0;
  pointer-events: none;
}

#hwCalc .editor-textarea {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 220px;
  color: transparent;
  caret-color: #e2e8f0;
  background: transparent;
  resize: vertical;
  outline: none;
  scrollbar-width: thin;
}

#hwCalc .autocomplete-popup {
  position: absolute;
  z-index: 4;
  min-width: 160px;
  max-height: 180px;
  padding: 4px;
  border: 1px solid var(--sc-line);
  border-radius: 10px;
  background: var(--sc-bg);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
  overflow: auto;
  scrollbar-width: none;
}

@media (max-width: 700px) {
  #hwCalc .sci-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  #hwCalc .guide-grid,
  #hwCalc .form-row {
    grid-template-columns: 1fr;
  }

  #hwCalc .keypad-grid button {
    min-height: 44px;
  }

  #hwCalc .mode-pill-btn {
    padding: 0 10px;
    font-size: 0.76rem;
  }

  #hwCalc .history-panel {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  #hwCalc,
  #hwCalc .result-line.pop,
  #hwCalc .history-panel,
  #hwCalc .modal-overlay,
  #hwCalc .tab-content.active {
    animation: none !important;
  }
}
