:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg-elevated: #1a1d24;
  --bg-card: #1a1e27;
  --accent: #4f8cff;
  --accent-2: #34d399;
  --accent-3: #a78bfa;
  --danger: #f4614a;
  --text: #eef1f6;
  --text-dim: #9aa3b2;
  --border: #2a2f3a;
  --radius: 16px;
  --grad-accent: linear-gradient(135deg, #4f8cff, #7c6bff);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 10px 24px -12px rgba(0,0,0,0.55);
  --shadow-btn: 0 8px 20px -8px rgba(79,140,255,0.55);
  --blob-1: rgba(79,140,255,0.16);
  --blob-2: rgba(167,139,250,0.13);
  --blob-3: rgba(52,211,153,0.08);
  --header-bg: rgba(26,29,36,0.75);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --accent: #3b6fe0;
  --accent-2: #199473;
  --accent-3: #7c5ce0;
  --danger: #e0483a;
  --text: #171a21;
  --text-dim: #666f7e;
  --border: #e1e5ee;
  --shadow-card: 0 1px 0 rgba(255,255,255,0.6) inset, 0 10px 24px -14px rgba(30,40,70,0.22);
  --shadow-btn: 0 8px 18px -9px rgba(59,111,224,0.45);
  --blob-1: rgba(79,140,255,0.10);
  --blob-2: rgba(124,92,224,0.08);
  --blob-3: rgba(25,148,115,0.07);
  --header-bg: rgba(255,255,255,0.72);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s ease, color .2s ease;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  background:
    radial-gradient(560px 320px at 15% 0%, var(--blob-1), transparent 60%),
    radial-gradient(480px 300px at 100% 10%, var(--blob-2), transparent 55%),
    radial-gradient(520px 360px at 50% 100%, var(--blob-3), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Home screen */
.home-header {
  padding: 36px 22px 10px;
}

.home-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.app-badge {
  display: flex;
  align-items: center;
  margin-bottom: 14px;
}

.app-badge svg {
  height: 32px;
  width: auto;
  display: block;
}

.app-badge svg path {
  fill: var(--text);
  transition: fill .2s ease;
}

.home-header h1 {
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  background: linear-gradient(120deg, #ffffff 20%, #b9c6ff 60%, #a78bfa 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

:root[data-theme="light"] .home-header h1 {
  background: linear-gradient(120deg, #182238 15%, #3b6fe0 60%, #7c5ce0 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

.home-header p {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}

/* Theme + language controls */
.top-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  padding: 0;
  transition: transform .12s ease, border-color .12s ease;
}

.icon-btn:active { transform: scale(0.92); border-color: rgba(79,140,255,0.5); }

.lang-select {
  width: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 11px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  height: 36px;
}

.tool-header .top-controls {
  margin-left: auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding: 22px;
}

.card {
  background: linear-gradient(160deg, var(--bg-card), var(--bg-elevated));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  min-height: 128px;
  box-shadow: var(--shadow-card);
  transition: transform .15s cubic-bezier(.2,.7,.3,1), border-color .15s ease, box-shadow .15s ease;
}

.card:active {
  transform: scale(0.96);
  border-color: rgba(79,140,255,0.55);
  box-shadow: 0 0 0 1px rgba(79,140,255,0.25), var(--shadow-card);
}

.card .icon {
  font-size: 24px;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(79,140,255,0.18), rgba(167,139,250,0.12));
  border: 1px solid rgba(255,255,255,0.06);
}

.card .label {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.25;
}

.card .sub {
  font-size: 11.5px;
  color: var(--text-dim);
}

.footer-note {
  padding: 18px 26px 36px;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  line-height: 1.6;
}

/* Tool page layout */
.tool-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  position: sticky;
  top: 0;
  z-index: 10;
}

.back-btn {
  font-size: 20px;
  padding: 6px 10px;
  margin-left: -10px;
  border-radius: 10px;
  transition: background .12s ease;
}

.back-btn:active { background: var(--bg-card); }

.tool-header h2 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  flex: 1;
}

.tool-body {
  flex: 1;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: linear-gradient(160deg, var(--bg-card), var(--bg-elevated));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--grad-accent);
  color: #06121f;
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: 13px;
  padding: 13px 18px;
  cursor: pointer;
  width: 100%;
  box-shadow: var(--shadow-btn);
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}

.btn:active {
  transform: scale(0.97);
  box-shadow: 0 4px 12px -6px rgba(79,140,255,0.55);
  opacity: 0.92;
}

.btn.secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn.secondary:active { box-shadow: none; }

.btn.danger { background: linear-gradient(135deg, #f4614a, #ff8a65); color: #21100c; box-shadow: 0 8px 20px -8px rgba(244,97,74,0.5); }
.btn.success { background: linear-gradient(135deg, #34d399, #4fe0b0); color: #05221a; box-shadow: 0 8px 20px -8px rgba(52,211,153,0.5); }

.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row .btn { flex: 1; }

video, canvas, img.preview {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  display: block;
}

.video-wrap {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
}

textarea, select, input[type="text"], input[type="number"] {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

label {
  font-size: 13px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 6px;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.hint {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.status {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.status.ok { border-color: rgba(52,211,153,0.5); color: var(--accent-2); background: rgba(52,211,153,0.08); }
.status.warn { border-color: rgba(244,97,74,0.5); color: var(--danger); background: rgba(244,97,74,0.08); }

.result-box {
  font-size: 22px;
  font-weight: 700;
  word-break: break-word;
  padding: 14px;
  background: var(--bg-elevated);
  border-radius: 10px;
  border: 1px solid var(--border);
  min-height: 28px;
}

.center { text-align: center; }
.hidden { display: none !important; }

.mirror-video {
  transform: scaleX(-1);
}
