:root {
  --rose: #ded0ff;
  --rose-dark: #7c4dff;
  --peach: #ffd8bd;
  --cream: #fffaf5;
  --warm: #fff3eb;
  --text: #302a2c;
  --muted: #776a70;
  --line: #ead8d2;
  --green: #79a88d;
  --gold: #d4a93f;
  --gray: #a9a0a4;
  --shadow: 0 18px 45px rgba(96, 55, 64, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(222, 208, 255, 0.5), transparent 34rem),
    linear-gradient(135deg, var(--cream), #fff7fb 48%, #f8fbf8);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  background: rgba(255, 250, 245, 0.88);
  border-bottom: 1px solid rgba(234, 216, 210, 0.72);
  backdrop-filter: blur(16px);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 4vw, 2.7rem);
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

h3 {
  margin-bottom: 0.55rem;
}

.eyebrow {
  margin-bottom: 0.25rem;
  color: var(--rose-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tab,
.mini-tab,
.ghost,
.secondary,
.primary {
  min-height: 2.75rem;
  border: 0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-weight: 800;
}

.tab {
  background: transparent;
  color: var(--muted);
}

.tab.active,
.mini-tab.active,
.secondary {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.mini-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.mini-tab {
  background: rgba(255, 255, 255, 0.45);
  color: var(--muted);
}

.primary {
  background: linear-gradient(135deg, var(--rose-dark), #5b32c7);
  color: white;
  box-shadow: 0 12px 24px rgba(124, 77, 255, 0.24);
}

.ghost {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
}

.hidden {
  display: none !important;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.auth-shell {
  width: min(100% - 2rem, 460px);
  margin: 0 auto;
}

.auth-card {
  border: 1px solid rgba(234, 216, 210, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 4vw, 1.4rem);
}

.auth-card h1,
.auth-card h2 {
  margin-bottom: 0;
}

.account-menu {
  position: relative;
}

.account-menu summary {
  display: grid;
  min-height: 2.75rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  cursor: pointer;
  font-weight: 900;
  list-style: none;
  padding: 0.7rem 1rem;
}

.account-menu summary::-webkit-details-marker {
  display: none;
}

.account-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 30;
  display: grid;
  gap: 0.8rem;
  width: min(92vw, 360px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 245, 0.98);
  box-shadow: var(--shadow);
  padding: 0.9rem;
}

.account-head {
  display: grid;
  gap: 0.15rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.7rem;
}

.account-head span,
.compact-list-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.account-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.compact-form {
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.compact-form h3,
.account-panel h3 {
  font-size: 1rem;
  margin-bottom: 0;
}

.compact-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.compact-list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  padding: 0.6rem;
}

.compact-list-item.active-user {
  border-color: rgba(124, 77, 255, 0.55);
  background: rgba(222, 208, 255, 0.25);
}

main {
  width: min(1180px, calc(100% - 2rem));
  margin: 0.8rem auto 3rem;
}

.side-panel,
.wheel-panel,
.diary-form,
.wordle-shell {
  border: 1px solid rgba(234, 216, 210, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.mini-view {
  display: none;
}

.mini-view.active {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin: 1.3rem 0 1rem;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  padding: 0.85rem;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.wheel-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(300px, 0.85fr);
  gap: 1rem;
}

.wheel-panel {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 2rem);
}

.pointer {
  width: 0;
  height: 0;
  border-left: 17px solid transparent;
  border-right: 17px solid transparent;
  border-top: 34px solid var(--rose-dark);
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
}

#dateWheel {
  width: min(100%, 420px);
  aspect-ratio: 1;
  border-radius: 50%;
  transition: transform 4s cubic-bezier(0.12, 0.72, 0.18, 1);
}

.side-panel {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.result-card {
  min-height: 12rem;
  border-radius: 8px;
  padding: 1rem;
  background: linear-gradient(135deg, #fff, var(--warm));
  border: 1px solid var(--line);
}

.muted {
  color: var(--muted);
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.8rem 0;
}

.pill {
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  background: rgba(222, 208, 255, 0.38);
  color: #7b4050;
  font-weight: 800;
  font-size: 0.84rem;
}

.status-text {
  min-height: 1.25rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.ai-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  background: rgba(255, 243, 235, 0.58);
}

.ai-suggestions {
  display: grid;
  gap: 0.75rem;
}

.ai-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem;
  background: rgba(255, 255, 255, 0.86);
}

.ai-card h4 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
}

.ai-card p {
  color: var(--muted);
}

.form {
  display: grid;
  gap: 0.8rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.diary-form {
  margin-bottom: 1rem;
  padding: 1rem;
}

.diary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
  gap: 1rem;
}

.diary-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow);
}

.diary-card img,
.photo-placeholder {
  width: 100%;
  height: 190px;
  object-fit: cover;
  display: block;
  background: linear-gradient(135deg, var(--rose), var(--peach));
}

.photo-placeholder {
  display: grid;
  place-items: center;
  color: #7b4050;
  font-weight: 900;
}

.diary-content {
  padding: 1rem;
}

.card-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.stars {
  color: var(--gold);
  font-size: 1.1rem;
  margin: 0.45rem 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.wordle-shell {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem;
}

.hint {
  color: var(--muted);
}

.wordle-board {
  display: grid;
  gap: 0.45rem;
  margin: 1rem 0;
}

.wordle-row {
  display: grid;
  gap: 0.45rem;
}

.tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: white;
  font-size: clamp(1.15rem, 7vw, 1.8rem);
  font-weight: 900;
  text-transform: uppercase;
}

.tile.correct {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.tile.present {
  background: var(--gold);
  border-color: var(--gold);
  color: white;
}

.tile.absent {
  background: var(--gray);
  border-color: var(--gray);
  color: white;
}

.wordle-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
}

.wordle-message {
  min-height: 1.5rem;
  margin: 0.8rem 0 0;
  font-weight: 800;
}

.wordle-admin {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.9rem;
}

.wordle-admin summary {
  cursor: pointer;
  color: var(--rose-dark);
  font-weight: 900;
}

.wordle-admin-form {
  margin-top: 0.85rem;
}

.wordle-word-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.wordle-word-item {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  padding: 0.65rem;
}

.wordle-word-item div {
  display: grid;
  gap: 0.15rem;
}

.wordle-word-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.game-shell,
.book-shell {
  border: 1px solid rgba(234, 216, 210, 0.85);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(96, 55, 64, 0.08), transparent 10%, transparent 90%, rgba(96, 55, 64, 0.08)),
    rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  padding: clamp(0.85rem, 3vw, 1.25rem);
}

.game-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.counter {
  display: inline-grid;
  min-height: 2.75rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-weight: 900;
}

.memory-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(0.4rem, 2vw, 0.75rem);
  width: min(100%, 560px);
  margin: 0 auto;
}

.memory-card {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--rose), var(--peach));
  color: #7b4050;
  font-weight: 900;
  transform-style: preserve-3d;
}

