:root {
  --ink: #2f312d;
  --muted: #77776f;
  --paper: #f5efe3;
  --paper-deep: #e8ddca;
  --card: #fffdf8;
  --forest: #315c4d;
  --forest-dark: #24483c;
  --coral: #d8755b;
  --line: rgba(47, 49, 45, 0.14);
  --shadow: 0 24px 70px rgba(69, 57, 40, 0.13);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(216, 117, 91, 0.14), transparent 28rem),
    radial-gradient(circle at 92% 92%, rgba(49, 92, 77, 0.13), transparent 32rem),
    var(--paper);
  font-family: "DM Sans", sans-serif;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }

.paper-grain {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E");
}

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: "Fraunces", Georgia, serif; }

.eyebrow {
  margin-bottom: 0.45rem;
  color: var(--coral);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.loading-shell {
  width: min(460px, calc(100% - 40px));
  margin: 25vh auto;
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 30px 10px 30px 10px;
  background: rgba(255, 253, 248, 0.74);
  box-shadow: var(--shadow);
}

.loading-mark, .loading-line {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--paper-deep), #fffdf8, var(--paper-deep));
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}
.loading-mark { width: 52px; height: 52px; margin-bottom: 28px; }
.loading-line { width: 58%; height: 13px; margin-top: 12px; }
.loading-line.long { width: 88%; height: 23px; }

@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
}

.auth-story {
  position: relative;
  display: flex;
  align-items: flex-end;
  min-height: 100vh;
  padding: clamp(36px, 7vw, 100px);
  overflow: hidden;
  background: var(--forest);
  color: #fbf7ee;
}

.auth-story::before {
  content: "";
  position: absolute;
  width: min(55vw, 680px);
  aspect-ratio: 1;
  top: -20%;
  right: -18%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 46% 54% 63% 37% / 44% 36% 64% 56%;
  transform: rotate(18deg);
}

