:root {
  --bg: #fdf2f8;
  --bg-2: #f2ecfb;
  --paper: #ffffff;
  --ink: #5b4b63;
  --muted: #a996ab;
  --accent: #f2a6c4;
  --accent-2: #c9b6e4;
  --accent-3: #8fd6bd;
  --accent-4: #ffc98f;
  --danger: #ef8e83;
  --border: #f5dcec;
  --shadow: 0 8px 20px rgba(196, 143, 178, 0.16);
  --radius: 22px;
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #241b2e;
    --bg-2: #2c2138;
    --paper: #322640;
    --ink: #f5e9f5;
    --muted: #b39dc0;
    --accent: #f4a9c9;
    --accent-2: #cbb8e8;
    --accent-3: #8fd9c4;
    --accent-4: #ffcb91;
    --danger: #ff9c8f;
    --border: #453655;
    --shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 4px; }
p { margin: 0 0 8px; line-height: 1.45; }
.muted { color: var(--muted); font-size: 0.9rem; }
.hidden { display: none !important; }

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

#screen-auth, #screen-loading {
  background:
    radial-gradient(circle at 14% 18%, rgba(143, 214, 189, 0.35), transparent 38%),
    radial-gradient(circle at 88% 12%, rgba(255, 201, 143, 0.35), transparent 34%),
    radial-gradient(circle at 50% 92%, rgba(201, 182, 228, 0.4), transparent 46%),
    var(--bg);
}

.center-pane {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(48px + var(--safe-top)) 24px 24px;
  text-align: center;
}
.logo-mark {
  width: 96px; height: 96px; margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 28px;
  box-shadow: var(--shadow);
  background: var(--paper);
}
.logo-mark img { width: 88px; height: 88px; border-radius: 22px; display: block; }

.stack { display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field span:first-child { font-size: 0.85rem; color: var(--muted); }
.field-label { font-size: 0.85rem; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.field-block { margin-top: 18px; }

input[type="text"], input[type="password"], textarea {
  font-size: 1rem;
  padding: 13px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  width: 100%;
}
textarea { resize: vertical; min-height: 120px; border-radius: 18px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font-size: 1rem;
  font-weight: 700;
  padding: 13px 20px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 6px 14px rgba(226, 140, 180, 0.35); }
.btn-secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--border); flex: 1; }
.btn-ghost { background: rgba(0,0,0,0.02); color: var(--ink); border: 1px solid var(--border); }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); color: #fff; box-shadow: 0 6px 14px rgba(239, 142, 131, 0.35); }
.btn-round {
  width: 68px; height: 68px; border-radius: 50%; background: var(--grad); color: #fff;
  font-size: 1.7rem; border: none; box-shadow: 0 6px 16px rgba(226, 140, 180, 0.4);
}
.btn-round.recording { background: linear-gradient(135deg, var(--danger), var(--accent)); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(239,142,131,0.4);} 50%{ box-shadow: 0 0 0 14px rgba(239,142,131,0);} }
.btn-pill { border-radius: 999px; padding: 9px 16px; font-size: 0.88rem; }

.link-btn {
  background: none; border: none; color: var(--accent); font-weight: 600;
  font-size: 0.9rem; margin-top: 18px; cursor: pointer; text-decoration: underline;
}

.hint {
  font-size: 0.8rem; color: var(--danger); background: rgba(239,142,131,0.1);
  border-radius: 14px; padding: 10px 14px; text-align: left;
}

