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

html,
body {
  height: 100%;
}

:root {
  --bg: #F0EEE9;
  --surface: #FAFAF7;
  --ink: #232630;
  --muted: #6B7380;
  --line: #DDD9D1;
  --blue: #5285BE;
  --blue-soft: #EBF0F8;
  --meter-ok: #2E6CA8;
  --green: #2A7430;
  --green-soft: #E8F3EA;
  --warn: #9A5A00;
  --warn-soft: #FEF3E2;
  --validity-label: #5E6470;
  --danger: #B83030;
  --r: 0.75rem;
  --r-sm: 0.625rem;
  --r-xs: 0.375rem;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1B1E25;
    --surface: #22262F;
    --ink: #E5E2DB;
    --muted: #8890A0;
    --line: #2E333E;
    --blue: #7AADD8;
    --blue-soft: #1D2A40;
    --meter-ok: #7AADD8;
    --green: #7DC285;
    --green-soft: #1C2E1F;
    --warn: #E8A030;
    --warn-soft: #2C2210;
    --validity-label: #969DAC;
    --danger: #E07070;
  }
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input {
  font-family: inherit;
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

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


/* ─── Layout ─────────────────────────────────── */

.app {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.view {
  width: 100%;
  max-width: 440px;
}


/* ─── Brand ──────────────────────────────────── */

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

.brand__mark {
  display: flex;
  flex-shrink: 0;
  height: 4rem;
}

.brand__wordmark {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--ink);
}


/* ─── Header ──────────────────────────────────── */

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

.header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header__lang-toggle {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  cursor: pointer;
  padding: 5px 9px;
  font-size: .78rem;
  letter-spacing: .05em;
}

.header__lang-toggle span {
  color: var(--muted);
  font-weight: 500;
  font-family: var(--mono);
}

.header__lang-toggle span + span {
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.header__lang-toggle[data-active="de"] span[data-l="de"],
.header__lang-toggle[data-active="en"] span[data-l="en"] {
  color: var(--blue);
  font-weight: 700;
}

.header__add-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  border: none;
  background: var(--blue);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header__add-btn:hover {
  filter: brightness(1.08);
}

.header__back {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .9rem;
  color: var(--blue);
  font-weight: 600;
}

.header__back-chevron {
  font-size: 1.2rem;
  line-height: 1;
}


/* ─── Divider ─────────────────────────────────── */

.divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0 18px;
}


/* ─── Instruction ─────────────────────────────── */

.instruction {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.6;
}

.instruction b {
  color: var(--ink);
  font-weight: 600;
}


/* ─── Validity strip ──────────────────────────── */

.validity {
  margin-bottom: 20px;
}

.validity__stamp {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px;
  background: var(--green-soft);
  border-radius: var(--r-sm);
  margin-bottom: 10px;
}

.validity--warn .validity__stamp {
  background: var(--warn-soft);
}

.validity__stamp-label {
  color: var(--validity-label);
  font-size: .78rem;
  font-weight: 500;
}

.validity__stamp-time {
  color: var(--green);
  font-family: var(--mono);
  font-size: .95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.validity--warn .validity__stamp-time {
  color: var(--warn);
}

.validity__bar {
  height: 3px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.validity__bar-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width .25s linear;
}

.validity--warn .validity__bar-fill {
  background: var(--warn);
}


/* ─── Card list ───────────────────────────────── */

.card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}


/* ─── Card ────────────────────────────────────── */

.card {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 15px 17px;
  background: var(--surface);
}

.card__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.card__name {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card__tag {
  font-family: var(--mono);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 2px 7px;
}

.card__delete {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  padding: 3px 6px;
  border-radius: var(--r-xs);
}

.card__delete:hover {
  color: var(--danger);
  background: #fef2f2;
}

.card__word {
  font-family: var(--mono);
  font-size: clamp(1.9rem, 8vw, 2.6rem);
  font-weight: 700;
  text-transform: capitalize;
  line-height: 1.08;
  word-break: break-word;
  color: var(--ink);
  transition: opacity .18s ease;
  min-height: 1.08em;
}

.card__confirm {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: .85rem;
  color: var(--muted);
}

.card__confirm-text {
  flex: 1;
}

.card__confirm-yes {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: .84rem;
}

.card__confirm-yes:hover {
  filter: brightness(1.08);
}

.card__confirm-no {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: .84rem;
}


/* ─── Empty state ─────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 44px 12px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-state__icon {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.empty-state__icon svg {
  width: 28px;
  height: 28px;
}

.empty-state__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}

.empty-state__body {
  margin: 0 0 8px;
  color: var(--muted);
  max-width: 32ch;
  line-height: 1.6;
  font-size: .88rem;
}


/* ─── Buttons ─────────────────────────────────── */

.btn--primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--blue);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
}

.btn--primary:hover {
  filter: brightness(1.08);
}

.btn--primary:disabled {
  opacity: .4;
  cursor: default;
  filter: none;
}


/* ─── Form ────────────────────────────────────── */

.form__title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -.01em;
  margin: 0 0 22px;
  color: var(--ink);
}

.form__field {
  margin-bottom: 16px;
}

.form__label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
}

.form__input {
  width: 100%;
  font-size: 1rem;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  outline: none;
  font-family: var(--sans);
}

.form__input::placeholder {
  color: var(--muted);
  opacity: .6;
}

.form__input:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
  outline: none;
}

.form__show-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: .85rem;
  cursor: pointer;
  user-select: none;
}

.form__show-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
}

.form__strength {
  margin-top: 10px;
}

.form__strength-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}

.form__strength-bar > span {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  transition: background-color .2s ease;
}

.form__strength-text {
  display: block;
  min-height: 1.2em;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
}

.form__strength[data-level="weak"] .form__strength-bar > span:nth-child(-n+1),
.form__strength[data-level="ok"] .form__strength-bar > span:nth-child(-n+2),
.form__strength[data-level="strong"] .form__strength-bar > span {
  background: currentColor;
}

.form__strength[data-level="weak"] {
  color: var(--warn);
}

.form__strength[data-level="ok"] {
  color: var(--meter-ok);
}

.form__strength[data-level="strong"] {
  color: var(--green);
}

.form__strength[data-level="weak"] .form__strength-text,
.form__strength[data-level="ok"] .form__strength-text,
.form__strength[data-level="strong"] .form__strength-text {
  color: inherit;
}

.form__note {
  margin-top: 16px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.65;
}

.form__error {
  margin-top: 14px;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--r-sm);
  padding: 11px 13px;
  font-size: .87rem;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  .form__error {
    background: #2C1818;
    border-color: #4A2424;
  }
}


/* ─── Language segment ────────────────────────── */

.lang-seg {
  display: flex;
  gap: 8px;
  margin: 8px 0 22px;
}

.lang-seg__option {
  flex: 1;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--sans);
  color: var(--ink);
}

.lang-seg__option--active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
}


/* ─── Footer ──────────────────────────────────── */

.footer {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-size: .75rem;
  line-height: 1.7;
}

.footer__name {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.footer__changelog {
  color: inherit;
  text-decoration: none;
}

.footer__name:hover,
.footer__changelog:hover {
  text-decoration: underline;
}

/* ─── Boot spinner ───────────────────────────── */

.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.boot__spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--blue);
  animation: boot-spin .7s linear infinite;
}

@keyframes boot-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .boot__spinner {
    animation-duration: 1.6s;
  }
}
