.app-body { background: var(--canvas); }
.app-shell { display: grid; min-height: 100dvh; grid-template-columns: 1fr; align-content: start; }
.auth-shell { display: grid; min-height: 100dvh; place-items: center; padding: var(--s5) var(--s4); background: var(--canvas); }
.auth-card { display: flex; width: min(100%, 430px); flex-direction: column; gap: var(--s5); padding: var(--s6); }
.auth-brand { align-self: flex-start; }
.auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.auth-message { min-height: 1.5em; text-align: center; }
.user-email { max-width: 220px; overflow: hidden; color: var(--ink-muted); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }

.app-topbar, .topbar {
  display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: var(--s4);
  position: sticky; top: 0; z-index: 6; min-height: 56px; padding: var(--s2) var(--s4); border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar-right { display: flex; align-items: center; gap: var(--s3); }
.avatar, .user-avatar {
  display: inline-grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; color: #765013;
  background: #f3d9a9; font-family: var(--display); font-size: .8125rem; font-weight: 700;
}

.tabs {
  display: flex; position: sticky; top: 56px; z-index: 5; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s2) var(--s4); border-bottom: 1px solid var(--line); background: var(--surface); scrollbar-width: none;
}
.top-nav-links { display: flex; min-width: 0; gap: var(--s1); overflow-x: auto; scrollbar-width: none; }
.top-nav-links::-webkit-scrollbar { display: none; }
.top-nav-actions { display: flex; flex: 0 0 auto; align-items: center; gap: var(--s3); margin-left: auto; }
.tabs a {
  display: inline-flex; min-height: 40px; flex: 0 0 auto; align-items: center; padding: 0 12px; border-radius: var(--r-sm);
  color: var(--ink-soft); font-size: .875rem; font-weight: 600;
}
.tabs a:hover, .tabs a[aria-current="page"] { color: var(--ink); background: #f3f6f8; text-decoration: none; }
.top-nav-reset { min-height: 32px; padding: 0; color: var(--ink-muted); background: transparent; font-size: .75rem; text-decoration: underline; }
.top-nav-reset:hover { color: var(--danger); }

.main, .dashboard-main { min-width: 0; padding: var(--s5) var(--s4) var(--s8); }
.main-inner { width: min(100%, 760px); margin: 0 auto; }
.dashboard-view { display: flex; flex-direction: column; gap: var(--s5); }

.notice {
  display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4); border: 1px solid var(--info-line);
  border-radius: var(--r-md); color: #624e1a; background: var(--info-bg); box-shadow: var(--sh-sm);
}
.notice p { color: #624e1a; font-size: .875rem; line-height: 1.5; }
.notice .icon-btn { flex: 0 0 auto; margin: -4px -6px -4px auto; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4); }
.head-text { display: flex; flex-direction: column; gap: var(--s2); }
.page-head h1 { color: var(--ink); font-size: clamp(1.875rem, 5vw, 2.5rem); font-weight: 700; letter-spacing: -.035em; line-height: 1.05; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--s2); }
.profile-switcher { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.profile-switcher .select { min-width: 150px; max-width: 220px; min-height: 40px; }

.qr-dialog {
  width: min(400px, calc(100% - 32px)); max-width: calc(100% - 32px); padding: 0; border: 0; border-radius: var(--r-lg);
  color: var(--ink); background: transparent; box-shadow: var(--sh-lg);
}
.qr-dialog:not([open]) { display: none; }
.qr-dialog::backdrop { background: rgba(16, 39, 60, .48); backdrop-filter: blur(3px); }
.qr-dialog-card { display: flex; flex-direction: column; gap: var(--s4); padding: var(--s5); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.qr-dialog-card .card-head { align-items: center; }
.qr-code-frame { display: grid; width: 100%; place-items: center; padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r-md); background: #fff; }
.qr-code-frame svg { display: block; width: min(100%, 280px); height: auto; }
.qr-dialog-copy { color: var(--ink-soft); font-size: .875rem; line-height: 1.5; text-align: center; }
.qr-page-url { overflow-wrap: anywhere; color: var(--terracotta); font-size: .8125rem; font-weight: 600; line-height: 1.45; text-align: center; }
.qr-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }

.dashboard-grid {
  display: grid; grid-template-areas: "profile" "preview" "links"; gap: var(--s4);
}
.combined-grid { grid-template-areas: "left" "preview"; }
.appearance-grid { grid-template-areas: "profile" "preview"; }
.a-profile { grid-area: profile; } .a-preview { grid-area: preview; } .a-links { grid-area: links; } .a-themes { grid-area: themes; }
.dashboard-left { display: flex; min-width: 0; grid-area: left; flex-direction: column; gap: var(--s4); }
.card {
  display: flex; min-width: 0; flex-direction: column; gap: var(--s4); padding: var(--s5); border: 1px solid var(--line);
  border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-sm);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.stack { display: flex; min-width: 0; flex-direction: column; gap: var(--s1); }
.card h2 { color: var(--ink); font-size: 1.375rem; font-weight: 700; line-height: 1.15; }
.card h3 { color: var(--ink); font-family: var(--display); font-size: 1.0625rem; font-weight: 700; }
.meta { flex: 0 0 auto; color: var(--ink-muted); font-size: .75rem; line-height: 1.4; text-align: right; }

#profile-form, #theme-form, #link-form { display: flex; flex-direction: column; gap: var(--s4); }
.identity { display: flex; align-items: flex-start; gap: var(--s4); }
.avatar-lg { display: flex; flex: 0 0 92px; flex-direction: column; align-items: center; gap: var(--s2); }
.avatar-lg .button { align-self: center; width: 92px; justify-content: center; text-align: center; }
.avatar-preview {
  display: grid; width: 72px; height: 72px; place-items: center; overflow: hidden; border: 3px solid var(--surface); border-radius: 50%;
  color: var(--ink-muted); background: #edf2f5; box-shadow: 0 0 0 1px var(--line), var(--sh-sm);
}
.avatar-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.avatar-placeholder .person-icon { width: 40px; height: 40px; }
.avatar-lg input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.identity-fields { display: grid; min-width: 0; flex: 1; gap: var(--s3); }
.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; }
.label, .field-label { color: var(--ink); font-size: .8125rem; font-weight: 600; line-height: 1.35; }
.input, .text-input {
  width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid #c7d3dc; border-radius: var(--r-sm); color: var(--ink);
  outline: 0; background: var(--surface); font-size: .9375rem; line-height: 1.4; transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 88px; padding-top: 10px; padding-bottom: 10px; resize: vertical; }
