/* =============================================================
   CIPHERLAB — Worksheet edition
   Sidebar navigation + stacked input/output. Flat, restrained,
   two typefaces, one accent used sparingly.
   ============================================================= */

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

:root {
  /* frame (header + sidebar) */
  --frame-bg:     #16332c;
  --frame-bg-2:   #1c3f37;
  --frame-text:   #dcecE6;
  --frame-text-2: #8fada4;
  --frame-line:   #2a4941;

  /* canvas (main content) */
  --bg:        #fbf9f4;
  --bg-alt:    #f2ede1;
  --ink:       #201f1a;
  --ink-2:     #625d4f;
  --ink-3:     #a19c8a;
  --line:      #e6e0d0;
  --line-2:    #d6cdb4;

  /* accent */
  --accent:      #b3862a;
  --accent-dark: #8c6a1f;
  --accent-soft: rgba(179, 134, 42, 0.12);
  --accent-line: rgba(179, 134, 42, 0.35);

  --red:      #a8392f;
  --red-soft: rgba(168, 57, 47, 0.08);

  --sans: 'Inter', sans-serif;
  --mono: 'JetBrains Mono', monospace;

  --topbar-h: 56px;
  --sidenav-w: 210px;
}

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.55;
  overflow: hidden;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* =====================
   HEADER
   ===================== */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--frame-bg);
  border-bottom: 1px solid var(--frame-line);
}

.wordmark {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--accent);
}

.topbar-logo {
  font-size: 12px;
  color: var(--frame-text-2);
}

/* =====================
   SHELL LAYOUT
   ===================== */
.shell {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  width: 100%;
}

/* =====================
   SIDEBAR NAV
   ===================== */
.sidenav {
  width: var(--sidenav-w);
  flex-shrink: 0;
  background: var(--frame-bg);
  padding: 18px 0;
  overflow-y: auto;
}

.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 22px;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  color: var(--frame-text-2);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: color .12s ease, background .12s ease, border-color .12s ease;
}

.tab:hover { color: var(--frame-text); background: rgba(255,255,255,0.03); }

.tab.active {
  color: var(--frame-text);
  font-weight: 600;
  border-left-color: var(--accent);
  background: var(--frame-bg-2);
}

.tab-num {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--frame-text-2);
  width: 16px;
  flex-shrink: 0;
}

.tab.active .tab-num { color: var(--accent); }

/* =====================
   MAIN CONTENT
   ===================== */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ---- INPUT ---- */
.pane-input {
  max-height: 46%;
  overflow-y: auto;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}

.panel {
  display: none;
  flex-direction: column;
  gap: 16px;
  padding: 28px 40px;
  max-width: 700px;
}

.panel.active { display: flex; }

.cipher-info { padding-bottom: 4px; }

.cipher-tag {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin-bottom: 5px;
}

.cipher-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 3px;
}

.cipher-formula {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
}

/* MODE — plain underline switch */
.mode-row {
  display: flex;
  gap: 22px;
  border-bottom: 1px solid var(--line);
}

.mode-toggle-btn {
  position: relative;
  background: none;
  border: none;
  padding: 8px 1px 10px;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: color .12s ease;
}

.mode-toggle-btn:hover { color: var(--ink-2); }

.mode-toggle-btn.active { color: var(--ink); font-weight: 600; }

.mode-toggle-btn.active::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent);
}

/* FIELDS */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-narrow { max-width: 220px; }

.field-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
}

.hint { color: var(--ink-3); font-weight: 400; }

.term-input {
  background: var(--bg-alt);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  padding: 9px 11px;
  outline: none;
  resize: vertical;
  width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}

.term-input:focus {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.term-input::placeholder { color: var(--ink-3); }

.term-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23625d4f' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

.inline-row {
  display: flex;
  gap: 14px;
}

.inline-row .field-group { flex: 1; }

.inline-row-3 .field-group { max-width: 130px; }

/* POLY KEYS */
.poly-key-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.poly-key-badge {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-dark);
  width: 22px;
  text-align: right;
  flex-shrink: 0;
}

.poly-key-entry input {
  flex: 1;
  background: var(--bg-alt);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}

