:root {
  --bg: #f3f4f2;
  --surface: #ffffff;
  --surface-strong: #111111;
  --text: #1f2323;
  --muted: #66706b;
  --line: #d9ded9;
  --accent: #5f6b67;
  --accent-strong: #35403d;
  --warm: #bd7b61;
  --danger: #a23b3b;
  --radius: 8px;
  --shadow: 0 18px 36px rgba(31, 35, 35, 0.12);
  --shadow-soft: 0 8px 18px rgba(31, 35, 35, 0.1);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 260px),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  transition:
    background-color 160ms var(--ease),
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease),
    color 160ms var(--ease),
    transform 160ms var(--ease);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

img {
  max-width: 100%;
  display: block;
}

.noscript {
  padding: 16px;
  color: #ffffff;
  background: var(--danger);
  text-align: center;
}

.app-shell {
  width: min(1220px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0 28px;
  animation: shell-enter 420ms var(--ease) both;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 18px;
}

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

.brand-icon {
  width: 40px;
  height: 40px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 2rem;
  line-height: 1;
  font-weight: 400;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.2;
  font-weight: 800;
}

h3 {
  font-size: 1rem;
  line-height: 1.25;
  font-weight: 900;
}

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.app-intro {
  max-width: 720px;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.45;
  font-weight: 700;
}

.key-status,
.ghost-button,
.icon-text-button,
.primary-button,
.secondary-button,
.file-button,
.segment,
.close-button {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.key-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
}

.key-status:hover,
.ghost-button:hover,
.icon-text-button:hover,
.secondary-button:hover,
.segment:hover,
.close-button:hover {
  border-color: #b8c0ba;
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

.primary-button:hover,
.file-button:hover {
  background: #283331;
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

.key-status:active,
.ghost-button:active,
.icon-text-button:active,
.primary-button:active,
.secondary-button:active,
.file-button:active,
.segment:active,
.close-button:active {
  transform: translateY(0) scale(0.98);
}

.key-status.is-ready {
  border-color: rgba(47, 133, 90, 0.42);
  box-shadow: 0 0 0 4px rgba(47, 133, 90, 0.08);
}

.key-status.is-updated {
  animation: soft-pop 520ms var(--ease);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

.status-dot.is-ready {
  background: #2f855a;
  animation: dot-ready 420ms var(--ease);
}

.app-grid {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: stretch;
  padding-top: 18px;
}

.mode-list {
  display: grid;
  gap: 14px;
  align-content: start;
}

.mode-card {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 158px;
  padding: 20px 14px;
  color: #ffffff;
  background-color: #303838;
  background-position: center;
  background-size: cover;
  border: 0;
  border-radius: var(--radius);
  text-align: center;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(31, 35, 35, 0.16);
  isolation: isolate;
  transform: translateY(0) scale(1);
  transition:
    box-shadow 220ms var(--ease),
    filter 220ms var(--ease),
    transform 220ms var(--ease);
  animation: card-enter 480ms var(--ease) both;
}

.mode-card:nth-of-type(2) {
  animation-delay: 45ms;
}

.mode-card:nth-of-type(3) {
  animation-delay: 90ms;
}

.mode-card:nth-of-type(4) {
  animation-delay: 135ms;
}

.mode-card:nth-of-type(5) {
  animation-delay: 180ms;
}

.mode-card::before,
.mode-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.mode-card::before {
  z-index: 0;
  background: rgba(17, 17, 17, 0.5);
  transition: background 220ms var(--ease), transform 420ms var(--ease);
}

.mode-card::after {
  z-index: 2;
  opacity: 0;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  transition: opacity 160ms var(--ease);
}

.mode-card.is-active {
  color: #ffffff;
}

.mode-card img {
  position: relative;
  z-index: 1;
  width: 64px;
  height: 64px;
  object-fit: contain;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.35));
  transition: transform 220ms var(--ease), filter 220ms var(--ease);
}

.mode-card span {
  position: relative;
  z-index: 1;
  max-width: 100%;
  padding: 4px 9px 5px;
  color: #ffffff;
  background: rgba(17, 17, 17, 0.22);
  border: 3px solid #ffffff;
  border-radius: 5px;
  font-size: 1.02rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-shadow: 0 2px 7px rgba(0, 0, 0, 0.35);
}

.mode-card:hover::after,
.mode-card:focus-visible::after,
.mode-card.is-active::after {
  opacity: 1;
}

.mode-card:hover,
.mode-card:focus-visible {
  box-shadow: 0 18px 30px rgba(31, 35, 35, 0.22);
  filter: saturate(1.06);
  transform: translateY(-3px);
}

.mode-card:hover::before,
.mode-card:focus-visible::before {
  background: rgba(17, 17, 17, 0.38);
  transform: scale(1.03);
}

.mode-card:hover img,
.mode-card:focus-visible img {
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.42));
  transform: scale(1.06);
}

