:root {
  color-scheme: light;
  --bg: #e4e7ec;
  --glow-a: rgba(186, 204, 220, 0.85);
  --glow-b: rgba(226, 220, 210, 0.75);
  --paper: rgba(248, 249, 251, 0.94);
  --well: #ffffff;
  --ink: #1c2128;
  --muted: #5c6570;
  --line: rgba(28, 33, 40, 0.12);
  --line-strong: rgba(28, 33, 40, 0.26);
  --track: #d5dbe3;
  --accent: #3d5a73;
  --accent-hover: #4a6b87;
  --accent-ink: #f4f7fa;
  --wash: rgba(61, 90, 115, 0.14);
  --row: transparent;
  --row-hover: rgba(28, 33, 40, 0.04);
  --weak: #b5523a;
  --fair: #9a7040;
  --strong: #3d6484;
  --excellent: #234864;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.75) inset, 0 24px 60px rgba(28, 36, 48, 0.08);
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --mono: "Cascadia Mono", "Cascadia Code", "Segoe UI Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14181d;
    --glow-a: rgba(90, 120, 150, 0.22);
    --glow-b: rgba(48, 58, 70, 0.5);
    --paper: rgba(26, 31, 38, 0.92);
    --well: #1a1f26;
    --ink: #e7edf2;
    --muted: #a3b0bc;
    --line: rgba(231, 237, 242, 0.12);
    --line-strong: rgba(231, 237, 242, 0.26);
    --track: #2c343d;
    --accent: #8eabbf;
    --accent-hover: #a8c0d0;
    --accent-ink: #15202a;
    --wash: rgba(142, 171, 191, 0.16);
    --row: transparent;
    --row-hover: rgba(231, 237, 242, 0.04);
    --weak: #e7a090;
    --fair: #e0c08a;
    --strong: #9ebbd0;
    --excellent: #d5e4ef;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 24px 70px rgba(0, 0, 0, 0.38);
  }
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(60% 42% at 100% -8%, var(--glow-a), transparent 70%),
    radial-gradient(48% 40% at -8% 108%, var(--glow-b), transparent 68%),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

main {
  width: min(100%, 560px);
  margin-inline: auto;
  margin-block: auto;
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 2.65rem);
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 0.98;
}

.lede {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.45;
}

.panel {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.password-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.field {
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  min-height: 4.75rem;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--well);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 4px var(--wash);
}

.field.is-fresh textarea {
  animation: settle 0.35s ease;
}

@keyframes settle {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

textarea {
  display: block;
  width: 100%;
  max-height: 9.5rem;
  padding: 0;
  border: 0;
  border-radius: 0;
  resize: none;
  overflow: auto;
  background: transparent;
  font-family: var(--mono);
  font-size: 1.3rem;
  font-variant-ligatures: none;
  line-height: 1.4;
  letter-spacing: -0.02em;
  text-align: center;
  word-break: break-all;
  scrollbar-width: thin;
}

textarea:focus { outline: none; }

textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.meta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
}

.meta-text {
  flex: 1;
  min-width: 0;
}

.meter {
  display: flex;
  gap: 5px;
  width: min(100%, 220px);
}

.meter span {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--track);
}

.meter[data-level="weak"] span:nth-child(-n + 1),
.meter[data-level="fair"] span:nth-child(-n + 2),
.meter[data-level="strong"] span:nth-child(-n + 3),
.meter[data-level="excellent"] span:nth-child(-n + 4) {
  background: var(--level, var(--ink));
}

.meter[data-level="weak"] { --level: var(--weak); }
.meter[data-level="fair"] { --level: var(--fair); }
.meter[data-level="strong"] { --level: var(--strong); }
.meter[data-level="excellent"] { --level: var(--excellent); }

.strength {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

#strength-label[data-level="weak"] { color: var(--weak); }
#strength-label[data-level="fair"] { color: var(--fair); }
#strength-label[data-level="strong"] { color: var(--strong); }
#strength-label[data-level="excellent"] { color: var(--excellent); }

#edited-flag { color: var(--ink); }

.tool-actions {
  display: flex;
  align-self: flex-end;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--well);
  color: var(--ink);
}

.icon-btn svg { display: block; }
.icon-btn .icon-check { display: none; }

.icon-btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.icon-btn.is-copied {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.icon-btn.is-copied .icon-copy { display: none; }
.icon-btn.is-copied .icon-check { display: block; }

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

.icon-btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.length-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
}

.length-top label,
.options-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 2px;
}

.stepper button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 1.15rem;
  line-height: 1;
}

.stepper button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.stepper output {
  min-width: 2.2ch;
  font-family: var(--serif);
  font-size: 1.7rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
  text-align: center;
}

input[type="range"] {
  --pct: 14%;
  display: block;
  width: 100%;
  height: 28px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]:focus { outline: none; }

input[type="range"]:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--pct), var(--track) var(--pct));
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -8px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--well);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border: 0;
  border-radius: 999px;
  background: var(--track);
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--well);
  appearance: none;
}

.scale {
  display: flex;
  justify-content: space-between;
  margin-top: -2px;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.options-label {
  margin-bottom: 8px;
}

.toggles {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--row);
  overflow: hidden;
}

.toggle {
  position: relative;
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 8px;
  min-height: 44px;
  margin: 0;
  padding: 4px 12px 4px 10px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.toggle:first-child { border-top: 0; }

.glyph {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: -0.04em;
}

.toggle-name {
  font-size: 0.92rem;
  line-height: 1.2;
}

.toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.hint {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
}

.toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.track {
  position: relative;
  flex: none;
  width: 36px;
  height: 22px;
  border-radius: 999px;
  background: var(--track);
  transition: background 0.15s ease;
}

.thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
  transition: transform 0.15s ease;
}

.toggle:has(input:checked) .track { background: var(--accent); }

.toggle:has(input:checked) .thumb { transform: translateX(14px); }

.toggle:has(input:focus-visible) .track {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.toggle-note { min-height: 52px; }

.notice {
  margin: 0;
  color: var(--weak);
  font-size: 0.9rem;
  line-height: 1.4;
}

.footnote {
  margin: 14px 4px 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
}

@media (hover: hover) {
  .icon-btn:hover:not(:disabled):not(.primary):not(.is-copied),
  .stepper button:hover:not(:disabled) {
    background: var(--row-hover);
  }

  .toggle:hover { background: var(--row-hover); }

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

.icon-btn:active:not(:disabled) { transform: translateY(1px); }

@media (min-width: 900px) {
  main {
    width: min(1120px, calc(100% - 64px));
    padding-top: calc(40px + env(safe-area-inset-top));
    padding-bottom: calc(36px + env(safe-area-inset-bottom));
  }

  h1 { font-size: 3rem; }

  .panel {
    margin-top: 28px;
    padding: 28px 32px 26px;
  }

  .field { min-height: 6.6rem; }

  textarea { font-size: 1.85rem; }

  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(320px, 1.1fr);
    column-gap: 48px;
    row-gap: 20px;
    align-items: start;
    margin-top: 24px;
    padding-top: 24px;
  }

  .notice { grid-column: 1 / -1; }

  .footnote { text-align: left; }
}

@media (max-width: 380px) {
  h1 { font-size: 1.85rem; }
  .toggle-name { font-size: 0.88rem; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
