/* Colors are set from app.js (see applyTheme); these are the dark Mint defaults. */
:root {
  --bg: #101214;
  --surface: #202427;
  --fg: #F2F4EF;
  --muted: #ABB3AD;
  --primary: #CAEFAC;
  --on-primary: #000;
  --container: rgba(202, 239, 172, 0.16);
  --outline: #938F99;
  --outline-variant: #49454F;
  --surface-container: #211F26;
  --surface-container-high: #2B2930;
  --surface-container-highest: #36343B;
  --error: #F2B8B5;
  --key: 72px;
  color-scheme: dark;
  font-family: Roboto, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  font-size: 16px;
  line-height: 24px;
  letter-spacing: 0.5px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
input { user-select: text; -webkit-user-select: text; }
button { font: inherit; letter-spacing: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3, p, ul, ol { margin: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.muted { color: var(--muted); }
.accent-text { color: var(--primary); }
.title-small, h3 { font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: 0.1px; }

/* State layer shared by all pressable surfaces (stand-in for the Material ripple). */
.pressable { position: relative; overflow: hidden; }
.pressable::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 120ms;
  pointer-events: none;
}
@media (hover: hover) { .pressable:not(:disabled):hover::after { opacity: 0.08; } }
.pressable:not(:disabled):active::after { opacity: 0.14; }

.screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

/* ---------- Calculator ---------- */

.calc-frame {
  position: absolute;
  inset: 0;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    calc(env(safe-area-inset-right) + 20px)
    calc(env(safe-area-inset-bottom) + 12px)
    calc(env(safe-area-inset-left) + 20px);
  container-type: size;
}
.calc-column {
  /* Same formula as the Compose layout: min((w - 30) / 4, (h - 200) / 5, 100) with a 40dp floor. */
  --key: max(40px, min(calc((100cqw - 30px) / 4), calc((100cqh - 200px) / 5), 100px));
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.toolbar { width: 100%; display: flex; }
.menu-anchor { position: relative; }

.icon-button {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--fg);
  display: grid;
  place-items: center;
  flex: none;
}
.icon-button svg { width: 24px; height: 24px; fill: currentColor; }

.display {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  scrollbar-width: none;
}
.display::before { content: ""; flex: 1; }
.count-label { color: var(--muted); font-size: 16px; }
.equation {
  width: 100%;
  text-align: end;
  color: var(--fg);
  overflow-wrap: anywhere;
  word-break: break-all;
  letter-spacing: 0;
}
.equation.clickable, .result.clickable { cursor: pointer; }
.result {
  max-width: 100%;
  margin-top: 8px;
  font-size: 23px;
  line-height: 32px;
  min-height: 32px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  color: var(--muted);
  letter-spacing: 0;
}
.result.has-answer { color: var(--primary); }
.average-error { color: var(--primary); font-size: 13px; line-height: 18px; }

.keys-width { width: calc(var(--key) * 4 + 30px); }
.average-row { padding: 20px 0; display: flex; }
.tonal-button {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 0;
  border-radius: 14px;
  padding: 0 24px;
  background: var(--container);
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tonal-button:disabled {
  background: color-mix(in srgb, var(--fg) 12%, transparent);
  color: color-mix(in srgb, var(--fg) 38%, transparent);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, var(--key));
  grid-auto-rows: var(--key);
  gap: 10px;
}
.key {
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--fg);
  font-size: 27px;
  line-height: 1;
  letter-spacing: 0;
  display: grid;
  place-items: center;
  padding: 0;
  touch-action: manipulation;
}
.key.operator { background: var(--container); color: var(--primary); }
.key.clear { color: var(--primary); }
.key.equals { background: var(--primary); color: var(--on-primary); }
.key:disabled { color: color-mix(in srgb, var(--muted) 35%, transparent); }
.bottom-spacer { height: 8px; flex: none; }

/* ---------- Menus ---------- */

.menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 10;
  min-width: 112px;
  max-width: 280px;
  padding: 8px 0;
  border-radius: 4px;
  background: var(--surface-container);
  box-shadow: 0 2px 6px 2px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
}
.menu.floating { position: fixed; top: 0; }
.menu button {
  height: 48px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--fg);
  text-align: start;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
  white-space: nowrap;
  min-width: 112px;
}

/* ---------- Settings ---------- */

.settings {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.settings-bar {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  flex: none;
}
.settings-bar h1 { font-size: 22px; line-height: 28px; font-weight: 400; letter-spacing: 0; margin-left: 4px; }
.settings-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.settings-content {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 720px;
  margin: 0 auto;
}
.card {
  background: var(--surface);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h2 { font-size: 16px; line-height: 24px; font-weight: 500; letter-spacing: 0.15px; color: var(--primary); }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
#themeChips { gap: 12px; }
.chip-rows { display: flex; flex-direction: column; gap: 12px; }
.chip {
  height: 32px;
  padding: 0 16px;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
}
.chip[aria-pressed="true"] {
  border-color: transparent;
  background: var(--container);
  color: var(--primary);
}

.switch-row { display: flex; align-items: center; gap: 16px; cursor: pointer; }
.switch-text { flex: 1; display: flex; flex-direction: column; }
.switch {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  flex: none;
  position: relative;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  border: 2px solid var(--outline);
  background: var(--surface-container-highest);
  cursor: pointer;
  transition: background 150ms, border-color 150ms;
}
.switch::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--outline);
  transform: translateY(-50%);
  transition: left 150ms, width 150ms, height 150ms, background 150ms;
}
.switch:checked { background: var(--primary); border-color: var(--primary); }
.switch:checked::before { left: 22px; width: 24px; height: 24px; background: var(--on-primary); }

