:root {
  --bg: #F3F6FA;
  --page: #FFFFFF;
  --ink: #14213D;
  --muted: #6A7590;
  --line: #DCE3EC;
  --gold: #F2A93B;
  --teal: #1F7A8C;
  --sel: #FCEBCB;
  --danger: #C94A4A;
  --stars: none;
  --lh: 36px;
  --rule: rgba(20, 33, 61, 0.08);
  --chip: rgba(242, 169, 59, 0.2);
  --sunop: 0.6;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1120;
    --page: #121A30;
    --ink: #E8EDF7;
    --muted: #8F9BB8;
    --line: #26304F;
    --teal: #5BC0D3;
    --sel: #4A3814;
    --danger: #F07A7A;
    --stars:
      radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent),
      radial-gradient(1px 1px at 30% 8%, #fff 50%, transparent),
      radial-gradient(1.5px 1.5px at 52% 22%, #fff 50%, transparent),
      radial-gradient(1px 1px at 66% 10%, #fff 50%, transparent),
      radial-gradient(1.5px 1.5px at 78% 30%, #fff 50%, transparent),
      radial-gradient(1px 1px at 90% 16%, #fff 50%, transparent),
      radial-gradient(1px 1px at 40% 34%, #fff 50%, transparent);
    --rule: rgba(232, 237, 247, 0.07);
    --chip: rgba(242, 169, 59, 0.16);
    --sunop: 0.35;
  }
}

:root[data-theme="dark"] {
  --bg: #0B1120;
  --page: #121A30;
  --ink: #E8EDF7;
  --muted: #8F9BB8;
  --line: #26304F;
  --teal: #5BC0D3;
  --sel: #4A3814;
  --danger: #F07A7A;
  --stars:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent),
    radial-gradient(1px 1px at 30% 8%, #fff 50%, transparent),
    radial-gradient(1.5px 1.5px at 52% 22%, #fff 50%, transparent),
    radial-gradient(1px 1px at 66% 10%, #fff 50%, transparent),
    radial-gradient(1.5px 1.5px at 78% 30%, #fff 50%, transparent),
    radial-gradient(1px 1px at 90% 16%, #fff 50%, transparent),
    radial-gradient(1px 1px at 40% 34%, #fff 50%, transparent);
  --rule: rgba(232, 237, 247, 0.07);
  --chip: rgba(242, 169, 59, 0.16);
  --sunop: 0.35;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

::selection { background: var(--sel); }

/* Shared Dira logo & sky */
.mark {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 22px;
}
.mark i {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid var(--teal);
  display: block;
  position: relative;
}
.mark i::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 1px;
  width: 5px;
  height: 11px;
  margin-left: -2.5px;
  background: var(--gold);
  border-radius: 3px;
  transform: rotate(35deg);
  transform-origin: 50% 100%;
}

.sky {
  position: absolute;
  inset: 0 0 auto 0;
  height: 340px;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 100% at 90% 0%, rgba(242, 169, 59, 0.22), transparent 65%),
    radial-gradient(ellipse 70% 90% at 0% 0%, rgba(31, 122, 140, 0.16), transparent 70%);
  -webkit-mask-image: linear-gradient(#000 55%, transparent);
  mask-image: linear-gradient(#000 55%, transparent);
}
.sky::before {
  content: "";
  position: absolute;
  right: -36px;
  top: -64px;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: var(--gold);
  opacity: var(--sunop);
  animation: rise 1.6s cubic-bezier(.2, .7, .2, 1) both;
}
.sky::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--stars);
  background-repeat: no-repeat;
}
@keyframes rise {
  from { transform: translateY(100px); opacity: 0; }
  to { transform: none; opacity: var(--sunop); }
}

.ib {
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 14px;
}
.ib:hover {
  border-color: var(--muted);
}
.icon-btn {
  padding: 6px 10px;
  line-height: 1;
}

.new {
  margin: 0 16px 10px;
  border: 0;
  background: var(--gold);
  color: #2B1B00;
  border-radius: 14px;
  padding: 12px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(242, 169, 59, 0.28);
}
.new:hover {
  filter: brightness(1.03);
}

/* Sign-in screen */
#auth-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background: var(--page);
}
.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: color-mix(in srgb, var(--page) 86%, var(--bg));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(11, 17, 32, 0.12);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.auth-card h1 {
  font: 600 28px/1.2 'Newsreader', Georgia, serif;
  margin: 18px 0 8px;
}
.auth-sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}
.field {
  display: block;
  margin-bottom: 14px;
}
.field span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--page);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.auth-submit {
  width: 100%;
  margin: 8px 0 0;
}
.auth-error {
  margin: 4px 0 10px;
  color: var(--danger);
  font-size: 13.5px;
}
.auth-note {
  margin: 16px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

/* Main App Shell */
#shell {
  display: flex;
  height: 100%;
}

#side {
  width: 296px;
  flex: none;
  border-right: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
#side header {
  padding: 18px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.side-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
#close { display: none; }

.search-wrap {
  padding: 0 16px 8px;
}
#search {
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--page);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
}

#list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 16px;
}
.item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px 12px 34px;
  margin-bottom: 8px;
  position: relative;
}
.item::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 17px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line);
}
.item:hover {
  border-color: var(--muted);
}
.item[aria-current="true"] {
  border-color: var(--gold);
  box-shadow: none;
}
.item[aria-current="true"]::before {
  background: var(--gold);
}
.item b {
  display: block;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}