.memory-card img,
.memory-back {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  object-fit: cover;
  transition: opacity 0.18s ease;
}

.memory-card img {
  opacity: 0;
}

.memory-card.flipped img {
  opacity: 1;
}

.memory-card.flipped .memory-back {
  opacity: 0;
}

.puzzle-board {
  --puzzle-size: min(82vw, 480px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: var(--puzzle-size);
  height: var(--puzzle-size);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.puzzle-piece {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255, 250, 245, 0.86);
  background-color: white;
  background-size: 400% 400%;
}

.puzzle-piece.selected {
  box-shadow: inset 0 0 0 4px var(--rose-dark);
}

.crop-area {
  display: grid;
  grid-template-columns: minmax(220px, 420px) 1fr;
  gap: 1rem;
  align-items: start;
}

#cropCanvas {
  width: min(100%, 420px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: grab;
  touch-action: none;
}

#cropCanvas:active {
  cursor: grabbing;
}

.crop-controls {
  display: grid;
  gap: 0.8rem;
}

.crop-controls label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 800;
}

.game-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.game-image-card {
  display: grid;
  gap: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  padding: 0.65rem;
}

.game-image-card img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: cover;
}

.game-image-card div {
  display: grid;
  gap: 0.15rem;
}

.game-image-card span {
  color: var(--muted);
  font-size: 0.84rem;
}