.slider, .hue-slider {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.slider { --pct: 20%; }
.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--primary) var(--pct), var(--container) var(--pct));
}
.slider::-moz-range-track { height: 4px; border-radius: 2px; background: var(--container); }
.slider::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--primary); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -8px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
}
.slider::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--primary); }

.outlined-button {
  height: 40px;
  padding: 0 24px;
  border: 1px solid var(--outline);
  border-radius: 20px;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
}
.outlined-button.full { width: 100%; }
.settings-content > .outlined-button { margin-bottom: 8px; }

.text-button {
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
}
.text-button:disabled { color: color-mix(in srgb, var(--fg) 38%, transparent); }

/* ---------- Dialogs ---------- */

.dialog {
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--surface);
  color: var(--fg);
  width: calc(100vw - 48px);
  max-width: 560px;
  max-height: calc(100dvh - 48px);
  overflow: hidden;
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  flex: 1;
}
.dialog-title { font-size: 25px; line-height: 32px; font-weight: 600; letter-spacing: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex: none; }
.dialog-actions.spread { justify-content: space-between; }

.history-list, .average-list {
  list-style: none;
  overflow-y: auto;
  min-height: 0;
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
}
.history-list { max-height: 420px; gap: 10px; }
.history-item {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-touch-callout: none;
  flex: none;
}
.history-item .date { color: var(--muted); font-size: 12px; line-height: 16px; }
.history-item .eq { font-size: 20px; line-height: 28px; overflow-wrap: anywhere; letter-spacing: 0; }
.history-item .res { font-size: 22px; line-height: 28px; color: var(--primary); overflow-wrap: anywhere; letter-spacing: 0; }

.average-list { max-height: 380px; gap: 4px; }
.average-item {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}
.average-item .index { color: var(--muted); font-size: 13px; }
.average-item .value { font-size: 22px; line-height: 28px; flex: 1; letter-spacing: 0; overflow-wrap: anywhere; }

/* AlertDialog uses Material's default container, not the app's surface color. */
.dialog.alert {
  background: var(--surface-container-high);
  border-radius: 28px;
  min-width: min(280px, calc(100vw - 48px));
}
.alert-title { font-size: 24px; line-height: 32px; font-weight: 400; letter-spacing: 0; }
.color-scroll {
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  color: var(--muted);
}

.sv-pad {
  --hue-color: #f00;
  position: relative;
  width: 100%;
  aspect-ratio: 1.3;
  border-radius: 12px;
  flex: none;
  touch-action: none;
  cursor: crosshair;
  background:
    linear-gradient(to bottom, transparent, #000),
    linear-gradient(to right, #fff, var(--hue-color));
}
.sv-thumb {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #000;
  box-shadow: inset 0 0 0 2px #fff;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.hue-wrap { position: relative; height: 44px; flex: none; display: grid; align-items: center; }
.hue-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 16px;
  border-radius: 8px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.hue-slider { position: relative; --thumb: #f00; }
.hue-slider::-webkit-slider-runnable-track { height: 16px; background: transparent; }
.hue-slider::-moz-range-track { height: 16px; background: transparent; }
.hue-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -2px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
  background: var(--thumb);
}
.hue-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
  background: var(--thumb);
}

.text-field { position: relative; display: block; padding-top: 8px; flex: none; }
.text-field-label {
  position: absolute;
  top: 0;
  left: 12px;
  padding: 0 4px;
  font-size: 12px;
  line-height: 16px;
  color: var(--muted);
  background: var(--surface-container-high);
}
.text-field-box {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 16px;
  border: 1px solid var(--outline);
  border-radius: 4px;
}
.text-field:focus-within .text-field-box { border: 2px solid var(--primary); padding: 0 15px; }
.text-field:focus-within .text-field-label { color: var(--primary); }
.text-field.error .text-field-box { border-color: var(--error); }
.text-field.error .text-field-label { color: var(--error); }
.text-field-prefix { color: var(--muted); margin-right: 2px; }
.text-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  letter-spacing: inherit;
  padding: 0;
}

.preview { display: flex; flex-direction: column; gap: 8px; flex: none; }
.preview h3 { color: var(--fg); }
.preview-box {
  --pick: #CAEFAC;
  --pick-on: #000;
  --pick-container: rgba(202, 239, 172, 0.16);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--outline-variant);
  background: var(--bg);
}
.preview-text { flex: 1; font-size: 20px; line-height: 28px; letter-spacing: 0; }
.preview-eq { color: var(--fg); }
.preview-res { color: var(--pick); }
.preview-key {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 22px;
  flex: none;
}
.preview-key.op { background: var(--pick-container); color: var(--pick); }
.preview-key.eq { background: var(--pick); color: var(--pick-on); }

/* ---------- Install banner ---------- */

.install-banner {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  width: calc(100vw - 32px);
  max-width: 480px;
  padding: 16px 16px 8px 24px;
  border-radius: 24px;
  background: var(--surface-container-high);
  color: var(--fg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.install-banner p { margin: 0 8px 4px 0; }
.install-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