.mode-card:active {
  transform: translateY(-1px) scale(0.99);
}

.mode-card[data-mode="text"] {
  background-image: url("https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?auto=format&fit=crop&w=900&q=80");
}

.mode-card[data-mode="gesture"] {
  background-image: url("https://images.unsplash.com/photo-1736470250162-fc52fdc66901?auto=format&fit=crop&w=900&q=80");
}

.mode-card[data-mode="link"] {
  background-image: url("https://images.unsplash.com/photo-1511831030-bec461ccd88e?auto=format&fit=crop&w=900&q=80");
}

.mode-card[data-mode="scan"] {
  background-image: url("https://images.unsplash.com/photo-1718486463454-a29ee090f0c5?auto=format&fit=crop&w=900&q=80");
}

.mode-card[data-action="key"] {
  background-image: url("https://images.unsplash.com/photo-1605211713889-080f454cc6a5?auto=format&fit=crop&w=900&q=80");
}

.quick-guide {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  color: var(--muted);
}

.guide-step {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(217, 222, 217, 0.9);
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.25;
  animation: step-enter 420ms var(--ease) both;
}

.guide-step:nth-child(2) {
  animation-delay: 70ms;
}

.guide-step:nth-child(3) {
  animation-delay: 140ms;
}

.guide-step b {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  color: #ffffff;
  background: var(--accent);
  border-radius: 50%;
  font-size: 0.78rem;
}

.workspace,
.output-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: surface-enter 420ms var(--ease) both;
}

.workspace {
  min-height: 650px;
  padding: 18px;
}

.workspace-header,
.panel-line,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.workspace-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.mobile-back-button {
  display: none;
}

.input-stack {
  margin-top: 18px;
}

.input-panel {
  min-height: 540px;
}

.input-panel.is-active {
  animation: panel-enter 280ms var(--ease) both;
}

.input-panel[hidden] {
  display: none;
}

label,
.setting-group > span,
.panel-line > span {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-weight: 900;
}

.helper-text {
  max-width: 64ch;
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  color: var(--text);
  background: #f9faf8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition:
    background-color 160ms var(--ease),
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease);
}

input {
  min-height: 46px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
}

input:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--accent);
  outline: 3px solid rgba(93, 101, 101, 0.2);
  outline-offset: 2px;
}

input:focus,
textarea:focus {
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(31, 35, 35, 0.08);
}

.secret-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 8px;
}

.gesture-pad,
.scanner {
  position: relative;
  min-height: 420px;
  overflow: hidden;
  background: #ecefed;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.gesture-pad {
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}

.gesture-pad::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px dashed #b9c0ba;
  border-radius: var(--radius);
  transition: border-color 180ms var(--ease), inset 180ms var(--ease);
}

.gesture-pad:hover,
.gesture-pad:focus-visible {
  border-color: #b8c0ba;
  box-shadow: inset 0 0 0 1px rgba(95, 107, 103, 0.16);
}

