:root {
  color-scheme: light;
  --ink: #153038;
  --muted: #60767c;
  --paper: #f4f8f7;
  --surface: #ffffff;
  --line: #dce7e5;
  --brand: #147a72;
  --brand-dark: #0f5c58;
  --accent: #d7f568;
  --danger: #a13d42;
  --shadow: 0 18px 50px rgba(21, 48, 56, 0.10);
  --radius: 24px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 95% -10%, rgba(215, 245, 104, .33), transparent 26rem),
    linear-gradient(180deg, #f9fbfa 0, var(--paper) 40rem);
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

body.is-booting { overflow: hidden; }
.app-root {
  min-height: 100vh;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity .34s ease, transform .34s ease, visibility 0s linear .34s;
}
body.is-ready .app-root {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: .08s, .08s, 0s;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 10px max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  background: rgba(249, 251, 250, .86);
  border-bottom: 1px solid rgba(220, 231, 229, .75);
  backdrop-filter: blur(18px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.16rem;
  text-decoration: none;
  letter-spacing: -.02em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--accent);
  background: var(--ink);
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(21, 48, 56, .18);
}
.brand-mark svg { width: 28px; height: 28px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  cursor: pointer;
}
.icon-button svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-button:hover { border-color: var(--brand); color: var(--brand); }

.page-shell {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 44px 0 110px;
}
.app-notice {
  display: block;
  position: sticky;
  top: 82px;
  z-index: 8;
  margin: 0 0 22px;
  padding: 12px 15px;
  color: var(--brand-dark);
  font-size: .86rem;
  font-weight: 750;
  border: 1px solid #bcdad4;
  border-radius: 14px;
  background: #edf8f5;
  box-shadow: 0 10px 28px rgba(21,48,56,.08);
}
.app-notice[data-type="error"] { color: var(--danger); border-color: #ecc7c9; background: #fff1f1; }
.hero { max-width: 710px; margin-bottom: 42px; }
.eyebrow {
  margin: 0 0 9px;
  color: var(--brand);
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .13em;
}
h1, h2, p { text-wrap: pretty; }
h1 { margin: 0; font-size: clamp(2.1rem, 7vw, 4.8rem); line-height: .99; letter-spacing: -.055em; }
.hero > p:last-child { max-width: 650px; margin: 20px 0 0; color: var(--muted); font-size: clamp(1rem, 2.4vw, 1.22rem); line-height: 1.6; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 18px; }
.section-heading h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.025em; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }

.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(180px, 43vw), 1fr));
  gap: 16px;
  align-items: start;
}
.shortcut-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(21, 48, 56, .055);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.shortcut-card:hover { transform: translateY(-2px); border-color: #c7dad6; box-shadow: var(--shadow); }
.shortcut-face {
  position: relative;
  display: block;
  width: 100%;
  height: 184px;
  min-height: 184px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.shortcut-face:focus-visible { outline: 3px solid rgba(20,122,114,.28); outline-offset: -4px; }
.shortcut-icon-stage {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.favicon-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: #f5f8f7;
}
.favicon { width: 34px; height: 34px; object-fit: contain; }
.favicon-fallback { display: none; font-weight: 900; font-size: 1.2rem; color: var(--brand-dark); }
.favicon-wrap.is-fallback .favicon { display: none; }
.favicon-wrap.is-fallback .favicon-fallback { display: block; }
.shortcut-name {
  position: absolute;
  right: 56px;
  bottom: 36px;
  left: 18px;
  overflow: hidden;
  font-size: 1.07rem;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.shortcut-host {
  position: absolute;
  right: 56px;
  bottom: 18px;
  left: 18px;
  overflow: hidden;
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.qr-mini {
  position: absolute;
  right: 12px;
  top: 136px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--brand);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 5px 14px rgba(21,48,56,.08);
  cursor: pointer;
}
.qr-mini:hover, .qr-mini:focus-visible { color: var(--brand-dark); border-color: #bfd6d1; background: #f1f8f6; }
.qr-mini svg { width: 21px; height: 21px; fill: currentColor; }
.expand-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 18px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 750;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fbfcfc;
  cursor: pointer;
}
.expand-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 2; transition: transform .2s ease; }
.expand-button[aria-expanded="true"] svg { transform: rotate(180deg); }
.shortcut-details { display: grid; gap: 13px; padding: 17px; border-top: 1px solid var(--line); }
.shortcut-details[hidden] { display: none; }

.field { display: grid; gap: 7px; margin-bottom: 17px; }
.field > span { color: var(--ink); font-size: .82rem; font-weight: 750; }
.field small { color: var(--muted); font-weight: 500; }
.field input, .field select {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  background: #fbfcfc;
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(20, 122, 114, .12); }
.compact-field { margin: 0; }
.compact-field input, .compact-field select { height: 42px; font-size: .85rem; }
.input-action-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.input-action-row input { border-radius: 13px 0 0 13px; }
.field-action {
  padding: 0 12px;
  color: var(--brand-dark);
  font-size: .75rem;
  font-weight: 800;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 13px 13px 0;
  background: #eef7f5;
  cursor: pointer;
}
.template-fields {
  display: grid;
  gap: 0;
  min-width: 0;
  margin: 0 0 17px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #f8fbfa;
}
.template-fields[hidden] { display: none; }
.template-fields legend { padding: 0 7px; color: var(--brand-dark); font-size: .78rem; font-weight: 850; }
.template-fields .field:last-of-type { margin-bottom: 0; }
.compact-template-fields { gap: 12px; margin: 0; padding: 12px; }
.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.template-note { margin: 2px 0 0; color: var(--muted); font-size: .75rem; line-height: 1.45; }
.detail-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; }
.save-state { color: var(--muted); font-size: .72rem; }
.danger-link { padding: 5px; color: var(--danger); font-size: .75rem; font-weight: 750; border: 0; background: transparent; cursor: pointer; }

.floating-add {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 19px;
  color: #fff;
  font-weight: 800;
  border: 0;
  border-radius: 18px;
  background: var(--brand-dark);
  box-shadow: 0 14px 30px rgba(15, 92, 88, .28);
  cursor: pointer;
}
.floating-add svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.dialog {
  width: min(520px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  overflow: auto;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(21, 48, 56, .3);
}
.dialog::backdrop { background: rgba(8, 26, 30, .55); backdrop-filter: blur(6px); }
.dialog > form, .qr-dialog { padding: 24px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.dialog-header h2 { margin: 0; font-size: 1.55rem; letter-spacing: -.035em; }
.dialog-close { flex: 0 0 auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  font-weight: 800;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 15px;
  cursor: pointer;
}
.button-primary { color: white; background: var(--brand-dark); }
.button-secondary { color: var(--ink); border-color: var(--line); background: var(--surface); }
.security-note, .qr-help { color: var(--muted); font-size: .78rem; line-height: 1.5; }
.security-note { padding: 11px 13px; border: 1px solid #eadba5; border-radius: 12px; background: #fff9e5; }

.qr-frame { display: grid; place-items: center; width: min(280px, 76vw); aspect-ratio: 1; margin: 0 auto 18px; padding: 18px; border: 1px solid var(--line); border-radius: 26px; background: white; }
.qr-frame img, .qr-frame canvas { width: 100% !important; height: 100% !important; image-rendering: pixelated; }
.qr-name { margin: 0; text-align: center; font-size: 1.12rem; font-weight: 850; }
.qr-url { display: block; max-width: 420px; margin: 8px auto 0; overflow-wrap: anywhere; color: var(--muted); font-size: .72rem; text-align: center; }
.qr-help { max-width: 420px; margin: 14px auto 0; text-align: center; }

.startup-overlay, .login-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  color: #ffffff;
  background-color: #0d2f36;
}
.startup-overlay {
  z-index: 100;
  opacity: 1;
  visibility: visible;
  transition: opacity .34s ease, visibility 0s linear 0s;
}
body.is-ready .startup-overlay {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .34s ease, visibility 0s linear .34s;
}
.startup-overlay[hidden] { display: none; }
.login-overlay {
  z-index: 110;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  background-color: #0d2f36;
  transition: opacity .25s ease, visibility 0s linear .25s;
}
.login-overlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity .25s ease, visibility 0s linear 0s;
}
.login-overlay[hidden] { display: none; }
.startup-panel { width: min(430px, 100%); text-align: center; }
.key-stage { display: grid; place-items: center; height: 230px; perspective: 900px; }
.key-spinner { width: 96px; height: 174px; color: var(--accent); transform-style: preserve-3d; animation: key-turn 1.2s linear infinite; filter: drop-shadow(0 18px 24px rgba(0,0,0,.28)); }
.key-spinner svg { width: 100%; height: 100%; }
@keyframes key-turn { from { transform: rotateY(0deg); } to { transform: rotateY(360deg); } }
.startup-panel .eyebrow { color: var(--accent); }
.startup-panel h1 { margin: 0; font-size: clamp(1.9rem, 8vw, 3rem); line-height: 1.05; letter-spacing: -.045em; }
.startup-message { display: block; min-height: 28px; margin: 13px 0 0; color: #dce8e8; line-height: 1.55; }
.progress-track { height: 5px; margin: 26px auto 0; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.12); }
.progress-track span { display: block; width: 40%; height: 100%; border-radius: inherit; background: var(--accent); animation: progress-sweep 1.2s ease-in-out infinite; }
@keyframes progress-sweep { 0% { transform: translateX(-110%); } 100% { transform: translateX(360%); } }

@media (max-width: 560px) {
  .page-shell { width: min(100% - 24px, 1080px); padding-top: 30px; }
  .hero { margin-bottom: 34px; }
  .shortcut-grid { gap: 12px; }
  .shortcut-face { height: 164px; min-height: 164px; }
  .shortcut-icon-stage { width: 88px; height: 88px; }
  .shortcut-name { font-size: .95rem; }
  .qr-mini { top: 116px; }
  .field-pair { grid-template-columns: 1fr; gap: 0; }
  .dialog { border-radius: 23px; }
  .dialog > form, .qr-dialog { padding: 19px; }
  .floating-add { width: 52px; padding: 0; justify-content: center; }
  .floating-add span { display: none; }
  .stacked-mobile { flex-direction: column-reverse; }
  .stacked-mobile .button { width: 100%; }
}

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

/* Compact shortcut detail tabs */
.detail-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #f1f6f5;
}
.detail-tabs button {
  min-width: 0;
  min-height: 44px;
  padding: 5px;
  color: var(--muted);
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.detail-tabs button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.detail-tabs button[aria-selected="true"] {
  color: var(--brand-dark);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(21, 48, 56, .12);
}
.detail-tabs button:focus-visible { outline: 3px solid rgba(20, 122, 114, .22); outline-offset: 1px; }
.detail-panel { display: grid; gap: 12px; min-width: 0; }
.detail-panel[hidden] { display: none; }
.detail-panel .template-fields { margin: 0; }

.app-notice[hidden] { display: none; }

@media (max-width: 560px) {
  .detail-tabs button {
    min-height: 44px;
    padding: 4px;
  }
  .detail-tabs button svg { width: 18px; height: 18px; }
}
