:root {
  --bg: #0f0f0f;
  --surface: #161616;
  --surface-2: #1d1d1d;
  --border: #262626;
  --text: #ededed;
  --muted: #8a8a8a;
  --accent: #e8e8e8;
  --accent-fg: #0f0f0f;
  --theme: #3a3a3a;
  --ok: #6ee7a0;
  --err: #ff8580;
  --radius: 14px;
  --gap: 14px;
  --pad: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100%;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 18px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100dvh;
}

.hdr {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 8px;
}

.hdr h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
}

.mode-toggle {
  background: transparent;
  border: 0;
  padding: 6px 4px;
  margin: -6px -4px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: auto;
  border-radius: 6px;
}

.mode-toggle .mode-opt {
  opacity: 0.4;
  transition: opacity 120ms ease, color 120ms ease;
}

.mode-toggle .mode-opt.active {
  opacity: 1;
  color: var(--text);
}

.mode-toggle .mode-sep {
  opacity: 0.3;
}

.mode-toggle:hover .mode-opt {
  opacity: 0.7;
}

.mode-toggle:hover .mode-opt.active {
  opacity: 1;
}

.mode-toggle:focus-visible {
  outline: 1px solid #3a3a3a;
  outline-offset: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.lbl {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 2px 2px -4px;
}

textarea,
input[type="password"],
input[type="text"] {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.45;
  outline: none;
  resize: vertical;
  transition: border-color 120ms ease, background 120ms ease;
}

textarea {
  min-height: 140px;
}

textarea:focus,
input:focus {
  border-color: var(--theme);
  background: #1f1f1f;
}

textarea[readonly] {
  background: #141414;
  color: #d8d8d8;
}

.key-row {
  display: flex;
  gap: 8px;
}

.key-row input {
  flex: 1;
}

button {
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 44px;
  transition: transform 80ms ease, background 120ms ease,
    border-color 120ms ease, color 120ms ease, opacity 120ms ease;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.primary {
  background: var(--accent);
  color: var(--accent-fg);
  width: 100%;
}

.primary:hover {
  background: #ffffff;
}

.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  padding: 10px 14px;
  min-width: 72px;
}

.ghost:hover {
  border-color: #3a3a3a;
  background: #1a1a1a;
}

.row {
  display: flex;
  gap: 8px;
}

.row .primary {
  flex: 1;
}

.status {
  font-size: 13px;
  color: var(--muted);
  margin: -2px 2px 0;
  min-height: 18px;
  font-family: var(--mono);
}

.status[data-kind="ok"] {
  color: var(--ok);
}

.status[data-kind="error"] {
  color: var(--err);
}

.output {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  margin-top: 4px;
  border-top: 1px dashed var(--border);
  padding-top: var(--gap);
}

.ftr {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  font-family: var(--mono);
  text-transform: uppercase;
  padding: 8px 0 0;
}

.ftr-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.link-btn {
  background: transparent;
  border: 0;
  padding: 4px 2px;
  margin: -4px -2px;
  min-height: 0;
  color: var(--muted);
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-decoration: none;
  cursor: pointer;
  border-radius: 4px;
}

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

.link-btn:focus-visible {
  outline: 1px solid #3a3a3a;
  outline-offset: 2px;
}

/* --- Modal --------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
  overflow: hidden;
  animation: panel-in 160ms ease-out;
}

@keyframes panel-in {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-hdr h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-section {
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-section legend {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding: 0;
  margin-bottom: 2px;
  font-family: var(--mono);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  font-family: var(--mono);
}

.hint-muted {
  opacity: 0.75;
}

.hint code {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text);
}

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

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

.icon-preview {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  object-fit: cover;
  flex: 0 0 auto;
}

.color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input[type="color"] {
  width: 100%;
  height: 44px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.modal-actions .primary {
  flex: 1;
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
    padding: 24px;
  }
  .modal-panel {
    border-radius: 16px;
    max-height: 80vh;
  }
}

@media (min-width: 640px) {
  .shell {
    padding-top: 56px;
  }
  .hdr h1 {
    font-size: 20px;
  }
}

::selection {
  background: #3a3a3a;
  color: #fff;
}
