:root {
  --ga-ink: #1d1a17;
  --ga-paper: #f4ecda;
  --ga-paper-deep: #e6d6b7;
  --ga-bronze: #8a622d;
  --ga-gold: #c69a4b;
  --ga-crimson: #7c2024;
  --ga-shadow: rgba(24, 17, 11, 0.24);
}

.ga-rules-assistant,
.ga-rules-assistant * {
  box-sizing: border-box;
}

.ga-rules-assistant {
  position: fixed;
  z-index: 9999;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ga-ink);
}

.ga-rules-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 18px 8px 9px;
  border: 1px solid #6f481d;
  border-radius: 999px;
  background: linear-gradient(180deg, #b98b43, #805923);
  color: #fff8e7;
  box-shadow: 0 12px 30px var(--ga-shadow), inset 0 1px rgba(255, 255, 255, 0.35);
  cursor: pointer;
  font: 700 15px/1 Georgia, "Times New Roman", serif;
  letter-spacing: 0.01em;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.ga-rules-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 36px rgba(24, 17, 11, 0.32), inset 0 1px rgba(255, 255, 255, 0.35);
}

.ga-rules-launcher:focus-visible,
.ga-rules-panel button:focus-visible,
.ga-rules-panel textarea:focus-visible,
.ga-rules-panel a:focus-visible {
  outline: 3px solid #e9bd67;
  outline-offset: 2px;
}

.ga-rules-launcher-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: rgba(56, 32, 10, 0.28);
  font-size: 21px;
}

.ga-rules-panel {
  position: absolute;
  right: 0;
  bottom: 66px;
  display: grid;
  grid-template-rows: auto auto minmax(160px, 1fr) auto auto;
  width: min(420px, calc(100vw - 28px));
  height: min(680px, calc(100vh - 110px));
  overflow: hidden;
  border: 1px solid #7f5b2c;
  border-radius: 18px;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.55), transparent 32%),
    linear-gradient(180deg, #f8f1e3, var(--ga-paper));
  box-shadow: 0 24px 70px rgba(20, 13, 8, 0.38);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(10px) scale(0.985);
  transform-origin: bottom right;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 0s linear 180ms;
}

.ga-rules-assistant.is-open .ga-rules-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.ga-rules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(113, 77, 35, 0.35);
  background: linear-gradient(135deg, #3b3025, #201a15);
  color: #fff6e5;
}

.ga-rules-eyebrow {
  margin: 0 0 3px;
  color: #d7b875;
  font: 700 11px/1.2 system-ui, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.ga-rules-header h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.1;
}

.ga-rules-close {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  font: 400 27px/1 system-ui, sans-serif;
}

.ga-rules-notice {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(113, 77, 35, 0.24);
  background: rgba(198, 154, 75, 0.13);
  color: #5a4328;
  font: 12px/1.4 system-ui, sans-serif;
}

.ga-rules-messages {
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
}

.ga-rules-message {
  width: min(92%, 360px);
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(94, 66, 33, 0.24);
  border-radius: 14px 14px 14px 4px;
  background: rgba(255, 252, 245, 0.78);
  box-shadow: 0 4px 12px rgba(45, 31, 18, 0.07);
}

