/* Kiwi Key Generator
   Colors are tokens: light by default, dark via the OS preference or data-theme="dark".
   --accent-hue and --tint-hue are set by the appearance dialog. */

:root {
  --accent-hue: 100;
  --tint-hue: 210;
  color-scheme: light;

  --bg: hsl(var(--tint-hue) 20% 97.5%);
  --surface: hsl(var(--tint-hue) 20% 100%);
  --surface-2: hsl(var(--tint-hue) 18% 96%);
  --field: hsl(var(--tint-hue) 20% 100%);
  --border: hsl(var(--tint-hue) 14% 89%);
  --border-strong: hsl(var(--tint-hue) 12% 80%);
  --text: hsl(var(--tint-hue) 18% 13%);
  --muted: hsl(var(--tint-hue) 9% 40%);

  --accent: hsl(var(--accent-hue) 58% 30%);
  --accent-hover: hsl(var(--accent-hue) 58% 25%);
  --accent-contrast: #fff;
  --accent-soft: hsl(var(--accent-hue) 50% 94%);
  --accent-text: hsl(var(--accent-hue) 60% 27%);
  --ring: hsl(var(--accent-hue) 60% 45% / 0.28);

  --danger: hsl(0 68% 44%);
  --danger-solid: hsl(0 68% 46%);
  --danger-soft: hsl(0 80% 97%);
  --danger-border: hsl(0 60% 82%);
  --warn: hsl(32 85% 32%);
  --warn-soft: hsl(40 90% 95%);
  --warn-border: hsl(38 70% 75%);

  --toast-bg: hsl(var(--tint-hue) 18% 14%);
  --toast-text: hsl(var(--tint-hue) 20% 96%);
  --shadow: 0 10px 30px hsl(var(--tint-hue) 30% 10% / 0.12);

  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: hsl(var(--tint-hue) 14% 7.5%);
    --surface: hsl(var(--tint-hue) 12% 10.5%);
    --surface-2: hsl(var(--tint-hue) 11% 13.5%);
    --field: hsl(var(--tint-hue) 12% 8.5%);
    --border: hsl(var(--tint-hue) 9% 19%);
    --border-strong: hsl(var(--tint-hue) 8% 28%);
    --text: hsl(var(--tint-hue) 12% 91%);
    --muted: hsl(var(--tint-hue) 7% 63%);
    --accent: hsl(var(--accent-hue) 50% 58%);
    --accent-hover: hsl(var(--accent-hue) 52% 66%);
    --accent-contrast: hsl(var(--accent-hue) 45% 9%);
    --accent-soft: hsl(var(--accent-hue) 30% 15%);
    --accent-text: hsl(var(--accent-hue) 55% 70%);
    --ring: hsl(var(--accent-hue) 55% 60% / 0.3);
    --danger: hsl(0 75% 68%);
    --danger-solid: hsl(0 60% 45%);
    --danger-soft: hsl(0 40% 13%);
    --danger-border: hsl(0 40% 32%);
    --warn: hsl(38 85% 62%);
    --warn-soft: hsl(38 40% 12%);
    --warn-border: hsl(38 40% 30%);
    --toast-bg: hsl(var(--tint-hue) 12% 92%);
    --toast-text: hsl(var(--tint-hue) 18% 10%);
    --shadow: 0 10px 30px rgb(0 0 0 / 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: hsl(var(--tint-hue) 14% 7.5%);
  --surface: hsl(var(--tint-hue) 12% 10.5%);
  --surface-2: hsl(var(--tint-hue) 11% 13.5%);
  --field: hsl(var(--tint-hue) 12% 8.5%);
  --border: hsl(var(--tint-hue) 9% 19%);
  --border-strong: hsl(var(--tint-hue) 8% 28%);
  --text: hsl(var(--tint-hue) 12% 91%);
  --muted: hsl(var(--tint-hue) 7% 63%);
  --accent: hsl(var(--accent-hue) 50% 58%);
  --accent-hover: hsl(var(--accent-hue) 52% 66%);
  --accent-contrast: hsl(var(--accent-hue) 45% 9%);
  --accent-soft: hsl(var(--accent-hue) 30% 15%);
  --accent-text: hsl(var(--accent-hue) 55% 70%);
  --ring: hsl(var(--accent-hue) 55% 60% / 0.3);
  --danger: hsl(0 75% 68%);
  --danger-solid: hsl(0 60% 45%);
  --danger-soft: hsl(0 40% 13%);
  --danger-border: hsl(0 40% 32%);
  --warn: hsl(38 85% 62%);
  --warn-soft: hsl(38 40% 12%);
  --warn-border: hsl(38 40% 30%);
  --toast-bg: hsl(var(--tint-hue) 12% 92%);
  --toast-text: hsl(var(--tint-hue) 18% 10%);
  --shadow: 0 10px 30px rgb(0 0 0 / 0.5);
}

/* ---------------------------------------------------------------- base */

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0;
  line-height: 1.3;
}

a {
  color: var(--accent-text);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 24px 72px;
}

/* ---------------------------------------------------------------- header & tabs */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  font-size: 28px;
  line-height: 1;
}

.brand h1 {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13.5px;
}

.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.mode-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.mode-toggle::-webkit-scrollbar {
  display: none;
}

