:root {
  --bg: #17110d;
  --bg-glow: radial-gradient(ellipse at 20% -10%, rgba(224, 138, 62, 0.16), transparent 55%),
    radial-gradient(ellipse at 100% 100%, rgba(122, 74, 44, 0.18), transparent 50%);
  --surface: rgba(255, 240, 222, 0.06);
  --surface-alt: rgba(255, 240, 222, 0.04);
  --border: rgba(255, 214, 170, 0.16);
  --text: #f3e7d8;
  --text-muted: #b6a291;
  --accent: #e08a3e;
  --accent-hover: #f0a55c;
  --accent-soft: rgba(224, 138, 62, 0.22);
  --danger: #d9705c;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.4);
  --transition: 160ms ease;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, sans-serif;
  --glass-blur: blur(18px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font-body); background: var(--bg-glow), var(--bg); color: var(--text); line-height: 1.5; }
button, input { font-family: inherit; }
a { color: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap;
}

.top-nav { position: fixed; top: 1rem; right: 1rem; z-index: 20; display: flex; gap: .5rem; }
.nav-link {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem .9rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-full); font-size: .85rem; text-decoration: none;
  color: var(--text-muted); box-shadow: var(--shadow-sm); cursor: pointer;
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  transition: color var(--transition), border-color var(--transition);
}
.nav-link:hover, .nav-link:focus-visible { color: var(--accent); border-color: var(--accent); }

/* ---- Calendar page ---- */
.cal-page { height: 100dvh; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.cal-card {
  width: min(920px, 100%); height: min(760px, 100%);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); display: flex; flex-direction: column; padding: 1.5rem 1.75rem; gap: 1rem;
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
}
.cal-header { display: flex; align-items: center; justify-content: space-between; }
.cal-title { font-family: var(--font-display); font-size: clamp(1.3rem, 2.4vw, 1.8rem); font-weight: 600; letter-spacing: .01em; }
.cal-nav { display: flex; gap: .5rem; }
.cal-nav-btn {
  width: 2.25rem; height: 2.25rem; border-radius: var(--radius-full);
  border: 1px solid var(--border); background: var(--surface-alt); color: var(--text);
  font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.cal-nav-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.cal-nav-btn:active { transform: scale(.94); }
.cal-nav-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: .4rem;
  font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); text-align: center;
}
.cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); gap: .4rem; min-height: 0; }
.cal-cell {
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-alt);
  padding: .4rem; display: flex; flex-direction: column; gap: .25rem; min-height: 0; position: relative;
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
}
.cal-cell.is-empty { background: transparent; border-color: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
.cal-cell.is-today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent), 0 0 16px rgba(224, 138, 62, 0.35); }
.cal-daynum { font-size: .75rem; color: var(--text-muted); }
.cal-cell.is-today .cal-daynum { color: var(--accent); font-weight: 600; }
.cal-cell-btn { all: unset; cursor: pointer; flex: 1; display: flex; flex-direction: column; gap: .25rem; min-height: 0; width: 100%; }
.cal-cell-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
.cal-badge {
  align-self: flex-start; font-size: .62rem; padding: .1rem .4rem; border-radius: var(--radius-full);
  background: var(--surface); border: 1px dashed var(--accent); color: var(--accent);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.modal { display: none; position: fixed; inset: 0; z-index: 100; align-items: center; justify-content: center; }
.modal.is-open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(59, 46, 34, .35); }
.modal-box {
  position: relative; z-index: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.5rem; max-width: 380px; width: 90%; box-shadow: var(--shadow-md);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
}
.modal-close { position: absolute; top: .75rem; right: .75rem; background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); }
.modal-title { font-family: var(--font-display); font-size: 1.1rem; margin-bottom: .75rem; }
.modal-event { padding: .6rem 0; border-top: 1px dashed var(--border); }
.modal-event:first-of-type { border-top: none; }
.modal-event-name { font-weight: 600; }
.modal-event-sub { font-size: .8rem; color: var(--text-muted); }

/* ---- Manage page ---- */
.manage-page { min-height: 100dvh; padding: 4rem 1.5rem 3rem; display: flex; flex-direction: column; align-items: center; gap: 2rem; }
.manage-title { font-family: var(--font-display); font-size: clamp(1.4rem, 3vw, 2rem); text-align: center; }

.entry-bar {
  width: min(640px, 100%); display: flex; flex-wrap: wrap; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-full);
  padding: .5rem; box-shadow: var(--shadow-sm);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
}
.entry-bar input[type="text"] { flex: 1 1 160px; border: none; background: transparent; padding: .6rem .9rem; font-size: .95rem; color: var(--text); }
.entry-bar input[type="date"] { border: none; background: transparent; padding: .6rem .9rem; font-size: .9rem; color: var(--text); }
.entry-bar input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-md); }
.entry-submit {
  border: none; background: var(--accent); color: #fff; padding: .6rem 1.3rem; border-radius: var(--radius-full);
  font-weight: 600; font-size: .9rem; cursor: pointer; transition: background var(--transition), transform var(--transition);
}
.entry-submit:hover { background: var(--accent-hover); }
.entry-submit:active { transform: scale(.96); }
.entry-cancel { border: none; background: transparent; color: var(--text-muted); padding: .6rem .9rem; font-size: .85rem; cursor: pointer; }

.pill-list { width: min(720px, 100%); display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }
.pill {
  display: flex; align-items: center; gap: .5rem; background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius-full); padding: .5rem .5rem .5rem 1rem; box-shadow: var(--shadow-sm);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  animation: pill-in 220ms ease both;
}
@media (prefers-reduced-motion: reduce) { .pill { animation: none; } }
@keyframes pill-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pill-main { all: unset; cursor: pointer; display: flex; flex-direction: column; line-height: 1.25; }
.pill-main:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
.pill-name { font-weight: 600; font-size: .9rem; }
.pill-date { font-size: .72rem; color: var(--text-muted); }
.pill-delete {
  width: 1.6rem; height: 1.6rem; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-alt);
  color: var(--danger); cursor: pointer; font-size: .9rem; display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.pill-delete:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.pill.is-editing { border-style: solid; border-color: var(--accent); }

.empty-state { color: var(--text-muted); font-size: .9rem; text-align: center; }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1.1rem; border-radius: var(--radius-full);
  font-size: .85rem; box-shadow: var(--shadow-md); z-index: 200;
}

body.is-locked #app-content { display: none; }
.gate { display: none; position: fixed; inset: 0; z-index: 300; align-items: center; justify-content: center; background: var(--bg); }
body.is-locked .gate { display: flex; }
.gate-box {
  width: min(320px, 90%); display: flex; flex-direction: column; gap: .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.75rem; backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow-md);
}
.gate-title { font-family: var(--font-display); font-size: 1.2rem; text-align: center; }
.gate-box input[type="password"] {
  padding: .7rem .9rem; border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font-size: .95rem;
}
.gate-box input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.gate-submit {
  border: none; background: var(--accent); color: #fff; padding: .7rem; border-radius: var(--radius-full);
  font-weight: 600; cursor: pointer; transition: background var(--transition);
}
.gate-submit:hover { background: var(--accent-hover); }
.gate-error { color: var(--danger); font-size: .8rem; text-align: center; }

@media (max-width: 640px) {
  .cal-page { padding: 1rem; }
  .cal-card { padding: 1rem; border-radius: var(--radius-md); }
  .cal-badge { font-size: .55rem; }
}