:root {
  --bg: #f7f7f8;
  --bg-2: #ffffff;
  --fg: #111214;
  --fg-2: #5a5f66;
  --line: #e6e7ea;
  --accent: #111214;
  --accent-fg: #ffffff;
  --card: #ffffff;
  --shadow: 0 2px 10px rgba(20,20,30,.06);
  --radius: 18px;
  --tap: 56px;
}

[data-theme="dark"] {
  --bg: #0e0f12;
  --bg-2: #17191d;
  --fg: #f4f5f7;
  --fg-2: #a5a9b1;
  --line: #262a31;
  --accent: #f4f5f7;
  --accent-fg: #0e0f12;
  --card: #17191d;
  --shadow: 0 2px 10px rgba(0,0,0,.35);
}

[data-theme="mint"] {
  --bg: #eefaf4;
  --bg-2: #ffffff;
  --fg: #0f2e26;
  --fg-2: #3b6b5f;
  --line: #cfeadf;
  --accent: #0fa37a;
  --accent-fg: #ffffff;
  --card: #ffffff;
}

[data-theme="sakura"] {
  --bg: #fff2f5;
  --bg-2: #ffffff;
  --fg: #4a1c2b;
  --fg-2: #8a5566;
  --line: #ffd7e1;
  --accent: #e94a72;
  --accent-fg: #ffffff;
  --card: #ffffff;
}