.story-copy { position: relative; max-width: 680px; animation: rise 0.65s both; }
.story-copy .eyebrow { color: #eeb29f; }
.story-copy h1 { max-width: 650px; margin-bottom: 1.5rem; font-size: clamp(3.2rem, 7.3vw, 7.2rem); line-height: 0.91; letter-spacing: -0.055em; }
.story-copy p:last-child { max-width: 530px; color: rgba(255,255,255,.72); font-size: clamp(1rem, 1.4vw, 1.2rem); line-height: 1.7; }

.auth-panel { display: grid; place-items: center; padding: 40px; }
.auth-card { width: min(430px, 100%); animation: rise 0.65s 0.1s both; }
.auth-card h2 { margin-bottom: 0.6rem; font-size: clamp(2.2rem, 5vw, 3.3rem); letter-spacing: -0.035em; }
.auth-subtitle { margin-bottom: 2.1rem; color: var(--muted); line-height: 1.6; }

.auth-tabs { display: flex; gap: 8px; margin-bottom: 26px; padding: 5px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.35); }
.auth-tab { flex: 1; padding: 10px 16px; border: 0; border-radius: 999px; background: transparent; cursor: pointer; font-weight: 700; }
.auth-tab.active { background: var(--ink); color: #fffdf8; }

label { display: grid; gap: 8px; margin-bottom: 18px; font-size: 0.82rem; font-weight: 700; letter-spacing: 0.02em; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: rgba(255, 253, 248, 0.78);
  color: var(--ink);
  padding: 13px 14px;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
textarea { resize: vertical; line-height: 1.65; }
input:focus, textarea:focus, select:focus { border-color: var(--forest); box-shadow: 0 0 0 4px rgba(49,92,77,.12); }
input:disabled { color: var(--muted); background: var(--paper-deep); }

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 20px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  transition: transform .2s, background .2s, box-shadow .2s;
}
.button:hover { transform: translateY(-2px); }
.button:active { transform: translateY(0); }
.button.primary { background: var(--forest); color: #fff; box-shadow: 0 10px 25px rgba(49,92,77,.2); }
.button.primary:hover { background: var(--forest-dark); }
.button.ghost { border-color: var(--line); background: transparent; }
.button.full { width: 100%; }
.button svg, .icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.form-error { min-height: 22px; margin: -4px 0 14px; color: #a74336; font-size: .86rem; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(22px, 5vw, 72px);
  border-bottom: 1px solid var(--line);
  background: rgba(245,239,227,.82);
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 12px; font-family: "Fraunces", Georgia, serif; font-size: 1.3rem; font-weight: 700; }
.brand-mark { width: 32px; height: 38px; border-radius: 4px 12px 4px 4px; background: var(--forest); transform: rotate(-5deg); box-shadow: 6px 5px 0 var(--coral); }
.nav-actions { display: flex; align-items: center; gap: 8px; }
.icon-button { display: grid; width: 44px; height: 44px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,253,248,.65); cursor: pointer; transition: transform .2s, background .2s; }
.icon-button:hover { transform: rotate(-4deg); background: #fffdf8; }

.dashboard { width: min(1380px, calc(100% - 44px)); margin: 0 auto; padding: clamp(48px, 8vw, 100px) 0 80px; }
.hero { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, .55fr); gap: 48px; align-items: end; margin-bottom: 64px; }
.hero h1 { max-width: 850px; margin-bottom: 0; font-size: clamp(3rem, 7vw, 7rem); line-height: .92; letter-spacing: -.06em; }
.hero-aside { padding: 24px 0 8px; border-top: 1px solid var(--ink); color: var(--muted); line-height: 1.7; }
.hero-aside strong { display: block; margin-bottom: 5px; color: var(--ink); font-size: 1.8rem; font-family: "Fraunces", Georgia, serif; }

.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) auto auto; gap: 12px; margin-bottom: 32px; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; top: 50%; left: 15px; width: 19px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 1.8; }
.search-wrap input { height: 48px; padding-left: 46px; border-radius: 999px; background: rgba(255,253,248,.7); }
.filter-button.active { border-color: var(--coral); background: rgba(216,117,91,.1); color: #9b4735; }

.diary-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 22px; }
.diary-card {
  grid-column: span 4;
  position: relative;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 6px 28px 6px 28px;
  background: var(--card);
  box-shadow: 0 8px 30px rgba(69,57,40,.07);
  animation: rise .45s both;
  transition: transform .25s, box-shadow .25s;
}
.diary-card:nth-child(5n + 2), .diary-card:nth-child(5n + 4) { grid-column: span 5; }
.diary-card:nth-child(5n + 3), .diary-card:nth-child(5n + 5) { grid-column: span 3; }
.diary-card:hover { transform: translateY(-6px) rotate(.25deg); box-shadow: var(--shadow); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.mood { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.mood-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.favorite-button { border: 0; background: transparent; cursor: pointer; color: #a5a398; padding: 5px; }
.favorite-button.active { color: var(--coral); }
.favorite-button svg { width: 23px; height: 23px; fill: currentColor; stroke: currentColor; }
.diary-card h3 { margin: 30px 0 12px; font-size: clamp(1.55rem, 2.5vw, 2.2rem); line-height: 1.05; letter-spacing: -.035em; }
.diary-excerpt { flex: 1; margin-bottom: 24px; color: #64645d; line-height: 1.65; white-space: pre-line; }
.card-footer { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.card-date { color: var(--muted); font-size: .78rem; }
.card-actions { display: flex; gap: 5px; }
.card-actions button { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 6px; }
.card-actions button:hover { color: var(--ink); }
.card-actions svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.empty-state { grid-column: 1 / -1; min-height: 390px; display: grid; place-items: center; text-align: center; border: 1px dashed rgba(47,49,45,.28); border-radius: 40% 10% 35% 8% / 12% 34% 10% 40%; }
.empty-state-inner { max-width: 430px; padding: 50px; }
.empty-state svg { width: 68px; color: var(--forest); fill: none; stroke: currentColor; stroke-width: 1.25; }
.empty-state h2 { margin: 24px 0 10px; font-size: 2.2rem; }
.empty-state p { color: var(--muted); line-height: 1.65; }

.sheet-dialog { width: min(680px, calc(100% - 28px)); max-height: calc(100vh - 30px); padding: 0; border: 0; border-radius: 8px 34px 8px 34px; background: transparent; box-shadow: var(--shadow); }
.sheet-dialog.compact { width: min(500px, calc(100% - 28px)); }
.sheet-dialog::backdrop { background: rgba(36, 40, 35, .58); backdrop-filter: blur(5px); }
.dialog-card { max-height: calc(100vh - 30px); overflow-y: auto; padding: clamp(25px, 5vw, 44px); background: var(--card); }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.dialog-heading h2 { margin: 0; font-size: 2.6rem; letter-spacing: -.04em; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.toast { position: fixed; z-index: 50; right: 24px; bottom: 24px; max-width: min(390px, calc(100% - 48px)); padding: 14px 18px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: var(--shadow); opacity: 0; transform: translateY(15px); pointer-events: none; transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8e3f35; }

@media (max-width: 1000px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-story { min-height: 42vh; }
  .auth-panel { min-height: 58vh; }
  .hero { grid-template-columns: 1fr; gap: 24px; }
  .diary-card, .diary-card:nth-child(n) { grid-column: span 6; }
}

@media (max-width: 650px) {
  .auth-story { min-height: 36vh; padding: 34px 24px; }
  .story-copy h1 { font-size: 3.4rem; }
  .story-copy p:last-child { display: none; }
  .auth-panel { padding: 38px 24px; place-items: start center; }
  .topbar { padding: 14px 18px; }
  .brand span:last-child { display: none; }
  .dashboard { width: min(100% - 30px, 1380px); padding-top: 48px; }
  .hero { margin-bottom: 42px; }
  .hero h1 { font-size: 3.4rem; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-wrap { grid-column: 1 / -1; }
  .toolbar .button { padding-inline: 14px; }
  .diary-card, .diary-card:nth-child(n) { grid-column: 1 / -1; min-height: 290px; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
