@import 'tokens.css';

/* ═══════════════════════════════════════════════════════════════════════
   Base — adopted from the Clipper / Shifter shared theme verbatim
   ═══════════════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(123, 92, 255, 0.14), transparent 60%),
    radial-gradient(900px 400px at 85% 110%, rgba(255, 45, 149, 0.10), transparent 60%),
    radial-gradient(900px 400px at 10% 100%, rgba(0, 240, 255, 0.08), transparent 60%),
    var(--bg);
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0, 240, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 240, 255, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 30%, #000 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 90% 70% at 50% 30%, #000 30%, transparent 100%);
}

::selection { background: rgba(0, 240, 255, 0.3); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: rgba(0, 240, 255, 0.18); border-radius: 8px; border: 2px solid var(--bg-2); }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 240, 255, 0.32); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

[hidden] { display: none !important; }

/* ── Header ── */

.app-header {
  text-align: center;
  padding: 26px 16px 8px;
  position: relative;
}

.logo {
  width: 44px;
  height: 44px;
  filter: drop-shadow(0 0 6px rgba(0, 240, 255, 0.6));
}

.app-header h1 {
  margin: 6px 0 2px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.55em;
  text-indent: 0.55em; /* recenters letter-spaced text */
  color: var(--ink);
  text-shadow: 0 0 14px rgba(0, 240, 255, 0.55), 0 0 40px rgba(0, 240, 255, 0.2);
}

.tagline {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: var(--ink-dim);
}

/* ── Layout ── */

main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.35);
}

.editor {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Buttons ── */

.btn {
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.25em;
  text-indent: 0.25em;
  padding: 13px 18px;
  border-radius: 12px;
  cursor: pointer;
  transition: box-shadow 0.2s, background 0.2s, transform 0.1s, opacity 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

.btn-outline {
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid rgba(0, 240, 255, 0.45);
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.5);
}

.btn-outline:hover { box-shadow: var(--glow-cyan); }

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(125, 138, 165, 0.35);
  color: var(--ink-dim);
}

.btn-ghost:hover { border-color: rgba(125, 138, 165, 0.6); color: var(--ink); }

.btn-danger {
  background: rgba(255, 45, 149, 0.06);
  border: 1px solid rgba(255, 45, 149, 0.4);
  color: var(--magenta);
}

.btn-danger:hover { box-shadow: var(--glow-magenta); }

.btn-primary {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.9), rgba(123, 92, 255, 0.9) 55%, rgba(255, 45, 149, 0.9));
  border: none;
  color: #04070d;
  font-weight: 700;
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.35), 0 0 34px rgba(255, 45, 149, 0.2);
}

.btn-primary:hover {
  box-shadow: 0 0 26px rgba(0, 240, 255, 0.55), 0 0 48px rgba(255, 45, 149, 0.35);
}

.btn-magic {
  background: rgba(123, 92, 255, 0.1);
  border: 1px solid rgba(123, 92, 255, 0.5);
  color: #c9bcff;
  text-shadow: 0 0 8px rgba(123, 92, 255, 0.6);
}

.btn-magic:hover { box-shadow: var(--glow-violet); }

.btn-small {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  padding: 8px 12px;
  border-radius: 9px;
  flex-shrink: 0;
}

.btn-icon {
  padding: 7px 9px;
  text-indent: 0;
  line-height: 0;
}

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

/* ── Switch ── */

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  width: 38px;
  height: 22px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  pointer-events: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(125, 138, 165, 0.5);
  background: rgba(0, 0, 0, 0.4);
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}

.switch input:focus-visible + .switch-track { box-shadow: var(--glow-cyan); }

.switch input:checked + .switch-track {
  border-color: var(--cyan);
  box-shadow: inset 0 0 8px rgba(0, 240, 255, 0.25);
}

.switch input:checked + .switch-track::after {
  transform: translateX(16px);
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.8);
}

/* ── Footer ── */

.app-footer {
  text-align: center;
  padding: 10px 16px 18px;
  font-size: 10px;
  letter-spacing: 0.15em;
  color: rgba(125, 138, 165, 0.6);
}

/* ═══════════════════════════════════════════════════════════════════════
   CipherDeck-specific components, built in the same visual language
   ═══════════════════════════════════════════════════════════════════════ */

