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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2e3147;
  --accent: #5b7fe8;
  --accent-hover: #4a6dd4;
  --text: #e2e4f0;
  --muted: #7a7f99;
  --error: #e05c5c;
  --success: #4caf7d;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 2rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
  position: relative;
}

.header-nav { position: absolute; top: 0; right: 0; display: flex; gap: 0.5rem; }
.header-nav-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: 0.8rem; padding: 0.35rem 0.75rem; cursor: pointer;
  transition: all 0.15s;
}
.header-nav-btn:hover { color: var(--text); border-color: var(--accent); }

.app-banner {
  display: block; max-width: 100%; width: 400px; height: auto;
  margin: 0 auto 1rem; border-radius: var(--radius); border: 1px solid var(--border);
}

header h1 { font-size: 2rem; letter-spacing: -0.5px; }
.subtitle { color: var(--muted); font-size: 0.9rem; margin-top: 0.3rem; }

.page-body { display: flex; justify-content: center; align-items: flex-start; gap: 1.5rem; }

main {
  max-width: 640px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: max-width 0.15s;
}

main.admin-wide { max-width: 960px; }

/* Left-hand step rail (Encrypt/Decrypt wizard progress) */
.step-rail { display: flex; flex-direction: column; gap: 1.25rem; padding-top: 1.5rem; flex-shrink: 0; }
.step-circle {
  width: 2rem; height: 2rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--border); color: var(--muted); font-weight: 600; font-size: 0.9rem;
  transition: all 0.15s;
  background: transparent; padding: 0; font-family: inherit; cursor: pointer;
}
.step-circle:hover { border-color: var(--accent); color: var(--accent); }
.step-node.active .step-circle { border-color: var(--accent); color: var(--accent); background: rgba(91,127,232,0.12); }

/* Intro / choice screen */
.intro-question { text-align: center; font-size: 1.1rem; margin-bottom: 1.5rem; }
.choice-row { display: flex; flex-wrap: wrap; gap: 1rem; }
.choice-btn {
  flex: 1 1 140px; display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 1.5rem 1rem; cursor: pointer; transition: all 0.15s;
}
.choice-btn:hover { border-color: var(--accent); background: rgba(91,127,232,0.1); }
.choice-title { font-size: 1.1rem; font-weight: 600; color: var(--accent); }
.choice-desc { font-size: 0.85rem; color: var(--muted); text-align: center; }

.back-link {
  background: none; border: none; color: var(--muted); font-size: 0.85rem;
  cursor: pointer; margin-bottom: 1rem; padding: 0;
}
.back-link:hover { color: var(--text); }

/* Tabs */
.tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.75rem; }
.tab-btn, .app-nav-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--muted); padding: 0.4rem 1.2rem; cursor: pointer; font-size: 0.95rem; transition: all 0.15s;
}
.tab-btn.active, .tab-btn:hover, .app-nav-btn.active, .app-nav-btn:hover { color: var(--text); background: var(--border); }
.tab-btn.active, .app-nav-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(91,127,232,0.1); }

/* Header app-nav (Encrypt / Decrypt / Example / Home, shown while in view-app or view-why) */
.app-nav { display: flex; justify-content: center; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }
.home-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.4rem 0.6rem; }
.home-btn svg { width: 18px; height: 18px; display: block; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.admin-tab-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--muted); padding: 0.4rem 1.2rem; cursor: pointer; font-size: 0.95rem; transition: all 0.15s;
}
.admin-tab-btn.active, .admin-tab-btn:hover { color: var(--text); background: var(--border); }
.admin-tab-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(91,127,232,0.1); }

.admin-tab-panel { display: none; }
.admin-tab-panel.active { display: block; }

/* Wizard steps (Encrypt/Decrypt tabs) */
.step-panel { margin-bottom: 1rem; }
.wizard-nav { display: flex; justify-content: space-between; gap: 0.75rem; margin-top: 1.25rem; }
.wizard-nav.wizard-nav-end { justify-content: flex-end; }

.subtabs { margin-bottom: 1rem; }
.subtab-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--muted); padding: 0.4rem 1.2rem; cursor: pointer; font-size: 0.95rem; transition: all 0.15s;
}
.subtab-btn.active, .subtab-btn:hover { color: var(--text); background: var(--border); }
.subtab-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(91,127,232,0.1); }
.subtab-count { color: var(--muted); font-size: 0.8rem; }

.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

/* Emoji cover-style picker (Encrypt Options step) */
.emoji-picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr));
  gap: 0.4rem; margin-top: 0.75rem;
}
.emoji-btn {
  width: 2.75rem; height: 2.75rem; font-size: 1.4rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: all 0.15s;
}
.emoji-btn:hover { border-color: var(--accent); background: rgba(91,127,232,0.1); }
.emoji-btn.active { border-color: var(--accent); background: rgba(91,127,232,0.15); }

/* Post-completion menu (inside encode-result / decode-result) */
.post-menu { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }

/* Fields */
.field-group { margin-bottom: 1rem; }
.field-group label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; }

input[type="password"],
input[type="text"],
input[type="email"],
input[type="number"],
select,
textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); padding: 0.6rem 0.8rem;
  font-size: 0.95rem; outline: none; transition: border-color 0.15s;
  font-family: inherit;
}
input[type="password"]:focus, input[type="email"]:focus, input[type="number"]:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }

