:root {
  --bg: #0e1116;
  --panel: #161b22;
  --key: #1b2330;
  --key-2: #222c3b;
  --line: #28323f;
  --text: #f2f6fb;
  --muted: #8a99ad;
  --accent: #16c784;
  --accent-press: #12a76d;
  --accent-ink: #04130d;
  --post: #f7b733;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Root font scales with screen width, so every rem-based size grows on big
   phones (iPhone Pro Max) and shrinks on small ones — fully adaptive. */
html { font-size: clamp(16px, 4.5vw, 23px); }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}
button { font-family: inherit; touch-action: manipulation; }

.calc {
  height: 100dvh;
  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);
}

/* ---------------- DISPLAY ---------------- */
.display {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px 8px;
}
.gear {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
}
.gear:active { background: var(--key-2); }

.display__results {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
}
.kv { display: flex; flex-direction: column; }
.kv__k { font-size: 0.72rem; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.kv__k em { font-style: normal; color: var(--accent); font-weight: 800; }
.kv__v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 1px; }

.display__total { display: flex; flex-direction: column; margin-top: 2px; }
.display__label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.display__big {
  font-size: clamp(3rem, 17vw, 5.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.02;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.display__base {
  align-self: flex-start;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
  text-align: left;
}
.display__base #baseText {
  color: var(--text);
  border-bottom: 1px dashed var(--muted);
  padding-bottom: 1px;
}
.display__alt { color: var(--post); font-weight: 700; }

.display__input {
  margin-top: auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 2px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.display__in-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.display__in-val {
  font-size: 1.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------------- CONTROLS ---------------- */
.controls {
  flex: 0 0 auto;
  padding: 6px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.t {
  border: 1px solid var(--line);
  background: var(--key);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 800;
  padding: 11px 0;
  border-radius: 12px;
  cursor: pointer;
}
.t::after { content: "%"; font-size: 0.7em; opacity: .6; margin-left: 1px; }
.t.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.t:active { transform: scale(0.96); }

.taxchip {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--key);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  padding: 13px 16px;
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
}
.taxchip:active { background: var(--key-2); }
.taxchip.is-off { color: var(--muted); }

/* ---------------- KEYPAD ---------------- */
.pad {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 6px 12px calc(10px + env(safe-area-inset-bottom));
}
.pad button {
  border: 0;
  border-radius: 16px;
  background: var(--key);
  color: var(--text);
  font-size: 1.9rem;
  font-weight: 600;
  height: clamp(52px, 9.3vh, 100px);
  cursor: pointer;
}
.pad button:active { background: var(--accent); color: var(--accent-ink); }
.pad .k-sub { background: var(--key-2); }
.pad .k-del { color: var(--muted); font-size: 1.5rem; }
.pad .k-del:active { background: var(--danger); color: #fff; }

/* ---------------- SETTINGS SHEET ---------------- */
.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 20;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 21;
  background: var(--panel);
  border-radius: 22px 22px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
  animation: slideup .26s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet__grip {
  width: 40px; height: 4px; border-radius: 99px;
  background: var(--line); margin: 6px auto 14px;
}
.sheet__sect { padding: 6px 0 14px; border-bottom: 1px solid var(--line); }
.sheet__sect:last-of-type { border-bottom: 0; }
.sheet h2 { margin: 0 0 10px; font-size: 0.95rem; }
.sheet__row { display: flex; align-items: center; justify-content: space-between; }
.sheet__row h2 { margin: 0; }
.sheet__row--rate { margin-top: 12px; }
.sheet__lab { font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.sheet__hint { margin: 0 0 12px; font-size: 0.82rem; line-height: 1.45; color: var(--muted); }

.rate { display: inline-flex; align-items: center; gap: 4px; background: var(--key); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.rate button { width: 40px; height: 36px; border: 0; border-radius: 9px; background: var(--key-2); color: var(--text); font-size: 1.3rem; font-weight: 700; cursor: pointer; }
.rate button:active { background: var(--accent); color: var(--accent-ink); }
.rate > span { min-width: 64px; text-align: center; font-weight: 800; }

.quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.quick button {
  border: 1px solid var(--line); background: var(--key); color: var(--text);
  font-size: 0.88rem; font-weight: 700; padding: 11px 8px; border-radius: 11px; cursor: pointer;
}
.quick button.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.quick button:active { transform: scale(0.97); }

.seg2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg2 button {
  border: 1px solid var(--line); background: var(--key); color: var(--text);
  font-size: 0.9rem; font-weight: 700; padding: 13px 8px; border-radius: 12px; cursor: pointer;
}
.seg2 button.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.rev {
  display: flex; align-items: center; gap: 6px;
  background: var(--key); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 14px;
}
.rev__sym { color: var(--muted); font-size: 1.2rem; font-weight: 700; }
.rev input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
  font-size: 1.3rem; font-weight: 700; padding: 12px 0; outline: none;
  -webkit-user-select: text; user-select: text;
}
.rev__out { margin: 10px 2px 0; font-size: 0.9rem; line-height: 1.45; color: var(--muted); min-height: 1.2em; }
.rev__out b { color: var(--text); }
.rev__out .tag { display: inline-block; font-weight: 800; padding: 1px 9px; border-radius: 99px; font-size: .82rem; }
.rev__out .tag--pre { background: rgba(22,199,132,.18); color: var(--accent); }
.rev__out .tag--post { background: rgba(247,183,51,.18); color: var(--post); }

.sheet__done {
  width: 100%; margin-top: 18px;
  border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 1.05rem; font-weight: 800; padding: 15px; cursor: pointer;
}
.sheet__done:active { background: var(--accent-press); }

.is-hidden { display: none !important; }
