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

body {
  font-family: Segoe UI, Arial, sans-serif;
  background: linear-gradient(135deg, #e2e8f0, #f1f5f9);
  color: #1e293b;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.container {
  width: 600px;
  text-align: center;
  padding: 40px 0;
}

h1 {
  margin-bottom: 10px;
  color: #0f172a;
}

.subtitle {
  margin-bottom: 30px;
  color: #64748b;
}

.card {
  background: #ffffff;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 24px;
}

label {
  display: block;
  margin-top: 15px;
  margin-bottom: 5px;
  text-align: left;
  font-weight: bold;
  color: #334155;
}

textarea {
  width: 100%;
  height: 100px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
  font-size: 14px;
  background: #f8fafc;
  color: #1e293b;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

textarea:focus {
  border-color: #3b82f6;
}

input, select {
  width: 100%;
  padding: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  margin-bottom: 10px;
  background: #f8fafc;
  color: #1e293b;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, select:focus {
  border-color: #3b82f6;
}

select option {
  background: #ffffff;
}

.buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 15px;
}

button {
  width: 48%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  transition: 0.2s;
}

.encrypt {
  background: #22c55e;
  color: white;
}

.encrypt:hover {
  background: #16a34a;
}

.decrypt {
  background: #3b82f6;
  color: white;
}

.decrypt:hover {
  background: #2563eb;
}

.analyze-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  transition: 0.2s;
  background: #7c3aed;
  color: white;
  margin-top: 10px;
}

.analyze-btn:hover {
  background: #6d28d9;
}

.help {
  margin-top: 25px;
  background: #f1f5f9;
  padding: 15px;
  border-radius: 8px;
  font-size: 14px;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.help ul {
  text-align: left;
  margin-top: 10px;
  margin-left: 20px;
}

/* ========================
   CRYPTANALYSIS OUTPUT
======================== */

#analysisOutput {
  margin-top: 22px;
  text-align: left;
  display: none;
}

.section-label {
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #94a3b8;
  margin: 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}

/* Stats */
.stats-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  flex: 1;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 10px;
  text-align: center;
}

.stat-lbl {
  font-size: 11px;
  color: #94a3b8;
  margin-bottom: 5px;
}

.stat-val {
  font-size: 1.3rem;
  font-weight: bold;
  font-family: monospace;
}

.stat-sub {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 4px;
}

/* Detection banner */
.det-banner {
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 4px;
  font-size: 13px;
  line-height: 1.5;
}

.det-banner strong {
  display: block;
  font-size: 14px;
  margin-bottom: 2px;
}

.det-banner.mono {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.det-banner.poly {
  background: #faf5ff;
  border: 1px solid #e9d5ff;
  color: #6b21a8;
}

.det-banner.unk {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

/* Frequency chart */
.freq-wrap {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px 14px 10px;
  margin-bottom: 4px;
}

.freq-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 72px;
  margin-bottom: 6px;
}

.freq-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  position: relative;
}

.bar-ref {
  width: 100%;
  background: rgba(245, 158, 11, 0.35);
  border-radius: 2px 2px 0 0;
  min-height: 1px;
  position: absolute;
  bottom: 14px;
  left: 0;
  z-index: 1;
}

.bar-ct {
  width: 100%;
  background: #3b82f6;
  border-radius: 2px 2px 0 0;
  min-height: 1px;
  position: relative;
  z-index: 2;
}

.bar-lbl {
  font-size: 8px;
  color: #94a3b8;
  margin-top: 3px;
  font-family: monospace;
}

.freq-legend {
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: #94a3b8;
}

.freq-legend span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.tab-btn {
  padding: 7px 16px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  color: #94a3b8;
  font-size: 13px;
  cursor: pointer;
  transition: 0.2s;
  width: auto;
}

.tab-btn:hover {
  color: #1e293b;
  border-color: #3b82f6;
}

.tab-btn.active {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #1d4ed8;
}

.tab-panel {
  display: none;
}

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

/* Candidate cards */
.cand {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  position: relative;
}

.cand.best {
  border-color: #22c55e;
  background: #f0fdf4;
}

.best-lbl {
  display: inline-block;
  background: #22c55e;
  color: white;
  font-size: 10px;
  font-family: monospace;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.cand-key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.cand-key-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cand-key-name {
  font-size: 13px;
  font-weight: bold;
  color: #334155;
}

.cand-key-val {
  font-family: monospace;
  font-size: 13px;
  color: #2563eb;
}

.cand-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.conf-block {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conf-pct {
  font-family: monospace;
  font-size: 12px;
  font-weight: bold;
  color: #64748b;
  white-space: nowrap;
}

.conf-wrap {
  width: 60px;
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
}

.conf-bar {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, #22c55e, #3b82f6);
}

.use-btn {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid #3b82f6;
  color: #3b82f6;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  transition: 0.2s;
  width: auto;
}

.use-btn:hover {
  background: #3b82f6;
  color: white;
}

.preview-label {
  font-size: 11px;
  color: #94a3b8;
  margin-bottom: 5px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cand-txt {
  font-family: monospace;
  font-size: 13px;
  color: #334155;
  word-break: break-all;
  line-height: 1.6;
  max-height: 56px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px 10px;
}

.cand-txt.exp {
  max-height: none;
}

.exp-btn {
  background: none;
  border: none;
  color: #3b82f6;
  font-size: 11px;
  cursor: pointer;
  padding: 4px 0 0;
  font-family: monospace;
  text-decoration: underline;
  display: inline-block;
  width: auto;
}

/* Key length chart */
.kl-wrap {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.kl-chart {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 52px;
  margin-bottom: 2px;
}

.kl-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.kl-bar {
  width: 100%;
  background: #93c5fd;
  border-radius: 2px 2px 0 0;
  min-height: 1px;
}

.kl-bar.top {
  background: #22c55e;
}

.kl-lbl {
  font-size: 9px;
  font-family: monospace;
  color: #94a3b8;
  margin-top: 3px;
}

.kl-note {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 8px;
  line-height: 1.5;
}

.no-res {
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
  padding: 16px;
}

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