.field-row { display: flex; gap: 0.5rem; align-items: center; }
.field-row input { flex: 1; }

.file-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }

/* Drag-and-drop upload zones */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.75rem 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: center;
  transition: border-color 0.15s, background-color 0.15s;
}
.dropzone-icon { width: 26px; height: 26px; color: var(--muted); pointer-events: none; }
.dropzone-text { margin: 0; font-size: 0.9rem; color: var(--muted); pointer-events: none; }
.dropzone-link { color: var(--accent); text-decoration: underline; }
.dropzone:hover { border-color: var(--accent); background: rgba(91,127,232,0.06); }
.dropzone.dragover { border-color: var(--accent); background: rgba(91,127,232,0.12); }
.dropzone.has-file { border-style: solid; border-color: var(--accent); }
.dropzone-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}

.radio-row { display: flex; gap: 1.5rem; }
.radio-row label { display: flex; align-items: center; gap: 0.4rem; color: var(--text); cursor: pointer; font-size: 0.95rem; }

.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-row input { width: auto; }
.checkbox-row label { color: var(--text); font-size: 0.9rem; margin: 0; }

/* Buttons */
.primary-btn {
  width: 100%; padding: 0.7rem; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); font-size: 1rem; cursor: pointer;
  transition: background 0.15s; margin-top: 0.5rem;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn {
  padding: 0.6rem 0.9rem; background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem;
  cursor: pointer; transition: border-color 0.15s;
}
.secondary-btn:hover:not(:disabled) { border-color: var(--accent); }
.secondary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Progress */
.progress { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.75rem; color: var(--muted); font-size: 0.9rem; }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Feedback */
.error { color: var(--error); font-size: 0.9rem; margin-top: 0.6rem; }
.info  { color: var(--muted); font-size: 0.85rem; margin-top: 0.4rem; }
.result { margin-top: 1rem; padding: 0.75rem 1rem; background: rgba(76,175,125,0.08); border: 1px solid var(--success); border-radius: var(--radius); }
.result p { color: var(--success); font-size: 0.9rem; margin-bottom: 0.4rem; }
.download-link { color: var(--accent); font-size: 0.9rem; text-decoration: none; }
.download-link:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* Sub-panels */
.sub-panel { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

/* Admin: user table */
.admin-table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: 0.85rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.admin-table td { color: var(--text); vertical-align: middle; }
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-admin { background: rgba(91,127,232,0.15); color: var(--accent); }
.badge-user { background: rgba(255,255,255,0.06); color: var(--muted); }
.badge-active { background: rgba(76,175,125,0.12); color: var(--success); }
.badge-invited { background: rgba(255,255,255,0.06); color: var(--muted); }
.badge-disabled { background: rgba(224,92,92,0.12); color: var(--error); }
.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.9rem; }

/* Admin: audit table */
.badge-expired { background: rgba(224,92,92,0.12); color: var(--error); }
.badge-indefinite { background: rgba(91,127,232,0.15); color: var(--accent); }
.password-cell { white-space: nowrap; }
.revealed-note { display: block; color: var(--muted); font-size: 0.7rem; margin-top: 0.15rem; }

.icon-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 0.2rem; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius); transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--accent); background: rgba(91,127,232,0.1); }
.icon-btn svg { width: 16px; height: 16px; display: block; }
.icon-btn.danger { color: var(--error); }
.icon-btn.danger:hover { color: var(--error); background: rgba(224,92,92,0.12); }

/* Password reveal modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal {
  position: relative; width: 90%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem;
}
.modal-close {
  position: absolute; top: 0.5rem; right: 0.75rem;
  background: none; border: none; color: var(--muted); font-size: 1.3rem;
  line-height: 1; cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.modal-password {
  font-family: monospace; font-size: 1.15rem; color: var(--text);
  word-break: break-all; margin: 0.6rem 0; padding: 0.6rem 0.8rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
}

/* Story / why-example page */
main.story { max-width: 620px; }

.story-title {
  font-size: 1.5rem; letter-spacing: -0.3px; margin: 0.75rem 0 1rem;
  background: linear-gradient(90deg, var(--text), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.story-lead { font-size: 1.05rem; color: var(--text); line-height: 1.6; margin-bottom: 1.25rem; }
.story-kicker { color: var(--accent); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.75rem; }
.story-body { color: var(--text); line-height: 1.6; margin-bottom: 1.5rem; }
.story-body em { color: var(--accent); font-style: normal; }

.steps { list-style: none; display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }
.step {
  display: flex; align-items: flex-start; gap: 0.9rem;
  background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.9rem 1rem; transition: border-color 0.15s;
}
.step:hover { border-color: var(--accent); }
.step-num {
  flex: none; width: 1.75rem; height: 1.75rem; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: rgba(91,127,232,0.15); color: var(--accent);
  font-size: 0.9rem; font-weight: 700;
}
.step-copy { display: flex; flex-direction: column; gap: 0.15rem; }
.step-title { font-weight: 600; color: var(--text); font-size: 0.95rem; }
.step-desc { color: var(--muted); font-size: 0.85rem; line-height: 1.45; }

.callout {
  background: rgba(76,175,125,0.06); border: 1px solid var(--success); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin-bottom: 1.5rem;
}
.callout p { color: var(--text); font-size: 0.9rem; line-height: 1.55; }

.story-tagline { text-align: center; font-size: 1.1rem; font-weight: 600; color: var(--success); }
