:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --text: #e8eaf0;
  --text-muted: #7c7f93;
  --error: #f04747;
  --warning: #faa61a;
  --success: #43b581;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app-header { text-align: center; margin-bottom: 0.25rem; }
.app-header h1 { margin: 0; font-size: 1.75rem; letter-spacing: -0.02em; }
.subtitle { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.9rem; }

.muted { color: var(--text-muted); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

/* ===== Banners ===== */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.banner-error {
  background: rgba(240, 71, 71, 0.12);
  border: 1px solid rgba(240, 71, 71, 0.3);
  color: var(--error);
}
.banner-info {
  background: rgba(88, 101, 242, 0.12);
  border: 1px solid rgba(88, 101, 242, 0.3);
  color: var(--text);
}
.banner-warning {
  background: rgba(250, 166, 26, 0.12);
  border: 1px solid rgba(250, 166, 26, 0.3);
  color: var(--warning);
  margin-top: 0.75rem;
}
.banner-dismiss {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  min-height: 44px;
}

/* ===== Buttons ===== */
.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 6px;
  min-height: 44px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-big { min-height: 52px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ===== Empty state ===== */
.choose-card {
  width: 100%;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  padding: 2.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.choose-card:active { border-color: var(--accent); }
.choose-icon { color: var(--accent); }
.choose-title { font-size: 1.2rem; font-weight: 600; }
.choose-hint { color: var(--text-muted); font-size: 0.9rem; }

.install-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

/* ===== Loaded state ===== */
.original-card {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.thumb {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--bg);
}
.original-meta { min-width: 0; }
.file-name {
  margin: 0 0 0.25rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.original-meta .muted { margin: 0; font-size: 0.9rem; }

/* ===== Sliders ===== */
.slider-card { display: flex; flex-direction: column; gap: 1.25rem; }
.slider-row { display: flex; flex-direction: column; gap: 0.4rem; }
.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.9rem;
}
.slider-label label { color: var(--text-muted); font-weight: 600; }
.readout { font-variant-numeric: tabular-nums; font-weight: 600; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;            /* full 44px touch area */
  background: transparent;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  margin-top: -11px;       /* center 28px thumb on 6px track */
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
}
input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
}

.size-line {
  margin: 0;
  text-align: center;
  font-size: 1rem;
  min-height: 1.4em;
}
.size-estimate { font-variant-numeric: tabular-nums; }
.size-estimate.estimating { color: var(--text-muted); }
.size-estimate .saved { color: var(--success); }
.size-estimate .grew { color: var(--warning); }

/* ===== Target size mode ===== */
.target-mode summary {
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.target-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
#target-size {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 0 0.75rem;
  min-height: 44px;
}
.target-unit { color: var(--text-muted); }
.target-row .btn { width: auto; padding: 0 1rem; }
.target-status { font-size: 0.85rem; margin: 0.5rem 0 0; }

/* ===== Result state ===== */
.result-preview {
  width: 100%;
  border-radius: 6px;
  background: var(--bg);
}
.result-stats { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; }
.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.saved { color: var(--success); font-weight: 600; }

/* ===== Long-press overlay ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 17, 23, 0.97);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: calc(env(safe-area-inset-top) + 1rem) 1rem calc(env(safe-area-inset-bottom) + 1rem);
}
.overlay-instruction { text-align: center; margin: 0; }
#overlay-img {
  max-width: 100%;
  max-height: 65vh;
  border-radius: var(--radius);
}
.overlay .btn { max-width: 200px; }
