:root {
  --bg-navy: #1F2A44;
  --paper: #EEF1F0;
  --surface: #FFFFFF;
  --chat-bg: #F6F8F7;
  --line: #1F2A44;
  --hair: #1F2A44;
  --skin: #FFFFFF;
  --feat: #1F2A44;
  --sun: #FFD23F;
  --blush: #FF9DB1;
  --mint: #BFE3D0;
  --muted: #64748B;
  --btn-ink: #1F2A44;
  --head: "Dela Gothic One", "Arial Black", sans-serif;
  --body: "Google Sans", "Noto Sans Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg-navy: #121829;
  --paper: #121829;
  --surface: #1A2238;
  --chat-bg: #141B2E;
  --line: #E6EBF5;
  --hair: #0A0E1A;
  --skin: #F1EEE8;
  --feat: #1F2A44;
  --mint: #1D3B35;
  --blush: #E9879D;
  --muted: #94A3B8;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--body);
  background-color: var(--bg-navy);
  color: var(--line);
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Static doodle pattern matching main site's second section */
body::before {
  --pat: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='20' cy='22' r='5'/%3E%3Cpath d='M82 26v14M75 33h14'/%3E%3Cpath d='M14 84q8-10 16 0t16 0t16 0'/%3E%3Cpath d='M92 88l8-12 8 12z'/%3E%3Ccircle cx='62' cy='60' r='2' fill='black'/%3E%3C/svg%3E");
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: #E6EBF5;
  opacity: 0.1;
  -webkit-mask-image: var(--pat);
  mask-image: var(--pat);
  -webkit-mask-size: 120px 120px;
  mask-size: 120px 120px;
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

.chat-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 700px;
  height: 100dvh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 720px) {
  .chat-shell {
    height: 92dvh;
    max-height: 860px;
    border-radius: 22px;
    border: 3px solid var(--line);
    box-shadow: 7px 7px 0 rgba(10, 14, 26, 0.55);
  }
}

/* Header */
.chat-header {
  padding: 14px 18px 16px;
  border-bottom: 2.5px dashed var(--line);
  background: var(--surface);
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--line);
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  box-shadow: 2px 2px 0 var(--line);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.back-link:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--line);
}

.back-link:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--line);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
  border: 2px solid var(--line);
}

.status-badge.online {
  background: var(--mint);
  color: var(--line);
}

.status-badge.offline {
  background: var(--paper);
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status-badge.online .status-dot {
  background: #10B981;
}

/* Hero Row: Text on left, Mr. Uze on far right */
.hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.hero-text {
  flex: 1;
  min-width: 0;
}

.uze-avatar {
  width: 80px;
  height: 84px;
  flex-shrink: 0;
}

.uze {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.uze * {
  stroke: var(--line);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.uze .f,
.uze .f * {
  stroke: var(--feat);
}

.uze .skin {
  fill: var(--skin);
}

.uze .solid {
  fill: var(--hair);
}

.uze .nofill {
  fill: none;
}

.uze .blush {
  fill: var(--blush);
  stroke: none;
}

.uze .eye {
  fill: var(--skin);
}

.uze .pupil {
  fill: var(--hair);
  stroke: none;
}

.uze .lid {
  fill: var(--skin);
  stroke: none;
  transform-box: fill-box;
  transform-origin: center top;
  animation: blink 4.5s infinite;
}

.uze .hop {
  animation: hop 2.8s ease-in-out infinite;
}

/* Toggle Normal (n) vs Sleepy (s) face */
.uze .fn,
.uze .fs {
  display: none;
}

.uze[data-f="n"] .fn,
.uze[data-f="s"] .fs {
  display: inline;
}

.uze .zzz {
  display: none;
}

.uze[data-f="s"] .zzz {
  display: block;
}

.uze text {
  stroke: none;
  fill: var(--line);
  font-family: var(--head);
  font-size: 26px;
}

.uze .z {
  animation: zrise 3s ease-in-out infinite;
  animation-delay: var(--d);
}

@keyframes zrise {
  0% { opacity: 0; transform: translate(0, 10px) scale(0.6); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translate(14px, -24px) scale(1.1); }
}

@keyframes blink {
  0%, 94%, 100% { transform: scaleY(0); }
  97% { transform: scaleY(1); }
}

@keyframes hop {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-5px) rotate(1.5deg); }
}

.silly-heading {
  font-family: var(--head);
  font-weight: 400;
  font-size: clamp(1.25rem, 4.5vw, 1.75rem);
  line-height: 1.2;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}

.silly-heading span {
  display: inline-block;
  animation: bob 2.4s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.1s);
}

.silly-heading span.sp {
  animation: none;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-0.14em) rotate(-4deg); }
}

.nickname-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.nickname-bar input {
  flex: 1;
  max-width: 210px;
  padding: 5px 10px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--line);
  font-family: var(--body);
  font-size: 0.88rem;
  font-weight: 500;
}

.nickname-bar input:focus {
  outline: none;
  background: var(--surface);
}

/* Offline Banner */
.offline-banner {
  background: var(--sun);
  color: var(--btn-ink);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 9px 18px;
  border-bottom: 2px solid var(--line);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

/* Messages Area */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--chat-bg);
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 12px 18px;
  border: 2px dashed var(--muted);
  border-radius: 16px;
}

.message-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: bubblePop 0.2s ease-out;
}

@keyframes bubblePop {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.message-row.visitor {
  align-self: flex-end;
  align-items: flex-end;
}

.message-row.admin {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  padding: 11px 15px;
  font-size: 0.98rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  border: 2.5px solid var(--line);
  box-shadow: 3px 3px 0 var(--line);
}

.message-row.visitor .message-bubble {
  background: var(--sun);
  color: #1F2A44;
  border-radius: 20px 20px 4px 20px;
}

.message-row.admin .message-bubble {
  background: #FFFFFF;
  color: #1F2A44;
  border-radius: 20px 20px 20px 4px;
}

.message-time {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 6px;
  padding: 0 4px;
}

/* Turnstile */
.turnstile-container {
  display: flex;
  justify-content: center;
  padding: 10px 16px 0;
  background: var(--surface);
  border-top: 2px solid var(--line);
}

/* Input Form */
.chat-form {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  border-top: 2px solid var(--line);
  background: var(--surface);
  align-items: flex-end;
}

.turnstile-container:not(.hidden) + .chat-form {
  border-top: none;
  padding-top: 10px;
}

.chat-form textarea {
  flex: 1;
  resize: none;
  padding: 10px 14px;
  border: 2.5px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--line);
  font-family: var(--body);
  font-size: 0.98rem;
  max-height: 120px;
  line-height: 1.5;
}

.chat-form textarea:focus {
  outline: none;
  background: var(--surface);
}

.chat-form button {
  padding: 10px 20px;
  background: var(--sun);
  color: var(--btn-ink);
  border: 2.5px solid var(--line);
  border-radius: 999px;
  font-family: var(--head);
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--line);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chat-form button:hover:not(:disabled) {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--line);
}

.chat-form button:active:not(:disabled) {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--line);
}

.chat-form button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}