/* install banner */
.install-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + var(--safe-top));
  background: linear-gradient(120deg, rgba(242,166,196,0.35), rgba(201,182,228,0.35));
  border-bottom: 1px solid var(--border);
}
.install-emoji { font-size: 1.4rem; flex-shrink: 0; }
.install-text { flex: 1; display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.install-text strong { font-size: 0.9rem; }
.install-text span { font-size: 0.78rem; color: var(--muted); }
.btn-install-cta { background: var(--grad); color: #fff; flex-shrink: 0; }

.app-header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 12px 14px;
  background: linear-gradient(120deg, var(--bg), var(--bg-2));
  border-bottom: 1px solid var(--border);
}
.icon-btn {
  background: none; border: none; font-size: 1.3rem; padding: 6px 10px;
  cursor: pointer; color: var(--ink); border-radius: 14px; min-width: 40px;
}
.icon-btn-accent { color: var(--accent); }

.group-switch { display: flex; gap: 8px; padding: 14px 16px 4px; }
.chip {
  padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--paper); color: var(--muted); font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.chip[data-group="week"].active { background: var(--accent-3); border-color: var(--accent-3); color: #234238; }
.chip[data-group="month"].active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip[data-group="year"].active { background: var(--accent-2); border-color: var(--accent-2); color: #3a2c52; }

.entries-list { padding: 8px 16px 100px; max-width: 640px; margin: 0 auto; }
.group-header {
  font-size: 0.9rem; font-weight: 800; color: var(--accent);
  margin: 22px 4px 8px;
  display: flex; align-items: center; gap: 6px;
}
.group-header::before { content: "✧"; }
.group-header:first-child { margin-top: 8px; }

.entry-card {
  background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); cursor: pointer;
}
.entry-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.entry-mood { font-size: 1.4rem; }
.entry-date { font-size: 0.78rem; color: var(--muted); }
.entry-excerpt { margin: 8px 0 0; font-size: 0.92rem; }
.entry-meta-row { display: flex; gap: 10px; margin-top: 8px; font-size: 0.8rem; color: var(--muted); }

.empty-state { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty-state .big { font-size: 2.4rem; margin-bottom: 4px; }

.fab {
  position: fixed; right: 20px; bottom: calc(24px + var(--safe-bottom));
  width: 62px; height: 62px; border-radius: 50%; background: var(--grad); color: #fff;
  font-size: 1.8rem; border: none; box-shadow: 0 8px 20px rgba(226, 140, 180, 0.45); cursor: pointer;
}

.entry-form-body { max-width: 640px; margin: 0 auto; padding: 16px; }
.timestamp { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }

.mood-picker { margin-bottom: 18px; }
.mood-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.mood-opt {
  font-size: 1.5rem; width: 48px; height: 48px; border-radius: 50%; border: 2px solid transparent;
  background: var(--paper); cursor: pointer; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
}
.mood-opt.selected { border-color: var(--accent); background: linear-gradient(135deg, rgba(242,166,196,0.25), rgba(201,182,228,0.25)); }

.audio-recorder { display: flex; align-items: center; gap: 14px; }
.attachment-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.attachment-item {
  display: flex; align-items: center; gap: 10px; background: var(--paper);
  border: 1px solid var(--border); border-radius: 16px; padding: 8px 10px;
}
.attachment-item audio { flex: 1; height: 34px; }
.remove-btn {
  background: none; border: none; color: var(--danger); font-size: 1.1rem; cursor: pointer;
  padding: 4px 8px;
}

.media-buttons { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.media-buttons .btn { flex: 1 1 auto; font-size: 0.85rem; padding: 10px; }

.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.media-thumb { position: relative; aspect-ratio: 1; border-radius: 18px; overflow: hidden; background: var(--paper); border: 1px solid var(--border); }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .badge { position: absolute; top: 4px; left: 4px; background: rgba(91,75,99,0.6); color: #fff; font-size: 0.7rem; padding: 1px 6px; border-radius: 8px; }
.media-thumb .remove-btn { position: absolute; top: 2px; right: 2px; background: rgba(91,75,99,0.6); color: #fff; border-radius: 50%; width: 26px; height: 26px; }

.detail-mood { font-size: 2.4rem; }
.detail-text { white-space: pre-wrap; font-size: 1.02rem; margin: 14px 0; }
.detail-media-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px; }
.detail-media-grid img, .detail-media-grid video { width: 100%; border-radius: 18px; display: block; }
.detail-audio { margin-top: 10px; }
.detail-audio audio { width: 100%; }

.settings-card {
  background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 0.88rem; opacity: 0; pointer-events: none; transition: all 0.25s ease; z-index: 50;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(91,75,99,0.45); display: flex;
  align-items: flex-end; justify-content: center; z-index: 60;
}
.modal-sheet {
  background: var(--bg); width: 100%; max-width: 480px; border-radius: 26px 26px 0 0;
  padding: 22px; padding-bottom: calc(22px + var(--safe-bottom));
}
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
