/* ── Design tokens ── */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;

  --blue-400: #3b9eff;
  --blue-500: #1a7fd4;
  --blue-600: #0d5fa8;
  --blue-glow: rgba(59, 158, 255, 0.22);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-bar-h: 64px;
  --app-max: 480px;

  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.14);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.2);

  color-scheme: dark light;
}

/* Dark (default) */
:root,
[data-theme="dark"] {
  --bg: #07111f;
  --bg-elevated: #0c1a2e;
  --surface: rgba(18, 32, 52, 0.92);
  --surface-2: rgba(24, 42, 68, 0.72);
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(59, 158, 255, 0.28);
  --text: #f1f5f9;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --primary: var(--blue-400);
  --primary-strong: var(--blue-500);
  --primary-on: #ffffff;
  --accent-soft: rgba(59, 158, 255, 0.12);
  --highlight: rgba(59, 158, 255, 0.16);
  --tab-bar-bg: rgba(7, 17, 31, 0.82);
  --input-bg: rgba(10, 22, 38, 0.88);
  --splash-bg: #07111f;
  --badge-soon: rgba(148, 163, 184, 0.14);
  --badge-soon-text: #94a3b8;
}

@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #eef2f7;
    --bg-elevated: #ffffff;
    --surface: #ffffff;
    --surface-2: #f4f7fb;
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(26, 127, 212, 0.28);
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --primary: var(--blue-500);
    --primary-strong: var(--blue-600);
    --primary-on: #ffffff;
    --accent-soft: rgba(26, 127, 212, 0.1);
    --highlight: rgba(26, 127, 212, 0.08);
    --tab-bar-bg: rgba(255, 255, 255, 0.88);
    --input-bg: #f8fafc;
    --splash-bg: #ffffff;
    --badge-soon: rgba(100, 116, 139, 0.12);
    --badge-soon-text: #64748b;
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.1);
  }
}

[data-theme="light"] {
  --bg: #eef2f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f7fb;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(26, 127, 212, 0.28);
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: var(--blue-500);
  --primary-strong: var(--blue-600);
  --primary-on: #ffffff;
  --accent-soft: rgba(26, 127, 212, 0.1);
  --highlight: rgba(26, 127, 212, 0.08);
  --tab-bar-bg: rgba(255, 255, 255, 0.88);
  --input-bg: #f8fafc;
  --splash-bg: #ffffff;
  --badge-soon: rgba(100, 116, 139, 0.12);
  --badge-soon-text: #64748b;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.1);
}

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

img {
  display: block;
  max-width: 100%;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
}

/* ── Splash ── */
.splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--splash-bg);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.splash--hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}

.splash-logo {
  width: 88px;
  height: 88px;
  object-fit: contain;
  border-radius: 22px;
  box-shadow: var(--shadow-md);
}

.splash-title {
  margin: 8px 0 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.splash-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.splash-loader {
  width: 28px;
  height: 28px;
  margin-top: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── App shell ── */
.app {
  width: min(100%, var(--app-max));
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 90% 40% at 50% -5%, var(--blue-glow), transparent 55%),
    var(--bg);
}

.app.is-hidden {
  visibility: hidden;
}

.app-main {
  flex: 1;
  min-height: 0;
  position: relative;
}

.page {
  display: none;
  height: 100%;
}

.page--active {
  display: block;
}

.page-scroll {
  padding: calc(12px + var(--safe-top)) 16px calc(var(--tab-bar-h) + var(--safe-bottom) + 20px);
}

/* ── Components ── */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.section-label {
  margin: 0 0 12px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: var(--primary-on);
  box-shadow: 0 8px 24px var(--blue-glow);
}

.btn--block {
  width: 100%;
}

.btn--ghost {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}

.btn--ghost.is-copied {
  border-color: rgba(34, 197, 94, 0.4);
  color: #22c55e;
}

.btn--sm {
  min-height: 40px;
}

/* ── Hero (Hesapla) ── */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
  padding: 8px 12px 0;
}

.hero-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 18px;
  box-shadow: var(--shadow-md);
}

.hero-title {
  margin: 14px 0 6px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.hero-lead {
  margin: 0;
  max-width: 320px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

/* ── Calculator form ── */
.calc-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.field-hint {
  font-style: normal;
  font-weight: 500;
  color: var(--muted);
}

.text-input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--input-bg);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.text-input::placeholder {
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: none;
}

.money-field {
  position: relative;
}

.money-input {
  width: 100%;
  min-height: 56px;
  padding: 0 44px 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--input-bg);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.money-field--accent .money-input {
  border-color: var(--border-strong);
  background: var(--highlight);
}

.money-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.money-suffix {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
}

.rate-field {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rate-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.rate-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--muted);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.rate-pill strong {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-2);
}

.rate-pill small {
  font-size: 11px;
  font-weight: 600;
}

.rate-pill.is-active {
  border-color: var(--border-strong);
  background: var(--highlight);
  box-shadow: 0 0 0 1px var(--accent-soft), var(--shadow-sm);
}

