/* -----------------------------------------------------------------------
   Keyforge — design tokens
   A "vault & forge" concept: deep indigo-black surfaces, a brass/gold
   accent for the things you'd actually reach for (the forge button, the
   entropy meter, focus states), and IBM Plex across three roles so the
   generated *values* always render in the same monospace voice whether
   they're on the plate or in history.
------------------------------------------------------------------------ */

:root {
  --bg: #12141b;
  --surface: #1a1d28;
  --surface-raised: #232735;
  --border: rgba(237, 234, 225, 0.09);
  --border-strong: rgba(237, 234, 225, 0.18);

  --ink: #ede9e0;
  --ink-dim: #9b9ca8;
  --ink-faint: #83848f;

  --brass: #c9a24b;
  --brass-bright: #e8c977;
  --brass-ink: #241d0c;

  --teal: #6c9aa0;
  --danger: #c1503d;
  --danger-text: #e59d90;
  --success: #6b9e6e;
  --fair: #c9a24b;

  --font-display: "IBM Plex Serif", Georgia, serif;
  --font-body: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-plate: inset 0 1px 0 rgba(237, 234, 225, 0.04), 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-raised: 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  /* Keyforge is intentionally a dark, vault-like surface in both modes —
     it's a security tool, and the brass accent needs the dark ground to
     read. We still respect reduced-motion and focus-visibility below. */
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 900px 500px at 50% -10%, rgba(201, 162, 75, 0.08), transparent),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: no-preference) {
  * {
    scroll-behavior: smooth;
  }
}

/* ---------- focus ---------- */

:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- header ---------- */

.site-header {
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 20px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.mark {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(155deg, var(--surface-raised), var(--surface));
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: var(--brass);
  margin-top: 2px;
}
.mark svg {
  width: 20px;
  height: 20px;
}

.site-header h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  letter-spacing: 0.01em;
  margin: 0 0 4px;
}

.tagline {
  margin: 0;
  color: var(--ink-dim);
  font-size: 0.92rem;
  max-width: 46ch;
}

/* ---------- layout ---------- */

.forge {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 20px 40px;
}

.site-footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 56px;
  color: var(--ink-faint);
  font-size: 0.82rem;
  text-align: center;
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}

.tab {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.9rem;
  padding: 10px 12px;
  border-radius: calc(var(--radius-md) - 4px);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab:hover {
  color: var(--ink);
}

.tab[aria-selected="true"] {
  background: var(--surface-raised);
  color: var(--brass-bright);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

/* ---------- output plate ---------- */

.plate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-raised);
  margin-bottom: 20px;
}

.plate {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-plate);
  padding: 16px 14px 16px 18px;
}

.plate-value {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink);
  word-break: break-all;
  user-select: all;
}

.plate-value.is-placeholder {
  color: var(--ink-faint);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-style: italic;
  user-select: none;
}

.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}
.icon-btn:hover {
  color: var(--brass-bright);
  border-color: var(--brass);
}
.icon-btn svg {
  width: 17px;
  height: 17px;
}
.icon-btn.is-copied {
  color: var(--success);
  border-color: var(--success);
}
.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.icon-btn:disabled:hover {
  color: var(--ink-dim);
  border-color: var(--border-strong);
}

/* ---------- entropy tumbler meter (signature element) ----------
   Ten pins, styled after a lock's tumbler pins. As entropy rises more
   pins "lift" and light up in brass, echoing the vault/forge concept
   instead of a generic progress bar. */

.meter-row {
  margin-top: 16px;
}

.tumbler-meter {
  display: flex;
  gap: 4px;
  height: 26px;
  align-items: flex-end;
}

.pin {
  flex: 1;
  height: 40%;
  min-width: 0;
  border-radius: 2px 2px 1px 1px;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
  transition: height 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.35s ease, border-color 0.35s ease;
}

.pin.is-lit {
  background: linear-gradient(180deg, var(--brass-bright), var(--brass));
  border-color: var(--brass);
  box-shadow: 0 0 8px rgba(201, 162, 75, 0.45);
}

.pin.is-weak.is-lit {
  background: linear-gradient(180deg, #d97a68, var(--danger));
  border-color: var(--danger);
  box-shadow: 0 0 8px rgba(193, 80, 61, 0.4);
}

.pin.is-strong.is-lit {
  background: linear-gradient(180deg, #86bf88, var(--success));
  border-color: var(--success);
  box-shadow: 0 0 8px rgba(107, 158, 110, 0.4);
}

@media (prefers-reduced-motion: reduce) {
  .pin {
    transition: none;
  }
}

.meter-label {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  transition: color 0.35s ease;
}

.meter-label.is-weak {
  color: var(--danger-text);
}

.meter-label.is-fair {
  color: var(--fair);
}

.meter-label.is-strong {
  color: var(--success);
}

.inline-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: rgba(193, 80, 61, 0.12);
  border: 1px solid rgba(193, 80, 61, 0.4);
  border-radius: var(--radius-sm);
  color: #e59d90;
  font-size: 0.85rem;
}

/* ---------- forge button ---------- */

.forge-btn {
  width: 100%;
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--brass-bright), var(--brass));
  color: var(--brass-ink);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 13px 16px;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.forge-btn svg {
  width: 17px;
  height: 17px;
}
.forge-btn:hover {
  filter: brightness(1.06);
}
.forge-btn:active {
  transform: translateY(1px);
}
.forge-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}
.forge-btn:disabled:active {
  transform: none;
}