.select { appearance: auto; background: var(--surface); }
.input:hover, .text-input:hover { border-color: #aebfcb; }
.input:focus, .text-input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(15, 94, 140, .13); }
.prefix-field {
  display: flex; min-width: 0; align-items: center; border: 1px solid #c7d3dc; border-radius: var(--r-sm); color: var(--ink-muted);
  background: var(--surface); font-size: .875rem; transition: border-color .15s, box-shadow .15s;
}
.prefix-field:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(15, 94, 140, .13); }
.prefix-field > span { flex: 0 0 auto; padding-left: 12px; }
.prefix-field .input { min-width: 0; border: 0; box-shadow: none; }
.field-hint, .counter { color: var(--ink-muted); font-size: .75rem; line-height: 1.35; }
.counter { text-align: right; }
.field-error { margin: 0; color: var(--danger); font-size: .8125rem; line-height: 1.4; }
.divider { width: 100%; height: 1px; margin: 0; border: 0; background: var(--line); }

.form-actions, .save-bar, .editor-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--s2); }
.form-actions { margin-top: var(--s1); }
.profile-form-actions .profile-action-button { min-width: 160px; justify-content: center; }
.form-message { margin-right: auto; color: var(--success); font-size: .8125rem; line-height: 1.4; }
.form-message-error { color: var(--danger); }