.rate-pill.is-active strong {
  color: var(--primary);
}

.rate-pill.is-active small {
  color: var(--primary);
  opacity: 0.85;
}

/* ── Result sheet (modal) ── */
.result-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.result-sheet:not([hidden]) {
  pointer-events: auto;
}

.result-sheet.is-open .result-sheet-backdrop {
  opacity: 1;
}

.result-sheet.is-open .result-sheet-panel {
  transform: translateY(0);
}

.result-sheet-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(2, 8, 18, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.28s ease;
  cursor: pointer;
}

.result-sheet-panel {
  position: relative;
  z-index: 1;
  width: min(100%, var(--app-max));
  max-height: min(88dvh, 640px);
  overflow-y: auto;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  border-radius: 28px 28px 0 0;
  border: 1px solid var(--border);
  border-bottom: 0;
  background: var(--bg-elevated);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28);
  transform: translateY(105%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

.result-sheet-handle {
  width: 40px;
  height: 4px;
  margin: 6px auto 16px;
  border-radius: 999px;
  background: var(--border);
}

.result-sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.result-sheet-head-copy {
  min-width: 0;
}

.result-sheet-badge {
  display: inline-block;
  margin-bottom: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.result-sheet-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.result-sheet-plaka {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-sheet-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
}

.result-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.result-sheet-actions .btn--ghost {
  margin-top: 0;
  min-height: 48px;
  border-radius: var(--radius-md);
}

body.sheet-open {
  overflow: hidden;
}

/* ── Results ── */
.result-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.result-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.result-card--highlight {
  grid-column: 1 / -1;
  padding: 18px;
  border-color: var(--border-strong);
  background: linear-gradient(160deg, var(--highlight), var(--surface));
  box-shadow: var(--shadow-md);
}

.result-card-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.result-card-value {
  display: block;
  font-size: clamp(18px, 5vw, 22px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.result-card-value--lg {
  font-size: clamp(26px, 7vw, 32px);
  color: var(--primary);
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50dvh;
  padding: 32px 24px;
  text-align: center;
}

.empty-state-icon {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  border-radius: 22px;
  background: var(--accent-soft);
  color: var(--primary);
}

.empty-state-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 800;
}

.empty-state-text {
  margin: 0;
  max-width: 260px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* ── History ── */
.history-header {
  margin-bottom: 16px;
  padding: 4px 4px 0;
}

.history-title {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.history-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-card {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.history-card-main {
  flex: 1;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.history-card-main:active {
  transform: scale(0.99);
  border-color: var(--border-strong);
}

.history-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.history-card-plaka {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.history-card-date {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.history-card-value {
  display: block;
  margin-bottom: 6px;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.history-card-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.history-card-delete {
  flex-shrink: 0;
  width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--muted);
}

.history-card-delete:active {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.35);
}

#page-history .empty-state {
  min-height: 42dvh;
}

/* ── Tools ── */
.tool-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tool-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: transform 0.15s ease;
}

.tool-card--active {
  border-color: var(--border-strong);
  background: linear-gradient(135deg, var(--highlight), var(--surface));
}

.tool-card--disabled {
  opacity: 0.72;
  cursor: default;
}

.tool-card:not(.tool-card--disabled):active {
  transform: scale(0.99);
}

.tool-card-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--muted);
}

.tool-card-icon--blue {
  background: var(--accent-soft);
  color: var(--primary);
}

.tool-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tool-card-body strong {
  font-size: 15px;
  font-weight: 700;
}

.tool-card-body small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tool-card-badge {
  flex-shrink: 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--badge-soon);
  color: var(--badge-soon-text);
  font-size: 11px;
  font-weight: 700;
}

.tool-card-badge--active {
  background: var(--accent-soft);
  color: var(--primary);
}

/* ── About ── */
.about-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 28px 20px;
  margin-bottom: 14px;
}

.about-logo {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 24px;
  box-shadow: var(--shadow-md);
}

.about-app-name {
  margin: 16px 0 8px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.about-tagline {
  margin: 0;
  max-width: 300px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.about-version {
  display: inline-block;
  margin-top: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.about-block {
  padding: 18px;
  margin-bottom: 14px;
}

.about-block-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
}

.about-text {
  margin: 0;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.6;
}

.about-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 0;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  border-top: 1px solid var(--border);
}

.about-link:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.about-link-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--primary);
}

.about-footer {
  margin: 8px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

/* ── Tab bar ── */
.tab-bar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  transform: translateX(-50%);
  width: min(100%, var(--app-max));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: calc(var(--tab-bar-h) + var(--safe-bottom));
  padding: 6px 8px calc(6px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--tab-bar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 52px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  transition: color 0.15s ease, background 0.15s ease;
}

.tab-item.is-active {
  color: var(--primary);
  background: var(--accent-soft);
}

.tab-icon {
  flex-shrink: 0;
}

.tab-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ── Utilities ── */
[hidden] {
  display: none !important;
}

@media (min-width: 481px) {
  body {
    background: #03080f;
  }

  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }

  .tab-bar {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