.flipbook-wrap {
  display: grid;
  justify-content: center;
  overflow-x: auto;
  padding: 1rem 0 0.7rem;
}

.story-flipbook {
  --page-width: min(38vw, 380px);
  --page-height: min(56vw, 540px);
  position: relative;
  width: calc(var(--page-width) * 2);
  height: var(--page-height);
  perspective: 2200px;
  transform-style: preserve-3d;
  filter: drop-shadow(0 28px 28px rgba(96, 55, 64, 0.18));
}

.story-flipbook::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 1px);
  width: 2px;
  z-index: 200;
  pointer-events: none;
  background: linear-gradient(
    to right,
    rgba(62, 43, 45, 0.22),
    rgba(255, 255, 255, 0.55),
    rgba(62, 43, 45, 0.18)
  );
}

.story-book-page {
  position: absolute;
  top: 0;
  width: var(--page-width);
  height: var(--page-height);
  margin: 0;
  border: 1px solid #dfd0c8;
  padding: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.28), rgba(255,250,241,0)),
    repeating-linear-gradient(0deg, rgba(124, 77, 255, 0.018), rgba(124, 77, 255, 0.018) 1px, transparent 1px, transparent 28px),
    #fffaf1;
  color: var(--text);
  text-align: left;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  transition:
    transform 0.92s cubic-bezier(0.22, 0.86, 0.22, 1),
    box-shadow 0.92s ease,
    filter 0.92s ease;
  box-shadow: 0 18px 30px rgba(96, 55, 64, 0.13);
  will-change: transform;
}

.story-book-page::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  transition: background 0.5s ease;
}

.story-book-page::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 34px;
  z-index: 3;
  pointer-events: none;
  opacity: 0.62;
}

.story-book-page:nth-child(odd) {
  right: 0;
  transform-origin: left center;
  border-radius: 0 8px 8px 0;
  background-image: linear-gradient(to right, rgba(48, 42, 44, 0.13), rgba(255, 250, 241, 0) 14%);
}

.story-book-page:nth-child(odd):hover {
  transform: rotateY(-12deg);
}

.story-book-page.turning:nth-child(odd) {
  box-shadow: -18px 22px 38px rgba(48, 42, 44, 0.24);
  filter: brightness(0.98);
}

.story-book-page:nth-child(odd)::after {
  left: 0;
  background: linear-gradient(to right, rgba(48, 42, 44, 0.16), transparent);
}

.story-book-page:nth-child(even) {
  left: 0;
  transform-origin: right center;
  transform: rotateY(180deg);
  border-radius: 8px 0 0 8px;
  pointer-events: none;
  background-image: linear-gradient(to left, rgba(48, 42, 44, 0.12), rgba(255, 250, 241, 0) 14%);
}

.story-book-page.flipped:nth-child(odd) {
  transform: rotateY(-180deg);
  pointer-events: none;
}

.story-book-page.flipped:nth-child(even) {
  transform: rotateY(0deg);
  pointer-events: auto;
}

.story-book-page.flipped:nth-child(even):hover {
  transform: rotateY(12deg);
}

.story-book-page.turning:nth-child(even) {
  box-shadow: 18px 22px 38px rgba(48, 42, 44, 0.22);
  filter: brightness(1.02);
}

.story-book-page.instant-reveal {
  transition: none;
}

.story-book-page:nth-child(even)::after {
  right: 0;
  background: linear-gradient(to left, rgba(48, 42, 44, 0.14), transparent);
}

.story-book-page:nth-child(even)::before,
.story-book-page.flipped:nth-child(odd)::before {
  background: rgba(48, 42, 44, 0.18);
}