/* ---------- options ---------- */

.options {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.options-title {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin: 0 0 18px;
}

.field {
  margin-bottom: 18px;
}
.field:last-child {
  margin-bottom: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

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

.field label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink);
}

.field-head output {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--brass-bright);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 1px 8px;
  min-width: 2.2em;
  text-align: center;
}

.hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--ink-faint);
}

/* range input */

input[type="range"] {
  --range-progress: 0%;
  width: 100%;
  height: 18px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--brass) var(--range-progress),
    var(--surface-raised) var(--range-progress)
  );
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--brass-bright);
  border: 2px solid var(--brass-ink);
  cursor: pointer;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-raised);
}
input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 2px 0 0 2px;
  background: var(--brass);
}
input[type="range"]::-moz-range-thumb {
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brass-bright);
  border: 2px solid var(--brass-ink);
  cursor: pointer;
}

/* number / select / text inputs */

input[type="number"],
input[type="text"],
input[type="email"],
select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="number"]::placeholder,
input[type="text"]::placeholder,
input[type="email"]::placeholder {
  color: var(--ink-faint);
}
input[type="number"]:hover,
input[type="text"]:hover,
input[type="email"]:hover,
select:hover {
  border-color: var(--ink-faint);
}
input[type="number"]:focus-visible,
input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(201, 162, 75, 0.18);
}
input[type="number"]:invalid,
input[type="email"]:invalid:not(:placeholder-shown) {
  border-color: var(--danger);
}
input[type="number"]:disabled,
input[type="text"]:disabled,
input[type="email"]:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%), linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  cursor: pointer;
}

/* chips (character-set toggles) */

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  position: relative;
}
.chip input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.chip span {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-dim);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 7px 14px;
}
.chip input:checked + span {
  color: var(--brass-ink);
  background: var(--brass-bright);
  border-color: var(--brass-bright);
}
.chip input:focus-visible + span {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* checkbox rows */

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
  margin-top: 14px;
}
.checkbox-row[hidden] {
  display: none;
}
.checkbox-row:first-of-type {
  margin-top: 0;
}
.checkbox-row em {
  color: var(--ink-faint);
  font-style: normal;
}

.checkbox-control {
  position: relative;
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}
.checkbox-control input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.checkbox-box {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 5px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg);
  color: transparent;
  pointer-events: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.checkbox-check {
  width: 11px;
  height: 11px;
}
.checkbox-control input:hover ~ .checkbox-box {
  border-color: var(--brass);
}
.checkbox-control input:checked ~ .checkbox-box {
  background: var(--brass-bright);
  border-color: var(--brass-bright);
  color: var(--brass-ink);
}
.checkbox-control input:focus-visible ~ .checkbox-box {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}
.checkbox-control input:disabled ~ .checkbox-box {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- history ---------- */

.history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

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

.history-head h2 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin: 0;
}

.link-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 4px;
}
.link-btn:hover {
  color: var(--danger-text);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.history-list::-webkit-scrollbar {
  width: 8px;
}
.history-list::-webkit-scrollbar-track {
  background: transparent;
}
.history-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
.history-list::-webkit-scrollbar-thumb:hover {
  background: var(--ink-faint);
}

.history-empty {
  color: var(--ink-faint);
  font-size: 0.85rem;
  padding: 10px 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child {
  border-bottom: none;
}

.history-badge {
  flex: none;
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 3px 6px;
  width: 62px;
  text-align: center;
}

.history-value {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
}

.history-time {
  flex: none;
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.history-actions {
  flex: none;
  display: flex;
  gap: 2px;
}

.history-actions button {
  appearance: none;
  background: none;
  border: none;
  color: var(--ink-faint);
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.history-actions button:hover {
  color: var(--brass-bright);
  background: var(--surface-raised);
}
.history-actions button.delete:hover {
  color: var(--danger-text);
}
.history-actions svg {
  width: 14px;
  height: 14px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  font-size: 0.85rem;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-raised);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- responsive ---------- */

@media (max-width: 420px) {
  .field-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .plate-value {
    font-size: 1rem;
  }
  .history-badge {
    width: auto;
    padding: 3px 5px;
    font-size: 0;
  }
  .history-badge::after {
    content: attr(data-short);
    font-size: 0.68rem;
  }
}
