:root {
  --calc-blue: #0b5cad;
  --calc-navy: #102a43;
  --calc-orange: #f28c28;
  --calc-green: #0f7b6c;
  --calc-purple: #7c3aed;
}

.calculator-page { background: #eef5fb; }
.calculator-shell { width: min(calc(100% - 32px), 1380px); margin: 0 auto; padding: 42px 0 72px; }
.calculator-intro { display: flex; align-items: end; justify-content: space-between; gap: 32px; margin-bottom: 26px; }
.calculator-intro h1 { max-width: 810px; font-size: clamp(2rem, 4.5vw, 4.25rem); }
.calculator-intro p { max-width: 720px; margin: 16px 0 0; color: var(--muted); font-size: 1.08rem; }

.mode-switch { display: flex; flex: 0 0 auto; gap: 5px; padding: 5px; border: 1px solid #c9d9e8; border-radius: 16px; background: #fff; box-shadow: 0 8px 25px rgba(16,42,67,.08); }
.mode-button { display: flex; min-width: 116px; min-height: 58px; align-items: center; justify-content: center; gap: 8px; padding: 9px 13px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font: inherit; font-weight: 800; cursor: pointer; }
.mode-button span { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 8px; background: var(--surface-alt); font-size: .72rem; }
.mode-button:hover { background: var(--blue-soft); color: var(--blue-dark); }
.mode-button.is-active { background: var(--calc-navy); color: #fff; }
.mode-button.is-active span { background: rgba(255,255,255,.15); }

.calculator-panel { min-height: 650px; }
.calc-workspace { display: grid; grid-template-columns: minmax(0, 900px) minmax(270px, 1fr); gap: 22px; align-items: start; }
.calculator-machine, .history-card, .graph-sidebar, .graph-card, .analysis-card, .value-table-card, .tool-card { border: 1px solid #cbdbea; border-radius: 22px; background: #fff; box-shadow: 0 10px 30px rgba(16,42,67,.07); }
.calculator-machine { padding: clamp(16px, 3vw, 28px); }

.display-card { padding: 15px 18px 17px; border: 2px solid #294d6d; border-radius: 17px; background: linear-gradient(145deg, #f8fcff, #edf7f4); box-shadow: inset 0 2px 8px rgba(16,42,67,.08); }
.display-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; color: var(--muted); font-size: .78rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.angle-toggle { display: flex; gap: 2px; padding: 2px; border-radius: 8px; background: #dce8e7; }
.angle-toggle button { padding: 4px 7px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-size: .67rem; font-weight: 900; cursor: pointer; }
.angle-toggle button.is-active { background: #fff; color: var(--calc-green); box-shadow: 0 2px 5px rgba(16,42,67,.1); }
#calc-expression { display: block; width: 100%; min-height: 76px; resize: vertical; padding: 12px 0 6px; border: 0; outline: 0; background: transparent; color: var(--calc-navy); font: 600 clamp(1.25rem, 3vw, 2rem)/1.35 "Cambria Math", Cambria, monospace; }
#calc-expression::placeholder { color: #8ca0b4; }
.result-line { display: flex; align-items: baseline; justify-content: flex-end; gap: 13px; min-height: 49px; border-top: 1px solid #cbdbea; padding-top: 8px; color: var(--muted); }
.result-line output { max-width: 90%; overflow-wrap: anywhere; color: var(--calc-blue); font: 750 clamp(1.4rem, 3.5vw, 2.4rem)/1.2 "Cambria Math", Cambria, monospace; font-variant-numeric: tabular-nums; }
.display-message { min-height: 20px; margin: 6px 0 0; color: var(--muted); font-size: .82rem; }
.display-message.is-error { color: #b42318; font-weight: 750; }

.direct-tools { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 17px 0; }
.direct-tools button { display: grid; min-height: 70px; place-items: center; align-content: center; gap: 2px; padding: 8px 5px; border: 1px solid #cbdbea; border-radius: 11px; background: var(--surface-alt); color: var(--calc-navy); cursor: pointer; }
.direct-tools button:hover { border-color: #8eb5da; background: var(--blue-soft); }
.direct-tools strong { font: 800 1.05rem "Cambria Math", Cambria, serif; }
.direct-tools span { color: var(--muted); font-size: .68rem; }

.key-section { border-top: 1px solid var(--line); }
.key-section summary { padding: 13px 2px; color: var(--calc-navy); font-size: .88rem; font-weight: 850; cursor: pointer; }
.keypad { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; }
.key { grid-column: span 2; min-height: 51px; border: 1px solid #cbdbea; border-radius: 10px; background: #fff; color: var(--calc-navy); font: 800 1.08rem inherit; cursor: pointer; box-shadow: 0 2px 3px rgba(16,42,67,.04); }
.key.key-compact { grid-column: span 1; }
.key-separator { background: #eef3f7; color: var(--calc-green); font-size: 1.2rem; }
.key:hover { border-color: #8eb5da; background: var(--blue-soft); transform: translateY(-1px); }
.key:active { transform: translateY(1px); }
.key-utility { background: #eef3f7; color: #405a72; }
.key-operator { background: #e8f2fd; color: var(--calc-blue); font-size: 1.25rem; }
.key-equals { border-color: var(--calc-blue); background: var(--calc-blue); color: #fff; }
.key-equals:hover { background: var(--blue-dark); color: #fff; }
.science-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; padding-bottom: 3px; }
.science-grid button { min-height: 42px; padding: 6px; border: 1px solid #cbdbea; border-radius: 9px; background: #fff; color: var(--calc-navy); font: inherit; font-size: .76rem; font-weight: 750; cursor: pointer; }
.science-grid button:hover { background: var(--blue-soft); }

.history-card { position: sticky; top: 122px; padding: 22px; }
.aside-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.aside-heading h2, .panel-heading h2, .stoch-intro h2 { margin: 2px 0 0; font-size: 1.35rem; }
.aside-kicker { color: var(--calc-green); font-size: .7rem; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.text-button { padding: 5px; border: 0; background: transparent; color: var(--calc-blue); font: inherit; font-size: .78rem; font-weight: 800; cursor: pointer; }
.history-list { display: grid; gap: 8px; max-height: 510px; overflow: auto; margin: 18px 0 0; padding: 0; list-style: none; }
.history-list button { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-alt); color: var(--calc-navy); text-align: left; cursor: pointer; }
.history-list button:hover { border-color: #8eb5da; }
.history-expression { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .76rem; }
.history-result { display: block; margin-top: 3px; overflow-wrap: anywhere; font-weight: 850; }
.empty-state { padding: 24px 10px; color: var(--muted); text-align: center; }
.help-box { margin-top: 20px; padding: 15px; border-radius: 12px; background: #fff4e8; color: #69431d; font-size: .8rem; }
.help-box p { margin: 5px 0 0; }
kbd { padding: 2px 5px; border: 1px solid #c9b396; border-radius: 5px; background: #fff; font: inherit; font-size: .75rem; }

.graph-workspace { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 22px; align-items: start; }
.graph-sidebar { position: sticky; top: 122px; padding: 22px; }
.panel-heading p { margin: 8px 0 0; color: var(--muted); font-size: .86rem; }
.panel-heading code { padding: 2px 5px; border-radius: 5px; background: var(--surface-alt); }
.function-list { display: grid; gap: 9px; margin-top: 20px; }
.function-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) 24px; align-items: center; gap: 7px; padding: 7px 8px; border: 1px solid var(--line); border-left: 5px solid currentColor; border-radius: 10px; }
.function-row span { font-family: "Cambria Math", Cambria, serif; font-weight: 900; }
.function-row input { min-width: 0; padding: 7px 4px; border: 0; outline: 0; color: var(--calc-navy); font: 650 .95rem "Cambria Math", Cambria, monospace; }
.function-row button { width: 18px; height: 18px; border: 3px solid currentColor; border-radius: 50%; background: currentColor; cursor: pointer; }
.function-row button[aria-pressed="false"] { background: transparent; opacity: .4; }
.function-one { color: var(--calc-orange); }.function-two { color: var(--calc-blue); }.function-three { color: var(--calc-purple); }
.window-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.window-fields label, .tool-fields label, .binomial-fields label, .tool-card > label { color: var(--muted); font-size: .72rem; font-weight: 800; }
.window-fields input, .tool-fields input, .binomial-fields input, .binomial-fields select, .tool-card textarea { width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid #b8cadb; border-radius: 9px; background: #fff; color: var(--calc-navy); font: inherit; }
.graph-actions { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 16px; }
.graph-hint { margin: 14px 0 0; color: var(--muted); font-size: .76rem; }
.graph-main { min-width: 0; }
.graph-card { overflow: hidden; }
.graph-toolbar { display: flex; min-height: 54px; align-items: center; justify-content: space-between; gap: 15px; padding: 9px 13px; border-bottom: 1px solid var(--line); }
.graph-tool-buttons { display: flex; gap: 5px; }
.graph-tool-buttons button { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--calc-navy); font-size: 1.1rem; font-weight: 900; cursor: pointer; }
.graph-tool-buttons button:hover { background: var(--blue-soft); }
.graph-status { min-width: 0; overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.calculator-graph { display: block; width: 100%; height: 560px; max-width: none; background: #fff; cursor: crosshair; touch-action: none; }
.calculator-graph.is-dragging { cursor: grabbing; }
.graph-error { min-height: 30px; padding: 5px 14px 9px; color: #b42318; font-size: .78rem; font-weight: 750; }
.analysis-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.analysis-card { padding: 18px; }
.analysis-card h3 { margin: 3px 0 11px; }
.result-stack { display: grid; gap: 6px; color: var(--muted); font-size: .82rem; }
.result-stack span { display: block; padding: 7px 9px; border-radius: 8px; background: var(--surface-alt); }
.result-stack strong { color: var(--calc-navy); }
.inline-field { display: flex; align-items: center; gap: 7px; margin-bottom: 9px; color: var(--muted); font-size: .82rem; font-weight: 800; }
.inline-field input { width: 110px; padding: 6px 8px; border: 1px solid #b8cadb; border-radius: 8px; font: inherit; }
.value-table-card { margin-top: 14px; overflow: hidden; }
.value-table-card summary { padding: 15px 18px; font-weight: 850; cursor: pointer; }
.table-scroll { overflow-x: auto; padding: 0 16px 16px; }
.value-table-card table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.value-table-card th, .value-table-card td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; font-size: .82rem; }
.value-table-card th { color: var(--muted); }

.stoch-intro { max-width: 760px; margin-bottom: 22px; }
.stoch-intro p { margin: 8px 0 0; color: var(--muted); }
.tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.tool-card { position: relative; padding: clamp(20px, 3vw, 29px); }
.tool-card-wide { grid-column: 1 / -1; }
.tool-icon { display: grid; width: 42px; height: 42px; place-items: center; margin-bottom: 13px; border-radius: 12px; background: var(--blue-soft); color: var(--calc-blue); font: 900 1.1rem "Cambria Math", Cambria, serif; }
.tool-card h3 { margin-bottom: 7px; font-size: 1.22rem; }
.tool-card > p { margin: 0 0 17px; color: var(--muted); font-size: .9rem; }
.tool-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.binomial-fields { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 14px; }
.tool-result { display: block; min-height: 55px; margin-top: 14px; padding: 14px 16px; border-left: 4px solid var(--calc-orange); border-radius: 9px; background: #fff4e8; color: var(--calc-navy); font: 750 1.03rem/1.45 "Cambria Math", Cambria, serif; }
.tool-result.is-error { border-left-color: #b42318; background: #fff0ef; color: #8f1d16; }
.tool-result-list { font: 750 .9rem/1.6 inherit; }
.distribution-result { display: grid; grid-template-columns: minmax(230px, .6fr) minmax(0, 1.4fr); gap: 18px; align-items: stretch; }
.distribution-result canvas { width: 100%; height: 190px; max-width: none; border: 1px solid var(--line); border-radius: 12px; background: #fff; }

@media (max-width: 1050px) {
  .calculator-intro { align-items: start; flex-direction: column; }
  .calc-workspace, .graph-workspace { grid-template-columns: 1fr; }
  .history-card, .graph-sidebar { position: static; }
  .history-list { max-height: 260px; }
}

@media (max-width: 760px) {
  .calculator-shell { width: min(calc(100% - 20px), 1380px); padding-top: 24px; }
  .mode-switch { width: 100%; }
  .mode-button { flex: 1; min-width: 0; padding-inline: 6px; }
  .direct-tools { grid-template-columns: repeat(3, 1fr); }
  .calculator-graph { height: 430px; }
  .analysis-grid, .tool-grid { grid-template-columns: 1fr; }
  .tool-card-wide { grid-column: auto; }
  .binomial-fields { grid-template-columns: repeat(2, 1fr); }
  .distribution-result { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .calculator-intro h1 { font-size: 2.15rem; }
  .mode-button { min-height: 52px; flex-direction: column; gap: 2px; font-size: .7rem; }
  .mode-button span { height: 21px; }
  .calculator-machine, .history-card, .graph-sidebar, .analysis-card, .tool-card { padding: 15px; border-radius: 16px; }
  .display-card { padding: 12px; }
  .direct-tools { gap: 6px; }
  .science-grid { grid-template-columns: repeat(2, 1fr); }
  .calculator-graph { height: 350px; }
  .window-fields, .tool-fields, .binomial-fields { grid-template-columns: 1fr 1fr; }
  .graph-status { display: none; }
}

@media print {
  .calculator-intro, .mode-switch, .graph-sidebar, .graph-toolbar, .keypad, .direct-tools, .key-section summary { display: none !important; }
  .calculator-panel[hidden] { display: none !important; }
  .calculator-shell { width: 100%; padding: 0; }
}
