:root {
  --bg: #fdf6f0;
  --surface: #ffffff;
  --primary: #c4717b;
  --primary-dark: #a85a64;
  --accent: #f4a5ae;
  --text: #3d2c2e;
  --text-muted: #8a7376;
  --border: #f0e0e2;
  --shadow: 0 4px 24px rgba(196, 113, 123, 0.12);
  --radius: 16px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100%; }

.screen { display: none; min-height: 100dvh; padding: 24px 20px calc(var(--nav-h) + 24px + var(--safe-bottom)); }
.screen.active { display: block; }

/* Auth */
.auth-header { text-align: center; padding: 48px 0 32px; }
.logo { font-size: 48px; margin-bottom: 12px; }
.auth-header h1 { font-size: 28px; font-weight: 700; color: var(--primary); }
.subtitle { color: var(--text-muted); margin-top: 8px; font-size: 14px; }

.tabs { display: flex; gap: 8px; margin-bottom: 24px; background: var(--border); border-radius: 12px; padding: 4px; }
.tab { flex: 1; padding: 10px; border: none; background: transparent; border-radius: 10px; font-size: 15px; cursor: pointer; color: var(--text-muted); }
.tab.active { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

.auth-form label, .record-form label, .card label {
  display: block; margin-bottom: 16px; font-size: 13px; color: var(--text-muted); font-weight: 500;
}
.auth-form input, .record-form input, .record-form textarea, .card input {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 12px; font-size: 16px;
  background: var(--surface); color: var(--text);
}
.auth-form input:focus, .record-form input:focus, .record-form textarea:focus, .card input:focus {
  outline: none; border-color: var(--primary);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 14px 24px; border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600; cursor: pointer; transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; width: 100%; }
.btn.secondary { background: var(--accent); color: var(--text); width: 100%; }
.btn.ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); width: 100%; margin-top: 8px; }
.btn.full { width: 100%; margin-top: 8px; }
.btn.danger { background: #e74c3c; color: #fff; }

.hidden { display: none !important; }
.error { color: #c0392b; font-size: 14px; text-align: center; margin-top: 12px; }

/* Pair */
.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 22px; }
.page-header p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.page-header.compact { margin-bottom: 16px; }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.card h3 { font-size: 16px; margin-bottom: 8px; }
.hint { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }

.divider { text-align: center; margin: 20px 0; color: var(--text-muted); font-size: 13px; position: relative; }
.divider span { background: var(--bg); padding: 0 12px; position: relative; z-index: 1; }
.divider::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--border); }

