:root {
  --slate-950: #020617;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --text: #f8fafc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: linear-gradient(180deg, #1e2937 0%, var(--slate-950) 100%);
  color: var(--text);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--slate-900);
  border-bottom: 1px solid var(--slate-700);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand h1 {
  margin: 0;
  font-size: 1.4rem;
}

.brand p {
  margin: 2px 0 0;
  color: var(--slate-400);
  font-size: 0.85rem;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.text-btn, .icon-btn, .btn {
  border: none;
  cursor: pointer;
  font: inherit;
}

.text-btn {
  background: transparent;
  color: var(--amber-400);
  padding: 8px 12px;
  border-radius: 10px;
}

.text-btn:hover { background: rgba(251, 191, 36, 0.1); }

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px;
}

.panel {
  background: linear-gradient(180deg, #1e2937, var(--slate-950));
  border: 1px solid var(--slate-700);
  border-radius: 24px;
  padding: 16px;
}

.field-block + .field-block { margin-top: 12px; }

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

.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--slate-400);
  font-size: 0.9rem;
}

.count-badge {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--slate-600);
  color: var(--slate-400);
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: transparent;
  color: var(--amber-400);
  display: grid;
  place-items: center;
}

.icon-btn:hover { background: rgba(251, 191, 36, 0.12); }

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid var(--slate-600);
  border-radius: 16px;
  background: var(--slate-900);
  color: var(--text);
  padding: 14px;
  font: 0.95rem/1.45 ui-monospace, monospace;
}

textarea:focus {
  outline: 2px solid var(--amber-500);
  outline-offset: 1px;
}

textarea[readonly] {
  background: #0b1220;
  cursor: default;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 16px;
  font-weight: 600;
}

.btn-secondary {
  width: 100%;
  margin-top: 12px;
  background: var(--slate-800);
  color: var(--text);
  border: 1px solid var(--slate-600);
}

.btn-secondary:hover { background: var(--slate-700); }

.btn-primary {
  background: var(--amber-600);
  color: #111;
}

.btn-primary:hover { background: var(--amber-500); }

.rotor-section {
  margin-top: 16px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid transparent;
}

.rotor-section.editable {
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(30, 41, 59, 0.35);
  cursor: pointer;
}

.section-title {
  color: var(--amber-400);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.mono-line {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: var(--slate-400);
  margin: 4px 0;
}

.mono-line .warn { color: var(--amber-400); }

.hint {
  color: rgba(251, 191, 36, 0.85);
  font-size: 0.78rem;
  margin-top: 6px;
}

.rotor-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.rotor-card { text-align: center; }

.rotor-label {
  font-size: 0.75rem;
  color: var(--slate-400);
  margin-bottom: 6px;
}

.rotor-box {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 12px;
  border: 2px solid var(--amber-400);
  background: linear-gradient(180deg, var(--slate-600), var(--slate-800));
  display: grid;
  place-items: center;
}

.rotor-id {
  font-family: ui-monospace, monospace;
  font-size: 1.2rem;
}

.rotor-pos {
  margin-top: 6px;
  color: var(--amber-400);
  font-family: ui-monospace, monospace;
  font-size: 1.1rem;
}

.plugboard-head {
  color: var(--slate-400);
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.plugboard-pairs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.plug-pair {
  font-family: ui-monospace, monospace;
  color: var(--amber-400);
  background: var(--slate-800);
  border: 1px solid var(--slate-600);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.footer-note {
  margin-top: 8px;
  text-align: center;
  color: var(--slate-500);
  font-size: 0.75rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal.open { display: flex; }

.modal-card {
  width: min(720px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--slate-900);
  border: 1px solid var(--slate-700);
  border-radius: 20px;
  padding: 20px;
}

.modal-card.wide { width: min(860px, 100%); }

.modal-card h2 {
  margin: 0 0 8px;
  color: var(--amber-400);
}

.modal-card h3 {
  margin: 16px 0 8px;
  font-size: 1rem;
}

.modal-card p, .modal-card li {
  color: var(--slate-400);
  line-height: 1.5;
}

.modal-card ul { padding-left: 1.2rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: block;
  color: var(--slate-400);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

input, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--slate-600);
  background: var(--slate-800);
  color: var(--text);
  font: inherit;
}

textarea.setup {
  min-height: 72px;
  font-family: ui-monospace, monospace;
}

.key-export {
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  background: var(--slate-800);
  border: 1px solid var(--slate-600);
  border-radius: 12px;
  padding: 12px;
  color: var(--slate-400);
}

.duplicate-hint {
  color: var(--amber-400);
  font-size: 0.82rem;
}

.duplicate-hint[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--slate-800);
  border: 1px solid var(--slate-600);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.muted { color: var(--slate-500); }

a { color: var(--amber-400); }

@media (max-width: 640px) {
  .form-row-2 { grid-template-columns: 1fr; }
  .rotor-grid { grid-template-columns: repeat(2, 1fr); }
}