[data-theme="sunset"] {
  --bg: #fff4e8;
  --bg-2: #ffffff;
  --fg: #3a1d0a;
  --fg-2: #8a5c3a;
  --line: #ffd6b0;
  --accent: #ff6a3d;
  --accent-fg: #ffffff;
  --card: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.profile {
  text-align: center;
  padding: 12px 4px 24px;
}

.avatar {
  width: 96px; height: 96px;
  border-radius: 50%;
  margin: 0 auto 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: 44px; line-height: 1;
  overflow: hidden;
  border: 1px solid var(--line);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.name {
  font-size: 22px;
  font-weight: 700;
  margin: 4px 0 6px;
  letter-spacing: .02em;
}
.bio {
  color: var(--fg-2);
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.links {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.link-card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--tap);
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  text-decoration: none;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
  position: relative;
}
.link-card:active { transform: scale(.985); }
.link-card:hover { box-shadow: 0 6px 18px rgba(20,20,30,.10); }

.link-card .brand {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  color: #fff;
  flex-shrink: 0;
}
.link-card .txt {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-card .arrow {
  color: var(--fg-2);
  font-size: 18px;
  flex-shrink: 0;
}

.empty {
  text-align: center;
  color: var(--fg-2);
  padding: 40px 12px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}

.foot {
  text-align: center;
  margin-top: 28px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.ghost {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  min-height: 44px;
}
.ghost .ico { font-size: 16px; }

.tiny { color: var(--fg-2); font-size: 12px; margin-top: 12px; }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  padding: 0;
}
.modal.is-open { display: flex; }
.modal-card {
  width: 100%;
  max-width: 560px;
  background: var(--bg-2);
  border-radius: 20px 20px 0 0;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 8px 18px 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  animation: slideUp .22s ease;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@media (min-width: 640px) {
  .modal { align-items: center; padding: 20px; }
  .modal-card { border-radius: 20px; max-height: 86dvh; }
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px 4px;
  position: sticky; top: 0;
  background: var(--bg-2);
  z-index: 2;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: var(--fg-2);
}
.icon-btn:hover { background: var(--line); }

.tabs {
  display: flex;
  gap: 6px;
  margin: 8px 0 16px;
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1;
  padding: 12px 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.is-active {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

.tab-body { display: block; }
.tab-body.is-hidden { display: none; }

.field {
  display: block;
  margin-bottom: 14px;
}
.field span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-2);
  margin-bottom: 6px;
}
.field input,
.field textarea,
.field select,
.add-row input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg);
  font-size: 16px;  /* iOSでズームさせない */
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.field input:focus,
.field textarea:focus,
.field select:focus,
.add-row input:focus {
  border-color: var(--accent);
}

.add-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
@media (min-width: 480px) {
  .add-row {
    grid-template-columns: 1fr 1fr auto;
  }
}
.add-row .primary {
  min-height: 48px;
  padding: 0 22px;
}

.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 15px;
  min-height: 48px;
}

.secondary {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 15px;
  min-height: 48px;
  display: block;
  width: 100%;
  text-align: center;
  margin-bottom: 10px;
}
.as-label {
  cursor: pointer;
  box-sizing: border-box;
}

.danger {
  background: transparent;
  color: #d33;
  border: 1px solid #ecc;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 15px;
  min-height: 48px;
  width: 100%;
  margin-top: 12px;
}

.hint { color: var(--fg-2); font-size: 12px; margin: 4px 0 12px; }

.edit-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: flex; flex-direction: column;
  gap: 8px;
}
.edit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}
.edit-item .brand-small {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}
.edit-item .meta {
  flex: 1;
  min-width: 0;
}
.edit-item .meta .t {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.edit-item .meta .u {
  color: var(--fg-2);
  font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.edit-item .acts {
  display: flex; gap: 4px;
}
.edit-item .acts button {
  width: 36px; height: 36px;
  border-radius: 10px;
  color: var(--fg-2);
  font-size: 16px;
}
.edit-item .acts button:hover { background: var(--line); color: var(--fg); }
.edit-item .acts .del:hover { color: #d33; }

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 30;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 公開ビュー: 編集リンク ===== */
.edit-link {
  color: var(--fg-2);
  font-size: 12px;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  display: inline-block;
  border: 1px solid transparent;
  transition: background .15s;
}
.edit-link:hover {
  background: var(--card);
  border-color: var(--line);
}

/* ===== 汎用 ===== */
.is-hidden { display: none !important; }

/* ===== ゲート（パスワード） ===== */
.gate {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 20px;
}
.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.gate-emoji {
  font-size: 40px;
  margin-bottom: 6px;
}
.gate h1 {
  margin: 4px 0 6px;
  font-size: 20px;
}
.gate-desc {
  color: var(--fg-2);
  font-size: 13px;
  margin: 0 0 18px;
}
.gate input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg);
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 12px;
  outline: none;
}
.gate input:focus { border-color: var(--accent); }
.gate .primary {
  width: 100%;
  border: none;
}
.gate-msg {
  color: #d33;
  font-size: 13px;
  min-height: 18px;
  margin: 8px 0 0;
}
.gate-tip { margin-top: 14px; }
.gate-tip .edit-link { border: 1px solid var(--line); }

/* ===== 編集ページ ===== */
.edit-wrap {
  max-width: 640px;
  padding: 16px 18px 60px;
}
.edit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.back-link {
  color: var(--fg-2);
  font-size: 14px;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
}
.back-link:hover { background: var(--card); }

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg-2);
  background: var(--card);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #bbb;
  display: inline-block;
}
.dot.is-saving { background: #f5a623; animation: pulse 1s infinite ease-in-out; }
.dot.is-saved  { background: #22c55e; }
.dot.is-error  { background: #ef4444; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

.preview-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.mini-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  flex-shrink: 0;
}
.mini-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 2px;
}
.mini-bio {
  color: var(--fg-2);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}
.mini-url {
  font-size: 11px;
  color: var(--fg-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}
.preview-body { min-width: 0; flex: 1; }

/* ===== ランディング（signup/login） ===== */
.landing {
  max-width: 460px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}
.hero {
  text-align: center;
  margin-bottom: 28px;
}
.hero-logo {
  font-size: 48px;
  margin-bottom: 8px;
}
.hero-title {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 8px;
  letter-spacing: .02em;
}
.hero-desc {
  color: var(--fg-2);
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 8px 20px 22px;
  box-shadow: var(--shadow);
}

.auth-form { padding-top: 12px; }
.form-msg {
  color: #d33;
  font-size: 13px;
  margin: 10px 0 0;
  min-height: 18px;
  text-align: center;
}

.url-hint {
  display: block;
  font-size: 12px;
  color: var(--fg-2);
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.primary.wide,
.ghost.wide,
.secondary.wide {
  width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  gap: 6px;
}

.me-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.me-hi {
  margin: 0 0 14px;
  font-size: 15px;
  color: var(--fg);
}
.me-hi b { font-weight: 700; }
.me-url {
  color: var(--fg-2);
  font-size: 12px;
  margin: 0 0 8px;
}
.me-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

.url-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 8px;
}
.url-box a {
  flex: 1;
  min-width: 0;
  color: var(--fg);
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ghost.small {
  padding: 6px 12px;
  min-height: 32px;
  font-size: 12px;
  flex-shrink: 0;
}

.landing-foot {
  text-align: center;
  margin-top: 24px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-2);
  margin: 0 0 6px;
}
