:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #182033;
  --muted: #687187;
  --line: #dfe4ee;
  --key: #f2f4f8;
  --accent: #5b5ce2;
  --accent-text: #ffffff;
  --danger: #b84350;
  --shadow: 0 18px 50px #29345716;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

:root[data-theme="dark"] {
  --bg: #111522;
  --surface: #1b2131;
  --text: #f3f5fa;
  --muted: #abb4c7;
  --line: #30394d;
  --key: #252d40;
  --accent: #8c8dff;
  --accent-text: #101226;
  --danger: #fa8994;
  --shadow: 0 18px 50px #00000080;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
}

input { font: inherit; }

button, .pill, .icon-button, .copy-button, .keypad-toggle, .history-trigger {
  transition: filter 0.2s ease, transform 0.1s ease, background-color 0.2s ease !important;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
}

button:hover, .pill:hover, .icon-button:hover, .copy-button:hover, .keypad-toggle:hover, .history-trigger:hover {
  filter: brightness(0.9) !important;
  transform: translateY(-1px) !important;
  cursor: pointer !important;
}

button:active {
  transform: translateY(0px) !important;
  filter: brightness(0.8) !important;
}

.operator, .danger, .utility {
  font-weight: 600 !important;
}
.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  max-width: 1120px;
  margin: auto;
  padding: 16px;
}

.app-header,
.header-actions,
.toolbar,
.segmented,
.base-select,
.expression-line,
.result-line {
  display: flex;
  align-items: center;
}

.app-header {
  justify-content: space-between;
  gap: 10px;
}

.header-actions,
.segmented,
.base-select { gap: 5px; }

.brand {
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.brand span { color: var(--accent); }

.pill,
.icon-button,
.toolbar button,
.format-copy button {
  min-height: 34px;
  padding: 0 9px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

.pill.active,
.segmented button.active,
.base-select button.active,
.keypad-toggle.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 3px #0000001a;
}

.icon-button {
  width: 34px;
  padding: 0;
  font-size: 1.2rem;
}

.calculator,
.history-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.calculator { overflow: hidden; }

.toolbar {
  justify-content: space-between;
  gap: 5px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--key) 70%, transparent);
}

.segmented,
.base-select {
  padding: 3px;
  background: var(--key);
  border-radius: 11px;
}

.segmented button,
.base-select button {
  min-height: 28px;
  padding: 0 7px;
  font-size: 0.72rem;
  font-weight: 750;
}

.history-trigger { margin-left: auto; }

.history-trigger span {
  padding: 2px 6px;
  color: var(--accent-text);
  font-size: 0.75em;
  background: var(--accent);
  border-radius: 100px;
}

.display {
  display: flex;
  flex-direction: column;
  justify-content: end;
  min-height: 150px;
  padding: 14px 16px 10px;
  text-align: right;
}

.expression-line { gap: 8px; }

.expression-input {
  width: 100%;
  min-height: 34px;
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1.4;
  text-align: right;
  background: none;
  border: 0;
  outline: 0;
  white-space: nowrap;
  overflow-x: auto;
}

.expression-input:empty::before {
  color: var(--muted);
  content: attr(data-placeholder);
}
#expression {
  margin-right: 30px !important;
}

.root-box {
  display: inline-flex;
  align-items: end;
  margin: 0 2px;
  color: var(--text);
  vertical-align: middle;
}

.root-index {
  position: relative;
  top: -0.42em;
  width: 2.2em;
  min-width: 1.3em;
  height: 1.3em;
  padding: 0 1px;
  color: var(--accent);
  font-size: 0.7em;
  text-align: center;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  outline: 0;
  margin-right: -0.18em;
}

.root-mark {
  font-size: 1.65em;
  line-height: 0.88;
}

.root-radicand {
  width: 4em;
  min-width: 2em;
  height: 1.45em;
  padding: 0 2px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-top: 1px solid var(--text);
  outline: 0;
}


.result-line {
  justify-content: end;
  gap: 8px;
  min-width: 0;
}

.result {
  overflow-wrap: anywhere;
  font-size: clamp(2.2rem, 9vw, 4rem);
  font-weight: 720;
  line-height: 1.1;
  letter-spacing: -0.055em;
}