.gesture-pad:hover::before,
.gesture-pad:focus-visible::before {
  inset: 12px;
  border-color: #9fa8a2;
}

#gestureArrow {
  width: 76px;
  height: 74px;
  opacity: 0;
  transform: rotate(0deg) scale(0.86);
  transition: opacity 120ms ease, transform 120ms ease;
}

#gestureArrow.is-visible {
  opacity: 0.88;
  transform: rotate(var(--arrow-rotation, 0deg)) scale(1);
  animation: arrow-pop 180ms var(--ease);
}

#gestureArrow.is-up {
  --arrow-rotation: 0deg;
}

#gestureArrow.is-right {
  --arrow-rotation: 90deg;
}

#gestureArrow.is-down {
  --arrow-rotation: 180deg;
}

#gestureArrow.is-left {
  --arrow-rotation: 270deg;
}

.input-trail {
  display: block;
  min-height: 42px;
  margin-top: 12px;
  padding: 9px 11px;
  color: #ffffff;
  background: var(--surface-strong);
  border-radius: var(--radius);
  overflow-wrap: anywhere;
  transition: background-color 160ms var(--ease), transform 160ms var(--ease);
}

.pattern-wrap {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 86px);
  grid-template-rows: repeat(3, 86px);
  place-content: center;
  gap: 34px;
  min-height: 420px;
  background: #f7f8f6;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  touch-action: none;
  user-select: none;
}

.pattern-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pattern-dot {
  position: relative;
  z-index: 1;
  width: 86px;
  height: 86px;
  padding: 0;
  background: #fdfdfc;
  border: 2px solid #aeb7b0;
  border-radius: 50%;
  transition:
    background-color 160ms var(--ease),
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease),
    transform 160ms var(--ease);
}

.pattern-dot::after {
  content: attr(data-cell);
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 900;
}

.pattern-dot.is-selected {
  background: var(--accent);
  border-color: var(--accent-strong);
  box-shadow: 0 10px 18px rgba(53, 64, 61, 0.2);
  transform: scale(1.04);
}

.pattern-dot.is-selected::after {
  color: #ffffff;
}

.scanner video,
.scanner canvas {
  width: 100%;
  height: 420px;
  display: block;
  object-fit: cover;
  background: #1c2020;
}

.scan-status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  padding: 8px 10px;
  color: #ffffff;
  background: rgba(17, 17, 17, 0.86);
  border-radius: var(--radius);
  font-weight: 800;
  animation: status-enter 220ms var(--ease) both;
}

.scan-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.output-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.password-output {
  min-height: 84px;
  padding: 14px;
  color: #ffffff;
  background: var(--surface-strong);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 1.05rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  transition: box-shadow 180ms var(--ease), transform 180ms var(--ease);
}

.password-output.is-updated {
  animation: password-ready 620ms var(--ease);
}