.ga-rules-message.user {
  margin-left: auto;
  border-color: #6d3030;
  border-radius: 14px 14px 4px 14px;
  background: linear-gradient(145deg, #8e3034, #641e22);
  color: #fff9ed;
}

.ga-rules-role {
  display: block;
  margin-bottom: 7px;
  color: var(--ga-bronze);
  font: 800 10px/1 system-ui, sans-serif;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.ga-rules-message.user .ga-rules-role {
  color: #f1cb83;
}

.ga-rules-answer p {
  margin: 0 0 9px;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.48;
}

.ga-rules-answer p:last-child {
  margin-bottom: 0;
}

.ga-rules-ruling-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.ga-rules-ruling-meta span {
  padding: 4px 7px;
  border: 1px solid rgba(96, 63, 26, 0.25);
  border-radius: 999px;
  background: rgba(198, 154, 75, 0.12);
  color: #684b28;
  font: 700 10px/1 system-ui, sans-serif;
  text-transform: capitalize;
}

.ga-rules-sources {
  margin-top: 10px;
  border-top: 1px solid rgba(100, 72, 42, 0.18);
  padding-top: 8px;
  font: 12px/1.4 system-ui, sans-serif;
}

.ga-rules-sources summary {
  color: #704d23;
  cursor: pointer;
  font-weight: 800;
}

.ga-rules-sources ol {
  margin: 8px 0 0;
  padding-left: 20px;
}

.ga-rules-sources li {
  margin-bottom: 9px;
}

.ga-rules-sources a {
  color: #6f2528;
  font-weight: 800;
}

.ga-rules-sources p {
  display: -webkit-box;
  overflow: hidden;
  margin: 3px 0 0;
  color: #5c5145;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.ga-rules-suggestions {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 0 16px 12px;
}

.ga-rules-suggestion {
  flex: 0 0 auto;
  max-width: 240px;
  padding: 8px 10px;
  border: 1px solid rgba(108, 72, 31, 0.35);
  border-radius: 999px;
  background: rgba(255, 251, 240, 0.7);
  color: #5a3d20;
  cursor: pointer;
  font: 700 11px/1.2 system-ui, sans-serif;
}

.ga-rules-form {
  padding: 13px 14px 12px;
  border-top: 1px solid rgba(113, 77, 35, 0.3);
  background: rgba(232, 217, 187, 0.62);
}

.ga-rules-input-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.ga-rules-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.ga-rules-input-row textarea {
  width: 100%;
  min-height: 47px;
  max-height: 120px;
  resize: vertical;
  border: 1px solid #a88658;
  border-radius: 10px;
  background: #fffdf8;
  color: #211c17;
  padding: 10px 11px;
  font: 14px/1.35 system-ui, sans-serif;
}

.ga-rules-send {
  min-height: 47px;
  padding: 0 15px;
  border: 1px solid #672126;
  border-radius: 10px;
  background: linear-gradient(180deg, #98383d, #671f23);
  color: #fff;
  cursor: pointer;
  font: 800 13px/1 system-ui, sans-serif;
}

.ga-rules-send:disabled {
  cursor: wait;
  opacity: 0.6;
}

.ga-rules-form-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 20px;
  margin-top: 6px;
  color: #675a4b;
  font: 11px/1.2 system-ui, sans-serif;
}

.ga-rules-status.is-error {
  color: #8a2025;
  font-weight: 700;
}

.ga-rules-clear {
  border: 0;
  background: transparent;
  color: #6e4c25;
  cursor: pointer;
  font: 700 11px/1 system-ui, sans-serif;
  text-decoration: underline;
}

.ga-rules-thinking {
  display: flex;
  gap: 5px;
  padding: 4px 0 2px;
}

.ga-rules-thinking span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ga-bronze);
  animation: ga-rules-pulse 1s infinite ease-in-out;
}

.ga-rules-thinking span:nth-child(2) { animation-delay: 120ms; }
.ga-rules-thinking span:nth-child(3) { animation-delay: 240ms; }

@keyframes ga-rules-pulse {
  0%, 70%, 100% { opacity: 0.25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}

@media (max-width: 620px) {
  .ga-rules-assistant {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .ga-rules-launcher-label {
    display: none;
  }

  .ga-rules-launcher {
    width: 52px;
    padding: 8px;
  }

  .ga-rules-panel {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    height: min(78vh, 720px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 20px 20px 0 0;
    transform-origin: bottom center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ga-rules-panel,
  .ga-rules-launcher,
  .ga-rules-thinking span {
    animation: none;
    transition: none;
  }
}