.link-list { display: flex; flex-direction: column; gap: var(--s2); margin: 0; padding: 0; list-style: none; }
.link-row {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3);
  border: 1px solid var(--line); border-radius: var(--r-md); background: #fff;
}
.link-row.is-hidden { background: #f8fafb; } .link-row.is-hidden .link-main { opacity: .62; }
.drag-grip { color: #9aacb8; font-size: 1.125rem; line-height: 1; }
.link-main { min-width: 0; }
.link-title, .link-url { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-title { color: var(--ink); font-size: .875rem; font-weight: 600; line-height: 1.35; }
.link-url { margin-top: 2px; color: var(--ink-muted); font-size: .75rem; line-height: 1.35; }
.badge { display: none; padding: 4px 7px; border-radius: 999px; font-size: .6875rem; font-weight: 600; white-space: nowrap; }
.badge-on { color: #176348; background: var(--success-bg); } .badge-off { color: #4a5c69; background: #e8edf0; }
.link-actions { display: flex; align-items: center; gap: var(--s1); }
.icon-btn, .icon-button {
  display: inline-grid; width: 36px; height: 36px; place-items: center; border-radius: var(--r-sm); color: var(--ink-soft);
  background: transparent; font-size: 1.125rem; line-height: 1;
}
.icon-btn:hover, .icon-button:hover { color: var(--ink); background: #eef2f5; }
.switch {
  display: inline-flex; width: 40px; height: 24px; align-items: center; padding: 3px; border-radius: 999px;
  background: #bdcad2; transition: background .15s;
}
.switch[aria-checked="true"] { background: var(--success); }
.switch-track {
  width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(16, 39, 60, .18);
  transition: transform .15s;
}
.switch[aria-checked="true"] .switch-track { transform: translateX(16px); }
.link-action-menu {
  display: flex; grid-column: 2 / -1; flex-wrap: wrap; gap: var(--s2); padding-top: var(--s2); border-top: 1px solid #ebf0f3;
}
.button-danger { color: var(--danger); border-color: #edc6bf; background: #fff; }
.button-danger:hover { color: #8f2818; border-color: #dfaa9f; background: var(--danger-bg); }
.edit-panel {
  padding: var(--s4); border: 1px solid var(--info-line); border-left: 4px solid var(--accent); border-radius: var(--r-md); background: #fffcf5;
}
.add-link { align-self: flex-end; margin-top: auto; }
.add-link span {
  display: inline-grid; width: 18px; height: 18px; place-items: center; border-radius: 50%; color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent-ink) 12%, transparent); font-size: 1.125rem; line-height: 1;
}

.preview-card { padding: 0; gap: 0; }
.preview-card summary { display: flex; min-height: 92px; align-items: center; justify-content: space-between; padding: var(--s5); cursor: pointer; list-style: none; }
.preview-card summary::-webkit-details-marker { display: none; }
.collapsible-card { padding: 0; gap: 0; }
.collapsible-card summary { display: flex; min-height: 92px; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s5); cursor: pointer; list-style: none; }
.collapsible-card summary::-webkit-details-marker { display: none; }
.collapsible-card summary .card-head { min-width: 0; flex: 1; }
.collapsible-card[open] .preview-chevron { transform: rotate(45deg); }
.card-count { text-align: left; }
.collapsible-body { display: flex; flex-direction: column; gap: var(--s4); padding: 0 var(--s5) var(--s5); }
.preview-chevron {
  width: 10px; height: 10px; flex: 0 0 auto; margin-right: 3px; border: solid var(--ink-soft); border-width: 0 2px 2px 0;
  transform: rotate(-45deg); transition: transform .15s ease;
}
.preview-card[open] .preview-chevron { transform: rotate(45deg); }
.preview-body { display: flex; flex-direction: column; gap: var(--s3); padding: 0 var(--s5) var(--s5); }
.preview-stage {
  --preview-scale: .8205;
  position: relative; overflow: hidden; width: min(100%, 340px); height: 664px; place-self: center;
  border: 10px solid var(--ink); border-radius: 32px; background: var(--ink); box-shadow: var(--sh-lg);
}
.preview-stage iframe {
  position: absolute; top: 16px; left: 50%; width: 390px; height: 762px; border: 0; background: var(--canvas);
  transform: translateX(-50%) scale(var(--preview-scale)); transform-origin: top center;
}
.preview-stage::before {
  position: absolute; top: 5px; left: 50%; z-index: 2; width: 68px; height: 5px; border-radius: 999px;
  background: #5a6c7a; content: ""; transform: translateX(-50%);
}
.preview-stage::after {
  position: absolute; top: 104px; right: -1px; z-index: 2; width: 3px; height: 78px; border-radius: 3px 0 0 3px;
  background: #30495b; box-shadow: 0 -54px 0 #30495b; content: "";
}
.preview-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--s2); text-align: center; }
.preview-foot a { color: var(--ink-soft); font-size: .8125rem; font-weight: 600; }
.preview-foot a:hover { color: var(--ink); }

.theme-grid { display: grid; grid-template-columns: 1fr; gap: var(--s2); }
.theme-card {
  position: relative; display: flex; min-width: 0; align-items: center; gap: var(--s3); padding: var(--s2); border: 1px solid var(--line);
  border-radius: var(--r-md); color: var(--ink); background: var(--surface); text-align: left; transition: border-color .15s, box-shadow .15s, transform .15s;
}
.theme-card:hover { border-color: #aebfcb; transform: translateY(-1px); }
.theme-card[aria-pressed="true"] { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(15, 94, 140, .12); }
.theme-thumb {
  display: grid; width: 48px; height: 48px; flex: 0 0 auto; place-items: center; border: 1px solid rgba(16, 39, 60, .1);
  border-radius: 9px; color: var(--ink); font-size: 1.125rem;
}
.theme-thumb-custom { color: #594721; background: conic-gradient(from 210deg, #efb350, #ed6fa2, #a88bde, #45b89d, #efb350); }
.theme-body { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.theme-name, .theme-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-name { font-size: .875rem; line-height: 1.3; } .theme-desc { color: var(--ink-muted); font-size: .75rem; line-height: 1.35; }
.theme-check {
  position: absolute; top: 8px; right: 8px; display: grid; width: 18px; height: 18px; place-items: center; border-radius: 50%;
  color: #fff; background: var(--focus); font-size: .625rem;
}
.color-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
.color-item {
  display: grid; min-width: 0; grid-template-columns: 32px minmax(0, 1fr); align-items: center; gap: var(--s2); padding: var(--s2);
  border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer;
}
.color-item input {
  width: 30px; height: 30px; padding: 1px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); cursor: pointer;
}
.color-item .name { overflow: hidden; color: var(--ink); font-size: .75rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.color-item .hex {
  grid-column: 2; overflow: hidden; color: var(--ink-muted); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: .6875rem; text-overflow: ellipsis; white-space: nowrap;
}
.slider-row { display: flex; flex-direction: column; gap: var(--s2); }
.slider-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.slider-val { color: var(--ink-muted); font-size: .8125rem; }
.slider-row input { width: 100%; accent-color: var(--focus); }
.theme-field-grid { display: grid; gap: var(--s3); }
.save-bar { padding-top: var(--s4); border-top: 1px solid var(--line); }

.link-image-editor { display: flex; align-items: center; gap: var(--s3); }
.link-image-preview { display: grid; width: 88px; height: 56px; flex: 0 0 88px; overflow: hidden; place-items: center; border: 1px dashed var(--line); border-radius: var(--r-sm); color: var(--ink-muted); background: #f8fafb; font-size: .75rem; text-align: center; }
.link-image-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.link-image-controls { display: flex; min-width: 0; flex: 1; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.link-image-controls .hint { flex-basis: 100%; }
.link-image-controls input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.background-image-editor { display: flex; align-items: center; gap: var(--s3); }
.background-image-preview { display: grid; width: 160px; height: 88px; flex: 0 0 160px; overflow: hidden; place-items: center; border: 1px dashed var(--line); border-radius: var(--r-sm); color: var(--ink-muted); background: #f8fafb; font-size: .75rem; text-align: center; }
.background-image-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.background-image-controls { display: flex; min-width: 0; flex: 1; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.background-image-controls .hint { flex-basis: 100%; }
.background-image-controls input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.link-preview-option { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3); border: 1px solid var(--line); border-radius: var(--r-md); background: #fff; cursor: pointer; }
.link-preview-option input { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 2px; accent-color: var(--focus); }
.link-preview-option-copy { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.link-preview-option-copy strong { color: var(--ink); font-size: .875rem; }
.link-preview-option-copy small { color: var(--ink-muted); font-size: .75rem; line-height: 1.4; }

.toast {
  position: fixed; right: var(--s4); bottom: var(--s4); z-index: 20; max-width: min(360px, calc(100vw - 32px)); padding: var(--s3) var(--s4);
  border: 1px solid #b8ddca; border-radius: var(--r-md); color: #15583e; background: #eef9f2; box-shadow: var(--sh-lg); font-size: .875rem; font-weight: 600;
}
.toast-error { border-color: #edc4bd; color: #8f2c1c; background: #fff2f0; }

@media (min-width: 600px) {
  .main, .dashboard-main { padding: var(--s6) var(--s6) var(--s8); }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .theme-field-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  .app-topbar, .topbar { grid-column: 1 / -1; padding-right: var(--s5); padding-left: var(--s5); }
  .main-inner { width: min(100%, 960px); }
  .preview-card[open] summary { cursor: default; }
}

@media (min-width: 1280px) {
  .main, .dashboard-main { padding: var(--s6) var(--s7) var(--s8); }
  .main-inner { width: min(100%, 1240px); }
  .dashboard-grid {
    grid-template-areas: "profile preview" "links preview";
    grid-template-columns: minmax(0, 1.45fr) minmax(360px, .9fr); align-items: start;
  }
  .combined-grid { grid-template-areas: "left preview"; }
  .appearance-grid { grid-template-areas: "profile preview"; }
  .preview-card { position: sticky; top: var(--s5); }
  .theme-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .page-head > .button { width: 100%; }
  .page-actions { width: 100%; }
  .page-actions .button { flex: 1; }
  .identity { flex-direction: column; }
  .avatar-lg { flex-basis: auto; align-items: center; }
  .identity-fields { width: 100%; }
  .card { padding: var(--s4); }
  .collapsible-card { padding: 0; }
  .collapsible-card summary { padding: var(--s4); }
  .preview-body { padding: 0 var(--s4) var(--s4); }
  .collapsible-body { padding: 0 var(--s4) var(--s4); }
  .preview-stage { --preview-scale: .7282; width: min(100%, 300px); height: 523px; border-width: 8px; border-radius: 27px; }
  .preview-stage iframe { top: 14px; }
  .link-row { grid-template-columns: 18px minmax(0, 1fr); padding: var(--s2); }
  .link-actions { grid-column: 2; justify-content: flex-start; }
  .link-action-menu { grid-column: 1 / -1; }
  .color-list, .theme-grid { grid-template-columns: 1fr; }
  .background-image-editor { align-items: flex-start; flex-direction: column; }
  .background-image-preview { width: 100%; max-width: 240px; }
  .editor-actions .button { flex: 1; }
  .profile-form-actions .profile-action-button { flex: 1 1 100%; width: 100%; }
  .save-bar .button { width: 100%; }
  .qr-dialog-card { padding: var(--s4); }
  .qr-actions { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .tabs { align-items: stretch; flex-direction: column; gap: var(--s1); overflow: visible; }
  .top-nav-links { width: 100%; }
  .top-nav-actions { width: 100%; justify-content: flex-end; padding-top: var(--s1); border-top: 1px solid var(--line); }
}