.mode-btn {
  flex: none;
  margin-bottom: -1px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.form-mode {
  display: none;
}

.form-mode.active {
  display: block;
}

/* ---------------------------------------------------------------- sections & forms */

.generator-section {
  margin-bottom: 16px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.generator-section h2 {
  margin-bottom: 16px;
  font-size: 15px;
  font-weight: 600;
}

.section-intro {
  margin: -4px 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.form-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
}

.form-group small {
  color: var(--muted);
  font-size: 12.5px;
}

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

input,
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  font-family: var(--mono);
  font-size: 13px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

input[type="file"] {
  padding: 6px;
  color: var(--muted);
}

input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.passphrase-container {
  display: flex;
  gap: 8px;
}

.passphrase-container input {
  flex: 1;
}

/* ---------------------------------------------------------------- buttons */

.btn-primary,
.btn-secondary,
.btn-copy,
.btn-download,
.segmented button {
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-primary,
.btn-secondary {
  align-self: flex-start;
  padding: 9px 16px;
  font-size: 14px;
}

.btn-primary {
  min-width: 160px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary,
.btn-copy,
.btn-download {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.btn-secondary:hover,
.btn-copy:hover,
.btn-download:hover {
  background: var(--surface-2);
}

.btn-copy,
.btn-download {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.btn-download {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.btn-download:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.btn-danger,
.btn-danger:hover {
  border-color: var(--danger-border);
  background: transparent;
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-soft);
}

/* ---------------------------------------------------------------- status, notices, disclosure */

.ca-status {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 8px;
  max-width: 100%;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.ca-status::before {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
}

.ca-status.ca-ready {
  color: var(--text);
}

.ca-status.ca-ready::before {
  border-color: var(--accent);
  background: var(--accent);
}

.warning {
  margin-bottom: 20px;
  padding: 12px 16px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 500;
}

.upload-section-container {
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.upload-section-header {
  padding: 11px 14px;
  cursor: pointer;
  user-select: none;
}

.upload-section-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
}

.fold-icon {
  flex: none;
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
}

.upload-section-container.open .fold-icon {
  transform: rotate(45deg);
}

.upload-section-content {
  display: none;
  flex-direction: column;
  gap: 16px;
  padding: 4px 14px 16px;
}

.upload-section-container.open .upload-section-content {
  display: flex;
}

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

.output-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.output-placeholder {
  margin: 0;
  padding: 28px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.output-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.output-group + .output-group {
  margin-top: 24px;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.output-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.output-info {
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.details {
  display: grid;
  grid-template-columns: minmax(110px, 180px) 1fr;
  gap: 6px 16px;
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 13.5px;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.output-file {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.file-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 12px;
}

.file-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  min-width: 0;
}

.file-title strong {
  font-size: 13.5px;
  font-weight: 600;
}

.file-name {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.output-file textarea {
  display: block;
  min-height: 110px;
  max-height: 360px;
  padding: 12px;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface-2);
  font-size: 12.5px;
  line-height: 1.5;
}

.output-file textarea:focus {
  box-shadow: none;
}

.binary-note {
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

/* ---------------------------------------------------------------- vault */

.vault-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.vault-toolbar h2 {
  margin: 0;
}

.vault-toolbar + .section-intro {
  margin: 0 0 20px;
}

.vault-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vault-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.vault-item.open {
  border-color: var(--border-strong);
}

.vault-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.vault-item-main {
  min-width: 0;
}

.vault-item-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.vault-item-title strong {
  margin-right: 2px;
  font-size: 14px;
  font-weight: 600;
}

.vault-item-desc {
  margin-top: 3px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.vault-item-details {
  margin-top: 14px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.vault-item-details > .form-container {
  margin-bottom: 20px;
}

.vault-picker {
  margin-bottom: 4px;
}

.badge {
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-warn {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-bad {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------------------------------------------------------------- notifications */

.notification {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 3000;
  max-width: min(34rem, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 500;
  transform: translateX(-50%);
  animation: toast-in 0.2s ease-out;
}

.notification-error {
  background: var(--danger-solid);
  color: #fff;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------------------------------------------------------- appearance dialog */

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.45);
}

.modal-card {
  width: min(380px, 100%);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.modal-head h3 {
  font-size: 16px;
  font-weight: 600;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
}

.segmented button {
  flex: 1;
  padding: 6px 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}

.hue-value {
  margin-left: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 400;
}

.hue-slider {
  height: 10px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(to right,
    hsl(0 65% 55%), hsl(60 65% 55%), hsl(120 65% 55%), hsl(180 65% 55%),
    hsl(240 65% 55%), hsl(300 65% 55%), hsl(360 65% 55%));
  appearance: none;
  cursor: pointer;
}

.hue-slider:focus {
  box-shadow: 0 0 0 3px var(--ring);
}

.hue-slider::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35), 0 1px 3px rgb(0 0 0 / 0.3);
  appearance: none;
}

.hue-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35), 0 1px 3px rgb(0 0 0 / 0.3);
}

/* ---------------------------------------------------------------- small screens */

@media (max-width: 640px) {
  .app {
    padding: 20px 16px 56px;
  }

  .brand p {
    font-size: 13px;
  }

  .generator-section {
    padding: 18px 16px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .btn-primary {
    align-self: stretch;
  }

  .details {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .details dd + dt {
    margin-top: 8px;
  }

  .vault-item-head {
    flex-direction: column;
    align-items: stretch;
  }
}

.output-container > div:empty {
  display: none;
}
