:root {
  color-scheme: light;
  --ink: #14080c;
  --yellow: #ffe135;
  --pink: #ff2d8a;
  --orange: #ff6a00;
  --neon: #ff4e00;
  --teal: #14e0d0;
  --violet: #7b2bff;
  --cream: #fff6d8;
  font-family: "Noto Serif Display", "Liberation Serif", "DejaVu Serif", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: #12080c;
  color: var(--ink);
  overflow-x: hidden;
}

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

button {
  border: 3px solid var(--ink);
  background: rgba(255, 225, 53, 0.72);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

button:hover { filter: brightness(1.06); }
button:disabled { opacity: 0.45; cursor: wait; filter: none; }
button:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

.poster-frame {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: none;
  background: #2a0848;
}

.poster-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("/backgrounds/margin-swirl.jpg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.poster {
  position: relative;
  z-index: 1;
  width: min(100vw, calc(100dvh * 2 / 3));
  height: min(100dvh, calc(100vw * 3 / 2));
  object-fit: contain;
  aspect-ratio: 2 / 3;
}

.stage {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 0.75rem;
  padding: 1rem;
  text-align: center;
}

.thread {
  width: min(40rem, 100%);
  flex: 0 1 auto;
  min-height: 0;
  max-height: min(42dvh, calc(100dvh - 10rem));
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  scrollbar-color: var(--pink) transparent;
  position: relative;
  z-index: 1;
}

.thread:empty { display: none; }

.bubble {
  max-width: 40rem;
  align-self: center;
  padding: 0.65rem 0.9rem;
  border: 3px solid var(--ink);
  border-radius: 1rem 0.45rem 1rem 0.55rem;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: center;
  font-weight: 700;
}

.bubble.user { background: rgba(255, 225, 53, 0.94); }
.bubble.reply { background: rgba(20, 224, 208, 0.94); }
.bubble.thinking,
.bubble.processing {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  background: rgba(20, 8, 12, 0.92);
  color: #fff6d8;
  -webkit-text-fill-color: #fff6d8;
  border-color: #fff6d8;
  border-style: dashed;
  font-style: italic;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.spin {
  width: 0.95rem;
  height: 0.95rem;
  flex: 0 0 auto;
  border: 3px solid rgba(255, 246, 216, 0.35);
  border-top-color: #fff6d8;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
.bubble.error { align-self: stretch; background: rgba(255, 45, 138, 0.82); color: var(--ink); }
.bubble .meta { display: block; margin-top: 0.3rem; font-size: 0.82rem; font-weight: 700; font-style: italic; }

.composer {
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  gap: 0.55rem;
  width: min(40rem, 100%);
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  position: relative;
  z-index: 2;
}

.field {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
}
.field > textarea,
.hip-ai {
  grid-area: 1 / 1;
}
.composer > button { flex: 0 0 auto; white-space: nowrap; }

.hip-ai {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  z-index: 1;
  pointer-events: none;
  color: #14080c;
  -webkit-text-fill-color: #14080c;
  font-weight: 800;
  font-size: 1.35rem;
  font-style: normal;
  letter-spacing: 0.02em;
}

.field:focus-within .hip-ai,
.field.has-text .hip-ai {
  display: none;
}

#message {
  min-height: 3.3rem;
  background: rgba(255, 246, 216, 0.7);
  border: 3px solid var(--ink);
  border-radius: 1.5rem 0.4rem 1.35rem 0.7rem;
  box-shadow: 5px 5px 0 rgba(255, 78, 0, 0.95);
  color: var(--ink);
  font-size: 1.05rem;
}

#send {
  min-height: 3.3rem;
  padding: 0 1.25rem;
  background: rgba(255, 78, 0, 0.9);
  border-radius: 0.45rem 1.35rem 0.5rem 1.2rem;
  box-shadow: 5px 5px 0 var(--teal);
  font-size: 1.15rem;
}

textarea {
  width: 100%;
  border: 2px solid var(--ink);
  border-radius: 0.7rem;
  padding: 0.55rem 0.7rem;
  color: var(--ink);
  resize: vertical;
}

textarea,
#message {
  background-color: rgba(255, 246, 216, 0.72);
  color: #14080c;
  -webkit-text-fill-color: #14080c;
  caret-color: #14080c;
  font-weight: 800;
  font-size: 1.2rem;
  font-style: normal;
  text-shadow: none;
}

textarea::placeholder,
#message::placeholder {
  color: #1a0a10;
  opacity: 1;
  font-weight: 800;
}

.banner {
  position: relative;
  z-index: 1;
  margin: 1rem auto;
  width: min(40rem, calc(100% - 2rem));
  padding: 0.45rem 0.8rem;
  border: 3px solid var(--ink);
  background: rgba(255, 225, 53, 0.72);
  color: var(--ink);
  border-radius: 999px;
  font-weight: 700;
  text-align: center;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.history-toggle {
  position: fixed;
  left: 0;
  top: 1rem;
  z-index: 4;
  min-height: 5.5rem;
  padding: 0.7rem 0.35rem;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  background: rgba(255, 225, 53, 0.92);
  border-radius: 0 0.8rem 0.8rem 0;
  box-shadow: 4px 4px 0 var(--neon);
}

.history {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  width: min(18rem, 80vw);
  margin: 0;
  padding: 4.6rem 0.8rem 1rem 2.4rem;
  overflow: auto;
  background: rgba(20, 8, 12, 0.88);
  color: var(--cream);
  border-right: 3px solid var(--ink);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  pointer-events: none;
}

body.history-open .history {
  transform: translateX(0);
  pointer-events: auto;
}

#history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.history-empty {
  margin: 0;
  color: var(--cream);
  font-weight: 700;
}

.history-item {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(255, 246, 216, 0.92);
  color: var(--ink);
  border-radius: 0.7rem;
  padding: 0.45rem 0.6rem;
  box-shadow: 3px 3px 0 var(--teal);
}

.history-item.current {
  background: var(--yellow);
  box-shadow: 3px 3px 0 var(--neon);
}

.history-item small {
  display: block;
  margin-top: 0.15rem;
  font-weight: 700;
  opacity: 0.8;
}

@media (max-width: 699px) {
  .stage { padding: 0.7rem 0.65rem 0.85rem; }
  .thread { max-height: min(40dvh, calc(100dvh - 8.5rem)); }
  #message, #send { min-height: 2.9rem; }
}

@media (min-width: 700px) and (max-width: 1099px) {
  .stage { padding: 1rem 2.2rem 1.2rem; }
}

@media (min-width: 1100px) {
  .stage { padding: 1.2rem 4rem 1.4rem; }
}