.card-title {
  font-size: 11px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--cyan);
  box-shadow: var(--glow-cyan);
  transform: rotate(45deg);
  flex-shrink: 0;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}

.meta-row { font-size: 10px; color: var(--ink-dim); letter-spacing: 0.05em; }

label.field-label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  color: var(--ink-dim);
  margin-bottom: 5px;
}

.field { display: flex; flex-direction: column; gap: 2px; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 130px; }

textarea, input[type="text"], input[type="number"], select {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 240, 255, 0.16);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
}

textarea { resize: vertical; min-height: 140px; line-height: 1.5; }
.input-textarea { min-height: 200px; }

select {
  appearance: none;
  cursor: pointer;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--cyan) 50%),
    linear-gradient(135deg, var(--cyan) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* ── tags / badges ── */

.tag {
  font-size: 9px;
  letter-spacing: 0.15em;
  text-indent: 0.15em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(125, 138, 165, 0.35);
  color: var(--ink-dim);
}

.tag-cat-encoding { color: var(--cyan); border-color: rgba(0, 240, 255, 0.35); }
.tag-cat-hashing { color: var(--magenta); border-color: rgba(255, 45, 149, 0.35); }
.tag-cat-text { color: #c9bcff; border-color: rgba(123, 92, 255, 0.4); }
.tag-cat-data { color: var(--ink-dim); border-color: rgba(125, 138, 165, 0.4); }

.index-badge {
  width: 22px; height: 22px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(0, 240, 255, 0.4);
  color: var(--cyan); flex-shrink: 0;
}

/* ── detect banner ── */

.banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(123, 92, 255, 0.4);
  background: rgba(123, 92, 255, 0.08);
  font-size: 12px;
  color: #c9bcff;
  animation: bannerIn 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.banner-text { flex: 1 1 220px; min-width: 0; line-height: 1.5; }
.banner-text strong { color: #fff; }
.banner-icon { margin-right: 6px; }

@keyframes bannerIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* ── operation stack ── */

.stack-list { display: flex; flex-direction: column; gap: 12px; }

.stack-empty {
  border: 1px dashed rgba(0, 240, 255, 0.25);
  border-radius: 14px;
  padding: 32px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 12px;
}

.stack-item {
  border: 1px solid rgba(0, 240, 255, 0.16);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
}

.stack-item-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 10px;
}

.stack-item-name { font-weight: 600; color: var(--ink); flex: 1; min-width: 90px; font-size: 13px; }

.stack-item-controls { display: flex; gap: 4px; margin-left: auto; }

.stack-item-config { margin-bottom: 10px; }

.stack-output {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 240, 255, 0.12);
  border-radius: 10px;
  padding: 10px 12px;
}

.stack-output-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
  font-size: 9px; color: var(--ink-dim); letter-spacing: 0.15em; text-transform: uppercase;
}

.stack-output pre {
  margin: 0;
  white-space: pre-wrap; word-break: break-word;
  font-size: 12.5px;
  max-height: 240px;
  overflow: auto;
  color: var(--ink);
}

.stack-output.is-error { border-color: rgba(255, 45, 149, 0.4); }
.stack-output.is-error pre { color: var(--magenta); }

/* ── modal (operation picker) ── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(4, 6, 12, 0.7);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 14px;
  z-index: 50;
}

.modal {
  width: 100%; max-width: 560px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  background: var(--bg-2);
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: 16px;
  box-shadow: var(--glow-cyan), 0 20px 60px -20px rgba(0, 0, 0, 0.8);
  padding: 16px;
}

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.op-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.op-group-label {
  font-size: 9px; color: var(--ink-dim);
  letter-spacing: 0.25em; text-indent: 0.25em; text-transform: uppercase;
  margin: 8px 0 2px;
}

.op-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
}

.op-option:hover, .op-option:focus-visible {
  background: rgba(0, 240, 255, 0.06);
  border-color: rgba(0, 240, 255, 0.2);
  outline: none;
}

.op-option-name { font-weight: 600; font-size: 13px; }
.op-option-desc { font-size: 11px; color: var(--ink-dim); }

/* ── magic result ── */

.magic-chain { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.magic-chain .tag { color: #c9bcff; border-color: rgba(123, 92, 255, 0.4); }

.copied-flash { color: var(--cyan) !important; border-color: rgba(0, 240, 255, 0.5) !important; }
