:root {
  --bg: #fbf1d9;
  --ink: #2b2a33;
  --muted: #6d6a75;
  --teal: #2a9d8f;
  --teal-dark: #1f7a70;
  --mustard: #e9b949;
  --card: #fffaf0;
  --visitor: #ffe0a8;
  --sluch: #d3efe9;
  --line: #e4d5b0;
  --danger: #c0392b;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(#ecdcae 1.4px, transparent 1.6px);
  background-size: 22px 22px;
  font: 17px/1.5 "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
.wrap { max-width: 660px; margin: 0 auto; padding: 24px 16px 40px; }

header { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
header svg { flex: 0 0 auto; width: 132px; height: auto; overflow: visible; }
.cord { transform-origin: 44px 122px; animation: cord-swing 3.6s ease-in-out infinite; }
@keyframes cord-swing {
  0%, 100% { transform: rotate(-4deg) scaleY(0.97); }
  25% { transform: rotate(0deg) scaleY(1.05); }
  50% { transform: rotate(4deg) scaleY(0.97); }
  75% { transform: rotate(0deg) scaleY(1.05); }
}
.spark { opacity: 0; animation: spark-flicker 1.3s infinite; }
.spark.s2 { animation-delay: 0.35s; }
.spark.s3 { animation-delay: 0.7s; }
.spark.s4 { animation-delay: 1s; }
@keyframes spark-flicker {
  0%, 20%, 55%, 70%, 100% { opacity: 0; }
  8%, 62% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .cord { animation: none; }
  .spark { animation: none; opacity: 1; }
}
h1 { margin: 0 0 4px; font-size: 2.1rem; line-height: 1.1; letter-spacing: -0.5px; color: var(--teal-dark); }
.tagline { margin: 0; color: var(--ink); font-size: 1.05rem; }

.chat {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 6px 6px 0 var(--ink);
  overflow: hidden;
}
.log {
  padding: 16px;
  height: 52vh;
  min-height: 300px;
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { max-width: 82%; padding: 9px 13px; border-radius: 16px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.visitor { align-self: flex-end; background: var(--visitor); border-bottom-right-radius: 4px; }
.msg.sluchatko { align-self: flex-start; background: var(--sluch); border-bottom-left-radius: 4px; }
.msg img { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin-top: 6px; }
.msg img:first-child { margin-top: 0; }
.who { display: block; font-size: 0.72rem; font-weight: 700; color: var(--teal-dark); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 2px; }
.time { display: block; font-size: 0.7rem; color: var(--muted); margin-top: 3px; white-space: normal; }
.typing { align-self: flex-start; color: var(--muted); font-style: italic; font-size: 0.92rem; padding: 2px 6px; }

form.send { display: flex; gap: 8px; padding: 12px; border-top: 3px solid var(--ink); background: #fff3d1; }
.langbar { display: flex; justify-content: flex-end; gap: 6px; margin: 0 0 12px; }
.langbar button { padding: 3px 12px; font-size: 0.78rem; letter-spacing: 0.04em; border-radius: 9px; background: #fff; color: var(--ink); box-shadow: 1px 1px 0 var(--ink); }
.langbar button:hover { background: #f4ead0; }
.langbar button[aria-pressed="true"] { background: var(--teal); color: #fff; }
.langbar button:focus-visible { outline: 3px solid var(--mustard); outline-offset: 1px; }
textarea, input[type="password"] {
  flex: 1;
  font: inherit;
  padding: 9px 12px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  resize: none;
}
textarea:focus, input:focus { outline: 3px solid var(--mustard); outline-offset: 1px; }
button {
  font: inherit;
  font-weight: 700;
  padding: 9px 18px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}
button:hover { background: var(--teal-dark); }
button:active { transform: translate(2px, 2px); box-shadow: none; }
button:disabled { opacity: 0.55; cursor: default; }
button.ghost { background: #fff; color: var(--ink); }
button.ghost:hover { background: #f4ead0; }
button.danger { background: var(--danger); }

.err { min-height: 1.3em; margin: 8px 4px 0; color: var(--danger); font-size: 0.92rem; }
.note { margin: 14px 4px 0; color: var(--muted); font-size: 0.85rem; }

/* admin */
.admin-grid { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.admin-wrap { max-width: 1000px; }
.threads { background: var(--card); border: 3px solid var(--ink); border-radius: 16px; max-height: 75vh; overflow-y: auto; }
.thread { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--ink); box-shadow: none; font-weight: 400; }
.thread:hover { background: #f8ecc9; }
.thread.active { background: var(--visitor); }
.thread b { display: flex; justify-content: space-between; gap: 8px; }
.thread .badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 8px; font-size: 0.75rem; }
.thread span.last { display: block; color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-top: 3px solid var(--ink); background: #fff3d1; }
.reply textarea { width: 100%; min-height: 84px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.quick button { font-weight: 400; font-size: 0.9rem; padding: 5px 10px; }
.empty { color: var(--muted); padding: 20px; }
.head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.hidden { display: none !important; }

@media (max-width: 720px) {
  header svg { width: 96px; }
  h1 { font-size: 1.6rem; }
  .admin-grid { grid-template-columns: 1fr; }
  .threads { max-height: 30vh; }
  .msg { max-width: 92%; }
}
