*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

:root, [data-theme="dark"] {
  --bg: #0b1020;
  --panel: #121a2d;
  --panel-2: #18233c;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #2d3f5e;
  --accent: #4d7cff;
  --accent-2: #7ce0ff;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 10px 30px rgba(0,0,0,0.4);
  --radius: 14px;
}

[data-theme="light"] {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-2: #eef3fb;
  --text: #172033;
  --muted: #5f6b85;
  --border: #d7dfef;
  --accent: #4d7cff;
  --accent-2: #0ea5e9;
  --good: #15803d;
  --warn: #b45309;
  --bad: #dc2626;
  --shadow: 0 10px 30px rgba(19,31,55,0.08);
}

button, input, textarea, select { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
textarea { resize: vertical; }

.hidden { display: none !important; }

/* Layout */
#app {
  width: min(1400px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

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

.app-title { margin: 0; font-size: 1.2rem; font-weight: 700; }
.app-subtitle { margin: 0; color: var(--muted); font-size: 0.85rem; }

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

/* Auth */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 120px);
}

.auth-panel {
  width: 100%;
  max-width: 360px;
}

.auth-panel h2 { margin: 0 0 6px; font-size: 1.4rem; }
.auth-panel .lead { color: var(--muted); margin: 0 0 24px; font-size: 0.9rem; }

/* Passcode field */
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field span { font-size: 0.88rem; color: var(--muted); }

#passcode {
  width: 100%;
  padding: 14px;
  font-size: 1.6rem;
  letter-spacing: 0.4em;
  text-align: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  caret-color: var(--accent);
}
#passcode:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(77,124,255,0.15); }

/* Numpad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.numpad button {
  padding: 18px;
  font-size: 1.2rem;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.numpad button:hover { background: var(--border); }
.numpad button:active { background: var(--accent); color: #fff; transform: scale(0.96); }

/* Buttons */
.primary-btn, .secondary-btn, .ghost-btn, .file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 4px;
}
.primary-btn:hover { opacity: 0.88; }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.secondary-btn:hover { background: var(--border); }

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.ghost-btn:hover { color: var(--bad); border-color: var(--bad); }

.file-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
}
.file-btn:hover { background: var(--border); }

/* Status */
.status-text {
  font-size: 0.85rem;
  min-height: 1.4em;
  margin-top: 10px;
  color: var(--muted);
}

/* Icon button */
.icon-btn {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

/* App grid */
.app-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

/* Input panel */
.panel h2 { margin: 0 0 4px; font-size: 1.1rem; }
.panel .lead { color: var(--muted); font-size: 0.88rem; margin: 0 0 16px; }

textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  margin-bottom: 14px;
}
textarea:focus { border-color: var(--accent); }

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

/* Result cards */
.result-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.result-card:last-child { margin-bottom: 0; }
.result-card h3 { margin: 0 0 10px; font-size: 0.9rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.result-body { font-size: 0.9rem; line-height: 1.7; word-break: break-word; white-space: pre-wrap; }

/* Responsive */
@media (max-width: 768px) {
  .app-grid { grid-template-columns: 1fr; }
  .numpad button { padding: 14px; font-size: 1rem; }
}