.message-line {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.message-line.is-live {
  animation: message-enter 240ms var(--ease) both;
}

.message-line.is-error {
  color: var(--danger);
}

.setting-group {
  display: grid;
  gap: 8px;
}

.length-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

input[type="range"] {
  min-height: auto;
  padding: 0;
  accent-color: var(--accent);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.segment {
  color: var(--text);
  background: #f8f9f7;
  border-color: var(--line);
  text-align: left;
}

.segment.is-active {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.primary-button,
.file-button {
  color: #ffffff;
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  text-align: center;
}

.secondary-button,
.ghost-button,
.icon-text-button {
  color: var(--text);
  background: #f8f9f7;
  border-color: var(--line);
}

.primary-button.is-pressed,
.secondary-button.is-pressed,
.ghost-button.is-pressed,
.icon-text-button.is-pressed,
.file-button.is-pressed {
  animation: soft-pop 420ms var(--ease);
}

.ghost-button.compact {
  min-height: 34px;
  padding: 0 10px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.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;
}

.copy-buffer {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.key-dialog {
  width: min(480px, calc(100% - 28px));
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
}

.key-dialog::backdrop {
  background: rgba(17, 17, 17, 0.46);
}

.dialog-surface {
  display: grid;
  gap: 12px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.close-button {
  min-width: 42px;
  padding: 0;
  color: var(--text);
  background: #f8f9f7;
  border-color: var(--line);
}

@keyframes shell-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes step-enter {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes surface-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes status-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes message-enter {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes password-ready {
  0% {
    box-shadow: 0 0 0 0 rgba(47, 133, 90, 0);
    transform: scale(1);
  }
  38% {
    box-shadow: 0 0 0 6px rgba(47, 133, 90, 0.16);
    transform: scale(1.01);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(47, 133, 90, 0);
    transform: scale(1);
  }
}

@keyframes soft-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.035);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes dot-ready {
  0% {
    transform: scale(0.7);
  }
  60% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes arrow-pop {
  from {
    filter: drop-shadow(0 0 0 rgba(53, 64, 61, 0));
  }
  to {
    filter: drop-shadow(0 8px 14px rgba(53, 64, 61, 0.22));
  }
}

@media (max-width: 980px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  .mode-list {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .mode-card {
    min-width: 0;
    min-height: 174px;
    text-align: center;
  }

  .output-panel {
    order: 3;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 6px;
  }

  .app-shell:not(.is-tool-open) .workspace,
  .app-shell:not(.is-tool-open) .output-panel {
    display: none;
  }

  .app-shell.is-tool-open .app-intro,
  .app-shell.is-tool-open .quick-guide,
  .app-shell.is-tool-open .mode-card:not(.is-active),
  .app-shell.is-tool-open .mode-card[data-action="key"] {
    display: none;
  }

  .app-grid {
    gap: 10px;
    padding-top: 10px;
  }

  .topbar {
    align-items: center;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 12px;
  }

  .brand {
    justify-content: center;
    text-align: center;
  }

  h1 {
    font-size: 2.25rem;
  }

  .app-intro {
    margin: 0 auto;
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.4;
  }

  .mode-list {
    gap: 9px;
  }

  .mode-card {
    min-height: 132px;
    padding: 14px 12px;
  }

  .mode-card img {
    width: 54px;
    height: 54px;
  }

  .app-shell.is-tool-open .mode-card.is-active {
    grid-template-columns: auto minmax(0, 1fr);
    justify-items: start;
    place-items: center start;
    min-height: 78px;
    padding: 12px 14px;
    text-align: left;
    animation: surface-enter 260ms var(--ease) both;
  }

  .app-shell.is-tool-open .mode-card.is-active img {
    width: 46px;
    height: 46px;
  }

  .quick-guide {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .guide-step {
    align-items: center;
    justify-content: center;
    min-height: 56px;
    padding: 7px 4px;
    flex-direction: column;
    gap: 5px;
    text-align: center;
    font-size: 0.78rem;
  }

  .guide-step b {
    width: 22px;
    height: 22px;
  }

  .workspace,
  .output-panel {
    padding: 13px;
  }

  .app-shell.is-tool-open .workspace,
  .app-shell.is-tool-open .output-panel {
    animation: panel-enter 320ms var(--ease) both;
  }

  .workspace {
    min-height: auto;
  }

  .workspace-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace-actions {
    width: 100%;
  }

  .workspace-actions .ghost-button {
    flex: 1 1 0;
  }

  .mobile-back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .input-panel {
    min-height: auto;
  }

  .gesture-pad,
  .scanner,
  .scanner video,
  .scanner canvas,
  .pattern-wrap {
    min-height: 330px;
  }

  .pattern-wrap {
    grid-template-columns: repeat(3, 66px);
    grid-template-rows: repeat(3, 66px);
    gap: 24px;
  }

  .pattern-dot {
    width: 66px;
    height: 66px;
  }

  .secret-row,
  .length-row,
  .scan-actions,
  .button-grid,
  .dialog-actions {
    grid-template-columns: 1fr;
  }
}
