:root {
  color-scheme: light;
  --ink: #1d1c19;
  --muted: #74716a;
  --paper: #f7f4ee;
  --card: rgba(255, 255, 255, 0.82);
  --line: rgba(29, 28, 25, 0.12);
  --accent: #315c4c;
  --accent-soft: #dce8e1;
  --danger: #a44137;
  --shadow: 0 18px 60px rgba(45, 42, 35, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 5%, rgba(233, 203, 171, 0.42), transparent 30rem),
    radial-gradient(circle at 90% 90%, rgba(158, 194, 177, 0.32), transparent 32rem),
    var(--paper);
  font-family: ui-rounded, "SF Pro Rounded", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.public-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 52px 20px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar-wrap {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  padding: 5px;
  background: rgba(255,255,255,.72);
  box-shadow: 0 10px 35px rgba(45,42,35,.12);
  margin-bottom: 22px;
}

.avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.avatar-fallback {
  width: 100%; height: 100%; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 2.5rem; font-weight: 750;
}

.profile-name { margin: 0; font-size: clamp(1.9rem, 8vw, 2.45rem); line-height: 1.14; letter-spacing: -.045em; text-align: center; }
.profile-bio { margin: 12px auto 30px; max-width: 390px; color: var(--muted); line-height: 1.65; text-align: center; white-space: pre-line; }
.links { width: 100%; display: grid; gap: 13px; }

.social-link {
  min-height: 66px;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 20px;
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 8px 28px rgba(45,42,35,.07);
  text-decoration: none;
  font-weight: 650;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
  backdrop-filter: blur(12px);
}
.social-link:hover { transform: translateY(-2px); box-shadow: 0 13px 35px rgba(45,42,35,.12); background: white; }
.social-link:active { transform: scale(.985); }
.social-icon { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; background: #efeee9; font-size: 1.05rem; font-weight: 800; }
.social-label { text-align: center; }
.arrow { text-align: right; font-size: 1.35rem; color: #9b978f; }
.empty-public { text-align: center; color: var(--muted); padding: 22px 10px; }
.tiny-footer { margin-top: auto; padding-top: 34px; color: #aaa59c; font-size: .77rem; letter-spacing: .06em; text-transform: uppercase; }

.editor-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 70px; }
.editor-header { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 26px; }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 800; }
.editor-header h1 { margin: 5px 0 0; font-size: clamp(1.7rem, 4vw, 2.5rem); letter-spacing: -.04em; }
.status { min-width: 120px; text-align: right; color: var(--muted); font-size: .9rem; }
.status.ok { color: var(--accent); }
.status.error { color: var(--danger); }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 26px; align-items: start; }
.panel { background: var(--card); border: 1px solid rgba(255,255,255,.75); border-radius: 26px; padding: 24px; box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.section-title { margin: 0 0 18px; font-size: 1.1rem; }
.field { display: grid; gap: 8px; margin-bottom: 17px; }
.field label { color: #57534c; font-size: .88rem; font-weight: 700; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px;
  color: var(--ink); background: rgba(255,255,255,.72); outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(49,92,76,.12); }
.field textarea { resize: vertical; min-height: 94px; line-height: 1.5; }
.avatar-editor { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.avatar-preview { width: 76px; height: 76px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); border: 4px solid white; box-shadow: 0 5px 18px rgba(0,0,0,.08); }
.upload-button, .primary-button, .secondary-button, .icon-button {
  border: 0; border-radius: 13px; cursor: pointer; font-weight: 750;
}
.upload-button, .secondary-button { padding: 11px 14px; background: #eceae4; color: var(--ink); }
.primary-button { padding: 13px 20px; background: var(--accent); color: white; box-shadow: 0 8px 18px rgba(49,92,76,.2); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.divider { height: 1px; background: var(--line); margin: 24px 0; }
.links-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.links-heading h2 { margin: 0; font-size: 1.1rem; }
.link-list { display: grid; gap: 11px; }
.link-card { display: grid; grid-template-columns: 34px 145px minmax(170px, 1fr) auto; gap: 9px; align-items: center; border: 1px solid var(--line); border-radius: 17px; padding: 11px; background: rgba(255,255,255,.62); }
.drag-handle { color: #aaa69e; cursor: grab; font-size: 1.15rem; text-align: center; user-select: none; }
.link-card input, .link-card select { min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: white; }
.link-card.dragging { opacity: .45; }
.row-actions { display: flex; gap: 5px; }
.icon-button { width: 34px; height: 34px; background: #eceae4; color: #57534c; }
.icon-button.delete { color: var(--danger); background: #f4e5e2; }
.empty-links { text-align: center; color: var(--muted); padding: 20px; border: 1px dashed var(--line); border-radius: 15px; }
.preview-panel { position: sticky; top: 22px; padding: 14px; }
.preview-label { padding: 5px 8px 13px; display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .8rem; }
.preview-link { color: var(--accent); text-decoration: none; font-weight: 700; }
.phone { width: 100%; aspect-ratio: 9 / 16; max-height: 690px; border: 7px solid #24231f; border-radius: 34px; overflow: hidden; background: var(--paper); box-shadow: 0 20px 50px rgba(0,0,0,.17); }
.phone iframe { width: 100%; height: 100%; border: 0; }
.mobile-link-meta { display: none; }

@media (max-width: 860px) {
  .editor-grid { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .phone { max-width: 390px; margin: 0 auto; }
}

@media (max-width: 620px) {
  .public-shell { padding-top: 38px; }
  .editor-shell { width: min(100% - 20px, 560px); padding-top: 22px; }
  .editor-header { align-items: start; }
  .panel { padding: 17px; border-radius: 21px; }
  .link-card { grid-template-columns: 28px 1fr auto; }
  .link-card select { grid-column: 2; }
  .link-card .url-input { grid-column: 2 / 4; }
  .row-actions { grid-column: 3; grid-row: 1 / 2; }
  .mobile-link-meta { display: block; grid-column: 2 / 4; color: var(--muted); font-size: .75rem; }
  .actions { position: sticky; bottom: 10px; z-index: 2; }
  .primary-button { flex: 1; }
}