.invite-box { background: linear-gradient(135deg, #fff5f6, #fff); border: 2px dashed var(--accent); border-radius: var(--radius); padding: 20px; text-align: center; margin-top: 16px; }
.invite-code-display { font-size: 36px; font-weight: 800; letter-spacing: 8px; color: var(--primary); margin: 12px 0; font-family: monospace; }

/* Main layout */
.top-bar {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 12px 0 20px; position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.top-bar h2 { font-size: 20px; }
.partner-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.icon-btn { background: var(--surface); border: none; border-radius: 10px; width: 40px; height: 40px; font-size: 18px; cursor: pointer; box-shadow: var(--shadow); }

.view { display: none; padding-bottom: calc(var(--nav-h) + 16px); }
.view.active { display: block; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); text-align: center; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.section-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; color: var(--text-muted); }

/* Records */
.record-list { display: flex; flex-direction: column; gap: 10px; }
.record-item {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform 0.1s;
}
.record-item:active { transform: scale(0.98); }
.record-item-header { display: flex; justify-content: space-between; align-items: center; }
.record-date { font-weight: 600; font-size: 15px; }
.record-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.record-ratings { display: flex; gap: 12px; margin-top: 10px; }
.rating-badge { font-size: 12px; background: #fff0f2; padding: 4px 10px; border-radius: 20px; color: var(--primary); }
.record-status { font-size: 11px; padding: 3px 8px; border-radius: 8px; }
.record-status.complete { background: #e8f8ef; color: #27ae60; }
.record-status.pending { background: #fff8e6; color: #e67e22; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state p:first-child { font-size: 16px; margin-bottom: 8px; }

/* Form extras */
.field { margin-bottom: 16px; }
.field-label { font-size: 13px; color: var(--text-muted); font-weight: 500; display: block; margin-bottom: 8px; }

.star-rating { display: flex; gap: 8px; }
.star-rating button {
  width: 44px; height: 44px; border: none; background: var(--border); border-radius: 12px;
  font-size: 22px; cursor: pointer; transition: all 0.15s;
}
.star-rating button.active { background: #fff0f2; transform: scale(1.05); }

.tag-group { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-btn {
  padding: 8px 14px; border: 1.5px solid var(--border); border-radius: 20px;
  background: var(--surface); font-size: 13px; cursor: pointer; color: var(--text);
}
.tag-btn.selected { border-color: var(--primary); background: #fff0f2; color: var(--primary); }

.record-form textarea { resize: vertical; min-height: 60px; font-family: inherit; }

/* Detail */
.back-btn { background: none; border: none; color: var(--primary); font-size: 15px; cursor: pointer; margin-bottom: 16px; padding: 4px 0; }
.detail-card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 12px; }
.detail-card h3 { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; }
.detail-entry { padding: 12px 0; border-bottom: 1px solid var(--border); }
.detail-entry:last-child { border-bottom: none; }
.entry-name { font-weight: 600; margin-bottom: 6px; }
.entry-note { font-size: 14px; color: var(--text-muted); margin-top: 6px; font-style: italic; }
.entry-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.entry-tag { font-size: 11px; background: #fff0f2; padding: 3px 8px; border-radius: 10px; color: var(--primary); }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 100;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--text-muted); font-size: 11px; cursor: pointer; padding: 8px;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 22px; }
.nav-add .nav-icon {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin-top: -20px; box-shadow: var(--shadow);
}

.privacy-note { font-size: 13px; color: var(--text-muted); margin: 12px 0; line-height: 1.5; }

.toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%); background: rgba(61,44,46,0.9); color: #fff;
  padding: 10px 20px; border-radius: 20px; font-size: 14px; z-index: 200;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

.filter-row {
  display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto;
  margin-bottom: 16px; padding-bottom: 4px; -webkit-overflow-scrolling: touch;
}
.filter-chip, .category-chip {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 999px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 13px; cursor: pointer; color: var(--text-muted);
}
.filter-chip.active, .category-chip.active {
  border-color: var(--primary); background: #fff0f2; color: var(--primary); font-weight: 600;
}
.category-row { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-badge {
  display: inline-block; font-size: 12px; background: #f7f0f1; color: var(--text-muted);
  padding: 3px 10px; border-radius: 999px; margin-top: 6px;
}
.cat-badge.intimacy { background: #fce8ef; color: #a85570; }
.record-title { font-weight: 600; margin-top: 6px; }
.record-item-body { display: flex; gap: 12px; }
.record-cover {
  width: 72px; height: 72px; border-radius: 12px; object-fit: cover;
  background: var(--border); flex-shrink: 0;
}
.photo-count { font-size: 12px; color: var(--text-muted); margin-left: 6px; }

.photo-grid {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px;
}
.photo-thumb-wrap, .photo-add-btn {
  width: 88px; height: 88px; border-radius: 12px; position: relative; overflow: hidden;
}
.photo-thumb {
  width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer;
  border-radius: 12px; background: var(--border);
}
.photo-remove {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px;
  border: none; border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff;
  font-size: 14px; cursor: pointer; line-height: 20px;
}

@media (min-width: 480px) {
  #screen-auth, #screen-pair, #screen-main { max-width: 420px; margin: 0 auto; }
}