.poly-key-entry input:focus {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* MATRIX */
.matrix-wrap {
  display: grid;
  gap: 6px;
  max-width: 220px;
}

.matrix-wrap input {
  background: var(--bg-alt);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  color: var(--accent-dark);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  padding: 8px 4px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}

.matrix-wrap input:focus {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* EXECUTE — modest, not full-width */
.exec-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--frame-bg);
  border: 1px solid var(--frame-bg);
  color: var(--accent);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  width: fit-content;
  align-self: flex-start;
  margin-top: 2px;
}

.exec-btn:hover { background: var(--accent); border-color: var(--accent); color: var(--frame-bg); }
.exec-btn:active { transform: scale(.98); }

/* ---- OUTPUT ---- */
.pane-output {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 40px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.output-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sb-sep { color: var(--line-2); }

.output-actions { display: flex; gap: 4px; }

.action-btn {
  background: none;
  border: none;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: color .12s ease, background .12s ease;
}

.action-btn:hover { color: var(--accent-dark); background: var(--accent-soft); }

.terminal {
  flex: 1;
  overflow-y: auto;
  padding: 24px 40px 40px;
  max-width: 760px;
}

/* WELCOME */
.term-welcome { padding-top: 24px; }

.welcome-hint {
  font-size: 13px;
  color: var(--ink-3);
}

.welcome-hint kbd {
  background: var(--bg-alt);
  border: 1px solid var(--line-2);
  color: var(--accent-dark);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
}

/* LOG BLOCKS */
.log-block {
  margin-bottom: 26px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.log-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.log-cmd {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 12px;
}

.log-cmd::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 8px;
  border-radius: 1px;
  background: var(--accent);
  vertical-align: middle;
}

/* FLOW — plain inline row, no boxes */
.log-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px 4px;
  margin-bottom: 14px;
  font-size: 12px;
}

.flow-step {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.flow-step-label {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.flow-step-value {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  word-break: break-all;
}

.flow-step.step-result .flow-step-value {
  color: var(--accent-dark);
  font-weight: 700;
}

.flow-arrow-sep {
  color: var(--ink-3);
  font-size: 12px;
  margin: 0 4px;
}

/* RESULT */
.log-result-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}

.log-result-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  word-break: break-all;
  line-height: 1.4;
  padding: 10px 16px;
  background: var(--accent-soft);
  border-left: 2.5px solid var(--accent);
  border-radius: 0 6px 6px 0;
  margin-bottom: 16px;
}

/* KEY INFO — plain text list, no chips */
.log-keyinfo {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
}

.log-keyinfo-item { }

.log-keyinfo-item b { color: var(--accent-dark); font-weight: 700; }

/* STEPS */
.log-step {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
}

.log-step:last-child { border-bottom: none; }

.step-n {
  color: var(--ink-3);
  font-size: 10px;
  min-width: 18px;
  flex-shrink: 0;
}

.step-calc { color: var(--ink-2); flex: 1; }

.step-out { color: var(--accent-dark); font-weight: 700; flex-shrink: 0; }

.log-section-title {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 10px 0 4px;
  border-top: 1px solid var(--line);
  margin-top: 6px;
}

/* ERROR */
.log-error {
  color: var(--red);
  padding: 10px 14px;
  border-left: 2px solid var(--red);
  background: var(--red-soft);
  border-radius: 0 6px 6px 0;
  font-size: 12.5px;
  font-weight: 500;
}

/* no blinking CLI cursor — removed for a calmer finish */
.cursor { display: none; }

/* =====================
   RESPONSIVE
   ===================== */
@media (max-width: 860px) {
  .sidenav { width: 170px; }
  .panel, .terminal { padding-left: 24px; padding-right: 24px; }
  .output-head { padding-left: 24px; padding-right: 24px; }
}

@media (max-width: 640px) {
  .topbar { padding: 0 16px; }
  .topbar-logo { display: none; }
  .shell { flex-direction: column; height: auto; overflow: visible; }
  html, body { overflow: auto; }
  .sidenav {
    width: 100%;
    display: flex;
    overflow-x: auto;
    padding: 8px;
    gap: 2px;
  }
  .tab { width: auto; white-space: nowrap; border-left: none; border-bottom: 2px solid transparent; padding: 8px 12px; }
  .tab.active { border-bottom-color: var(--accent); }
  .content { height: auto; }
  .pane-input { max-height: none; overflow-y: visible; }
  .panel { padding: 20px; max-width: none; }
  .terminal { max-width: none; padding: 20px; max-height: 60vh; }
}