.story-book-page:nth-child(odd)::before,
.story-book-page.flipped:nth-child(even)::before {
  background: rgba(48, 42, 44, 0);
}

.story-page-inner {
  height: 100%;
  overflow: hidden;
  padding: clamp(1rem, 2vw, 1.45rem);
}

.story-measure-page {
  position: fixed;
  left: -9999px;
  top: 0;
  z-index: -1;
  visibility: hidden;
  pointer-events: none;
  background: #fffaf1;
  box-sizing: border-box;
}

.story-page-inner img {
  width: 100%;
  max-height: 55%;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.story-page-inner h3 {
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
}

.story-page-inner p {
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.82rem, 1.24vw, 1.02rem);
  line-height: 1.58;
  white-space: pre-line;
}

.story-subtitle {
  color: var(--rose-dark);
  font-weight: 900;
  text-align: center;
}

.story-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 245, 0.72);
  margin-bottom: 0.75rem;
  padding: 0.85rem;
}

.story-editor summary {
  cursor: pointer;
  color: var(--rose-dark);
  font-weight: 900;
}

.story-editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 0.9rem;
}

.chapter-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.chapter-item {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  padding: 0.65rem;
}

.chapter-item div {
  display: grid;
  gap: 0.15rem;
}

.chapter-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.confetti {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 50;
}

.confetti i {
  position: absolute;
  top: -1rem;
  width: 0.6rem;
  height: 0.9rem;
  background: var(--rose-dark);
  animation: fall 1.8s linear forwards;
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(620deg);
    opacity: 0;
  }
}

@media (max-width: 820px) {
  .wheel-layout,
  .section-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .section-head,
  .game-head {
    align-items: stretch;
  }

  .topbar {
    align-items: stretch;
    display: grid;
    gap: 0.65rem;
    padding: 0.7rem 0.75rem 0.6rem;
  }

  .topbar h1 {
    font-size: 1.35rem;
    line-height: 1.1;
  }

  .topbar .eyebrow {
    margin-bottom: 0.1rem;
    font-size: 0.68rem;
  }

  .tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.4rem;
    margin: 0 -0.75rem;
    overflow-x: auto;
    padding: 0 0.75rem 0.15rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 2.35rem;
    padding: 0.62rem 0.8rem;
    white-space: nowrap;
  }

  .account-menu {
    justify-self: stretch;
  }

  .account-menu summary {
    min-height: 2.35rem;
    padding: 0.62rem 0.8rem;
  }

  .account-panel {
    left: 0;
    right: 0;
    width: auto;
  }

  .mini-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.4rem;
    margin: 0 -0.75rem;
    overflow-x: auto;
    padding: 0 0.75rem 0.15rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .mini-tabs::-webkit-scrollbar {
    display: none;
  }

  .mini-tab {
    flex: 0 0 auto;
    min-height: 2.35rem;
    padding: 0.62rem 0.8rem;
    white-space: nowrap;
  }

  .story-editor-grid {
    grid-template-columns: 1fr;
  }

  .story-flipbook {
    --page-width: min(44vw, 320px);
    --page-height: min(68vw, 490px);
  }

  .crop-area {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  main {
    width: min(100% - 1rem, 1180px);
    margin-top: 0.55rem;
  }

  .form-grid,
  .wordle-form {
    grid-template-columns: 1fr;
  }

  .wheel-panel,
  .side-panel,
  .diary-form,
  .wordle-shell,
  .game-shell,
  .book-shell {
    padding: 0.85rem;
  }

  .memory-board {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .memory-back {
    font-size: 0.75rem;
  }

  .game-head {
    display: grid;
  }

  .story-flipbook {
    --page-width: min(45vw, 220px);
    --page-height: min(78vw, 380px);
  }

  .story-page-inner {
    padding: 0.7rem;
  }

  .story-page-inner p {
    font-size: 0.78rem;
    line-height: 1.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .story-book-page {
    transition: none;
  }
}
