:root {
  --bg: #f6f1e8;
  --surface: #ffffff;
  --ink: #1f2937;
  --ink-muted: #6b7280;
  --border: #e6dfd1;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #e6f4f1;
  --accent: #b45309;
  --danger: #b91c1c;
  --shadow: 0 6px 24px rgba(17, 24, 39, 0.06);
  --radius: 14px;
  --font-en: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-te: "Noto Sans Telugu", "Inter", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-en);
  color: var(--ink);
  background: linear-gradient(180deg, #faf6ec 0%, #f2ead9 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body[data-lang="te"] {
  font-family: var(--font-te);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--primary-ink);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.brand-text h1 {
  font-size: 1.15rem;
  margin: 0;
  line-height: 1.1;
}

.brand-text p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  background: #fbf7ee;
}

.lang-btn {
  border: 0;
  background: transparent;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink-muted);
  font-family: inherit;
}

.lang-btn.active {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: var(--shadow);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

.card h3 {
  margin: 1.25rem 0 0.75rem;
  font-size: 1rem;
  color: var(--ink-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (max-width: 640px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field span {
  font-size: 0.85rem;
  color: var(--ink-muted);
  font-weight: 500;
}

.field input {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fbf7ee;
  font-family: inherit;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: #fff;
}

.hint {
  font-size: 0.85rem;
  color: var(--accent);
  min-height: 1.1em;
  font-weight: 500;
}

.actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.btn {
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.05s, background 0.15s, border-color 0.15s;
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-ink);
}

.btn.primary:hover {
  background: #0b5f59;
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}

.btn.ghost:hover {
  background: #f5efe0;
}

.btn:active {
  transform: translateY(1px);
}

.form-error {
  color: var(--danger);
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  min-height: 1.2em;
}

.hidden {
  display: none;
}

.results .summary-top {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--primary-soft);
  color: #0b5148;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-size: 0.95rem;
}

.pill-label {
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.pill-value {
  font-weight: 600;
}

.periods {
  display: grid;
  gap: 0.75rem;
}

.period {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  background: #fbf7ee;
}

.period.leftover {
  border-color: #e0b877;
  background: #fdf5e5;
}

.period-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.period-title {
  font-weight: 600;
}

.period-span {
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.period-lines {
  display: grid;
  gap: 0.25rem;
  font-size: 0.95rem;
}

.period-lines .row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.period-lines .row span:first-child {
  color: var(--ink-muted);
}

.period-lines .row.total span:last-child {
  font-weight: 700;
}

.summary-final {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
  display: grid;
  gap: 0.4rem;
}

.final-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 1rem;
}

.final-row.grand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
}

.foot {
  text-align: center;
  padding: 1.5rem;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  .topbar {
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }
  .brand-text h1 {
    font-size: 1rem;
  }
  .brand-text p {
    font-size: 0.75rem;
  }
  .logo {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }
  .lang-btn {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
  }
  .container {
    padding: 1rem;
    gap: 1rem;
  }
  .card {
    padding: 1.1rem;
    border-radius: 12px;
  }
  .card h2 {
    font-size: 1.1rem;
  }
  .actions {
    flex-direction: column;
  }
  .btn {
    width: 100%;
  }
  .period-lines .row {
    flex-wrap: wrap;
  }
  .period-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }
}