.empty {
  color: var(--muted);
  font-size: 14px;
  padding: 12px;
}

#user-bar {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.user-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.user-info strong {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-info span {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--page);
  position: relative;
  overflow: hidden;
}

#bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 14px;
  color: var(--muted);
  background: color-mix(in srgb, var(--page) 55%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
#bar .sp { flex: 1; }
#menu { display: none; }
#wc { color: var(--muted); }
#wc::before { content: "\00b7"; margin: 0 8px; }
#del { color: var(--muted); }

#paper {
  flex: 1;
  overflow-y: auto;
  position: relative;
  z-index: 1;
  background: transparent;
}
#doc {
  max-width: 720px;
  margin: 0 auto;
  padding: 36px 28px 96px;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

#title {
  border: 0;
  background: none;
  color: var(--ink);
  font: 600 40px/1.2 'Newsreader', Georgia, serif;
  letter-spacing: -0.01em;
  padding: 0;
  margin-bottom: 10px;
  width: 100%;
}
#date {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 6px;
  background: var(--chip);
  color: var(--ink);
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 26px;
}
#date::before {
  content: "\263E";
  color: var(--gold);
  font-size: 15px;
}
#body {
  flex: 1;
  min-height: 44vh;
  border: 0;
  background: none;
  resize: none;
  color: var(--ink);
  font: 400 20px/var(--lh) 'Newsreader', Georgia, serif;
  padding: 0;
  width: 100%;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--lh) - 1px),
    var(--rule) calc(var(--lh) - 1px),
    var(--rule) var(--lh)
  );
  background-attachment: local;
}
#title::placeholder, #body::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
#title:focus-visible, #body:focus-visible { outline: none; }

/* Dream Photos Section */
#photos-section {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px dashed var(--line);
}
.photos-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.photos-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
}
.photos-add-inline {
  font-size: 13px;
  padding: 5px 11px;
}
.drop-zone {
  border: 1.5px dashed transparent;
  border-radius: 16px;
  padding: 4px;
  transition: border-color 0.15s, background-color 0.15s;
}
.drop-zone.dragover {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 10%, transparent);
}
.photos-empty {
  margin: 0;
  padding: 16px;
  border-radius: 14px;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}
.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
}
.photo-card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg);
  aspect-ratio: 4 / 3;
}
.photo-thumb {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: rgba(11, 17, 32, 0.72);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.photo-remove:hover {
  background: var(--danger);
}

/* Lightbox Dialog */
#lightbox {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(94vw, 960px);
  max-height: 92vh;
  margin: auto;
  overflow: visible;
}
#lightbox::backdrop {
  background: rgba(8, 12, 24, 0.82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.lb-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
#lb-img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  background: var(--bg);
}
.lb-caption {
  color: #E8EDF7;
  font-size: 14px;
  text-align: center;
}
.lb-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--page);
  color: var(--ink);
  font-size: 20px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  color: var(--ink);
  font-size: 24px;
}
.lb-prev { left: 10px; }
.lb-next { right: 10px; }

#fab { display: none; }

@media (max-width: 760px) {
  :root { --lh: 34px; }
  #side {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 5;
    width: 86%;
    max-width: 320px;
    border-radius: 0 24px 24px 0;
    transform: translateX(-102%);
    transition: transform 0.2s;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
  }
  #side.open { transform: none; }
  #menu, #close { display: inline-block; }
  #title { font-size: 32px; line-height: 1.15; }
  #body { font-size: 19px; min-height: 36vh; }
  #doc { padding: 22px 20px 120px; }
  #bar {
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    flex-wrap: wrap;
  }
  #fab {
    display: grid;
    place-items: center;
    position: fixed;
    right: 18px;
    bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 0;
    background: var(--gold);
    color: #2B1B00;
    font-size: 32px;
    line-height: 1;
    z-index: 4;
    box-shadow: 0 12px 28px rgba(242, 169, 59, 0.5);
  }
  body:has(#body:focus) #fab { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #side { transition: none; }
  .sky::before { animation: none; }
}