.copy-button {
  flex: none;
  width: 32px;
  height: 32px;
  color: var(--muted);
  background: var(--key);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.exact,
.error {
  min-height: 1.2em;
  margin: 6px 0 0;
  font-size: 0.82rem;
}

.exact { color: var(--muted); }
.error { color: var(--danger); }

.key-area {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.operator-keys { grid-template-columns: repeat(2, 1fr); }

.keypad button {
  min-height: 40px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 650;
  background: var(--key);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
}

.keypad button:active { transform: scale(0.96); }
.keypad .operator { color: var(--accent); }
.keypad .utility { font-size: 0.8rem; }
.keypad .danger { color: var(--danger); }

.keypad .equals {
  grid-column: span 2;
  color: var(--accent-text);
  font-size: 1.1rem;
  background: var(--accent);
}

.dev-grid {
  grid-column: 1 / -1;
  grid-template-columns: repeat(5, 1fr);
}

.study-grid {
  grid-column: 1 / -1;
  grid-template-columns: repeat(5, 1fr);
}

.dev-output {
  min-height: 172px;
  padding: 14px 16px 0;
  background: color-mix(in srgb, var(--key) 35%, var(--surface));
  border-top: 1px solid var(--line);
}

.dev-bases {
  display: grid;
  gap: 10px;
  width: min(240px, 100%);
}

.base-row {
  display: flex;
  gap: 24px;
  color: var(--muted);
  font-size: 0.78rem;
}

.base-row:first-child {
  color: var(--accent);
}

.base-row code {
  color: var(--text);
}

.dev-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.75rem;
}

.dev-toolbar {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  color: var(--text);
  font-size: 0.78rem;
}

.dev-toolbar .dev-size { margin-left: auto; }

code {
  color: var(--text);
  font-family: ui-monospace, monospace;
}

.format-copy {
  display: flex;
  padding: 5px 0;
}
.format-copy button { flex: 1; min-height: 32px; font-size: 0.72rem; }

.study-mode .base-select,
.study-mode .dev-output,
.study-mode .dev-toolbar {
  display: none !important;
}

.dev-mode .display {
  min-height: 136px;
}

.dev-mode .segmented {
  display: none;
}

.dev-mode .key-area {
  display: block;
  padding-top: 8px;
}

.dev-mode .keypad button {
  min-height: 48px;
  color: var(--text);
  background: color-mix(in srgb, var(--key) 45%, var(--surface));
  border: 1px solid var(--line);
  border-radius: 6px;
}

.dev-mode .keypad .equals {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.history-panel {
  max-height: 560px;
  padding: 16px;
  overflow: auto;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-heading h2 { margin: 0; font-size: 1rem; }
.history-heading button { color: var(--danger); background: none; border: 0; cursor: pointer; }
.history-empty { color: var(--muted); font-size: 0.9rem; }

ol { margin: 10px 0; padding: 0; list-style: none; }

li {
  display: grid;
  gap: 2px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

li button {
  overflow: hidden;
  color: var(--muted);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: 0;
  cursor: pointer;
}

.history-result { color: var(--text); font-weight: 650; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent);
  outline-offset: 2px;
}

@media (max-width: 520px) {
  .app-shell { padding: 10px; }
  .app-header { align-items: flex-start; }
  .header-actions { flex-wrap: wrap; justify-content: end; }
  .pill { padding: 0 7px; }
  .display { min-height: 116px; padding: 10px 13px 8px; }
  .key-area { gap: 5px; padding: 8px; }
  .keypad { gap: 5px; }
  .keypad button { min-height: 40px; }
  .dev-mode .keypad button { min-height: 42px; }
  .history-panel { display: none; position: fixed; z-index: 3; right: 10px; bottom: 10px; left: 10px; max-height: 65vh; }
  .history-panel.open { display: block; }
  .base-select button { padding: 0 5px; }
}

@media (min-width: 820px) {
  .app-shell {
    grid-template-columns: minmax(580px, 1fr) 300px;
    align-items: start;
    padding-top: 28px;
  }

  .app-header { grid-column: 1 / -1; }
  .history-trigger { display: none; }
  .history-panel { grid-column: 2; grid-row: 2; }
}


.author-footer {
    margin-top: auto; 
    background-color: #0056b3; 
    color: #ffffff; 
    text-align: center; 
    padding: 20px; 
    font-family: Arial, sans-serif; 
}

.author-footer a {
    color: #e0e0e0;
    text-decoration: underline;
}

.author-footer a:hover {
    color: #ffffff;
}
