/* =========================================================
   PixelCode — Stylesheet
   Design: deep navy "code lab" theme with a three-colour pixel
   accent (electric blue / mint / amber), swapping to a soft
   paper light theme. System fonts only (fully offline).
   ========================================================= */

:root {
  --font-ui: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue",
             Roboto, "Noto Sans Bengali", "Nirmala UI", "Hind Siliguri", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas,
               "Noto Sans Mono", monospace;

  --accent-blue: #5B8DEF;
  --accent-mint: #6EE7B7;
  --accent-amber: #F2C14E;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow-1: 0 1px 2px rgba(0,0,0,.24), 0 8px 24px -8px rgba(0,0,0,.35);
  --shadow-card: 0 1px 3px rgba(0,0,0,.06), 0 10px 28px -14px rgba(0,0,0,.35);

  color-scheme: dark;
}

/* ---- Dark theme (default) ---- */
:root,
:root[data-theme="dark"] {
  --bg: #0F1420;
  --surface: #171E2E;
  --surface-2: #1E2740;
  --surface-3: #263252;
  --text: #E9ECF3;
  --text-muted: #8C96AC;
  --border: rgba(255,255,255,.09);
  --border-strong: rgba(255,255,255,.16);
  --danger: #F4726A;
}

/* ---- Light theme ---- */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F3F5FA;
  --surface: #FFFFFF;
  --surface-2: #EEF1F8;
  --surface-3: #E3E8F3;
  --text: #141826;
  --text-muted: #616B82;
  --border: rgba(20,24,38,.09);
  --border-strong: rgba(20,24,38,.16);
  --danger: #C6362F;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  font-family: var(--font-ui);
  color: var(--text);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

html { scroll-padding-top: env(safe-area-inset-top, 0px); }

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

button {
  font-family: inherit;
  cursor: pointer;
}

/* ===================== TOPBAR ===================== */
.topbar {
  position: sticky;
  top: 0;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 8px);
  grid-template-rows: repeat(2, 8px);
  gap: 3px;
}
.brand-mark span { border-radius: 2px; }
.brand-mark span:nth-child(1) { background: var(--accent-blue); }
.brand-mark span:nth-child(2) { background: var(--accent-mint); }
.brand-mark span:nth-child(3) { background: var(--accent-amber); }
.brand-mark span:nth-child(4) { background: var(--accent-blue); opacity: .5; }

.brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.chip-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}
.chip-btn:hover { background: var(--surface-3); }
.icon-btn {
  padding: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===================== TABS ===================== */
.tabbar {
  position: relative;
  display: flex;
  max-width: 420px;
  margin: 22px auto 0;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tab {
  position: relative;
  z-index: 1;
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 999px;
  transition: color .2s ease;
}
.tab.active { color: var(--bg); }
:root[data-theme="light"] .tab.active { color: #fff; }

.tab-indicator {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-mint));
  border-radius: 999px;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}

/* ===================== LAYOUT ===================== */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 18px 60px;
}

.panel { display: none; }
.panel.active { display: block; animation: fadeIn .25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
}

/* ===================== DROPZONE ===================== */
.dropzone {
  text-align: center;
  border: 1.5px dashed var(--border-strong);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dropzone:hover,
.dropzone:focus-visible { border-color: var(--accent-blue); }
.dropzone.drag-over {
  border-color: var(--accent-mint);
  background: color-mix(in srgb, var(--accent-mint) 8%, var(--surface));
}

.dz-content { padding: 20px 10px; }
.dz-icon { color: var(--accent-blue); margin-bottom: 10px; }
.dz-title { font-weight: 600; margin: 0 0 4px; font-size: 15px; }
.dz-sub { color: var(--text-muted); font-size: 13px; margin: 0; }

.dz-preview { width: 100%; }
.dz-preview img {
  max-height: 220px;
  margin: 0 auto 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  object-fit: contain;
  background: var(--surface-2);
}
.dz-preview-info {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
#previewName { color: var(--text); font-weight: 600; }

/* ===================== BUTTONS ===================== */
.actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-mint));
  color: #0B0F1A;
  border: none;
  font-weight: 700;
  font-size: 14px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  flex: 1;
  min-width: 160px;
  transition: opacity .15s ease, transform .1s ease;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
}
.btn-ghost:hover { background: var(--surface-3); }
.btn-ghost.small { padding: 8px 12px; font-size: 13px; }

/* ===================== OUTPUT / CODE ===================== */
.output-card { margin-top: 4px; }
.output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.output-head h2 { margin: 0; font-size: 16.5px; font-weight: 700; letter-spacing: -0.01em; }

.stat-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.pill small { font-family: var(--font-ui); }

.code-area {
  width: 100%;
  min-height: 140px;
  max-height: 300px;
  resize: vertical;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  padding: 14px;
  word-break: break-all;
  margin-bottom: 14px;
}
.code-area:focus { outline: none; border-color: var(--border-strong); }

/* জেনারেট হওয়া কোড কপি প্রতিরোধ — টেক্সট সিলেক্ট, রাইট-ক্লিক মেনু বন্ধ থাকবে,
   শুধু ডাউনলোড বাটন দিয়েই কোড বের করা যাবে */
.code-area.no-copy {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  cursor: default;
}

.hint-msg {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: -6px 0 14px;
}

/* ===================== RESTORE PANEL ===================== */
.restored-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
  margin-bottom: 12px;
}
.restored-preview img { max-height: 280px; margin: 0 auto; border-radius: var(--radius-sm); }

.error-msg {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  margin: 12px 0 0;
}

/* ===================== TOAST ===================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 16px);
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-1);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===================== LOADING OVERLAY ===================== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 60;
}
/* author CSS beats the UA [hidden] rule on specificity ties, so this
   explicit override is required or the overlay stays visible (and
   keeps blocking every click) even while the `hidden` attribute is set */
.loading-overlay[hidden] { display: none; }
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent-blue);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 420px) {
  .actions-row { flex-direction: column; }
  .btn-primary, .btn-ghost { width: 100%; }
}

/* ===================== ACCESSIBILITY ===================== */
:focus,
:focus-visible {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
