:root {
  --bg: #7f0815;
  --panel: #ffffff;
  --ink: #241812;
  --muted: #77685d;
  --line: #f4d5b8;
  --red: #e31a2f;
  --red-dark: #8d0714;
  --gold: #ffc928;
  --gold-soft: #fff4bc;
  --green: #12805c;
  --cell: #fff9e9;
  --shadow: 0 20px 60px rgba(65, 0, 10, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 201, 40, 0.3), transparent 10rem),
    radial-gradient(circle at 90% 8%, rgba(255, 255, 255, 0.18), transparent 8rem),
    linear-gradient(180deg, #b00819 0%, var(--bg) 100%);
}

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

.page-shell, .chat-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  place-items: center;
}

.reward-card, .chat-panel {
  width: 100%;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.reward-card {
  max-width: 560px;
  padding: 14px;
  text-align: center;
  background: linear-gradient(180deg, #ff2b38 0%, #c70720 100%);
  border: 5px solid #ff4b41;
  outline: 3px solid rgba(255, 201, 40, 0.72);
  color: #fff;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.utility-button {
  min-height: 34px;
  border: 1px solid rgba(255, 242, 168, 0.74);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(255, 249, 233, 0.96);
  color: var(--red-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 3px 0 rgba(94, 10, 10, 0.24);
}

.reset-visitor-button {
  background: #fff4bc;
}

.campaign-topline {
  margin: 2px 0 8px;
  color: #fff2a8;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.12;
}

h1 { font-size: clamp(24px, 8vw, 42px); }
h2 { font-size: clamp(26px, 6vw, 40px); }

.campaign-copy {
  max-width: 620px;
  margin: 8px 0 0;
  color: #ffe9b6;
  font-size: 14px;
  line-height: 1.45;
}

.language-row {
  display: grid;
  gap: 10px;
  margin: 0 auto 14px;
  max-width: 760px;
  text-align: center;
  justify-items: center;
}

.language-select {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #fff8dc;
  font-size: 12px;
  font-weight: 900;
}

.language-select select {
  min-height: 38px;
  border: 2px solid rgba(255, 201, 40, 0.85);
  border-radius: 8px;
  background: #fffdf9;
  color: var(--ink);
  padding: 0 14px;
  outline: 0;
}

.lucky-board {
  width: 100%;
  max-width: 500px;
  margin: 0 auto 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border-radius: 14px;
  position: relative;
  background: #d71927;
  box-shadow: inset 0 0 0 3px #ff5d35, 0 12px 24px rgba(82, 0, 8, 0.24);
}

.lucky-board::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 12px;
  pointer-events: none;
  background:
    radial-gradient(circle, #fff8b8 0 3px, transparent 4px) top 3px left 12px / 34px 8px repeat-x,
    radial-gradient(circle, #ffd22f 0 3px, transparent 4px) bottom 3px left 28px / 34px 8px repeat-x,
    radial-gradient(circle, #fff8b8 0 3px, transparent 4px) top 12px left 3px / 8px 34px repeat-y,
    radial-gradient(circle, #ffd22f 0 3px, transparent 4px) top 28px right 3px / 8px 34px repeat-y;
  animation: boardBulbs 1.7s ease-in-out infinite alternate;
  opacity: 0.78;
}

.lucky-board > * {
  position: relative;
  z-index: 1;
}

.prize-cell, .start-cell {
  min-width: 0;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid #ffd36c;
  display: grid;
  place-items: center;
  padding: 6px 4px;
}

.prize-cell {
  background: var(--cell);
  color: #411706;
  box-shadow: inset 0 -5px 0 rgba(255, 207, 116, 0.42), 0 2px 0 rgba(108, 10, 10, 0.18);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.prize-cell.is-active {
  transform: scale(1.045);
  border-color: #fff;
  box-shadow: 0 0 0 4px #ffe600, 0 0 18px rgba(255, 246, 0, 0.9);
}

.prize-cell.is-winning {
  animation: winningCellPulse 0.4s ease-in-out 3;
}

.prize-icon {
  display: block;
  font-size: clamp(26px, 8.5vw, 46px);
  line-height: 1;
}

.fridge-visual {
  width: clamp(28px, 8.4vw, 44px);
  height: clamp(38px, 11vw, 58px);
  display: block;
  position: relative;
  border: 2px solid #8f9aa5;
  border-radius: 6px 6px 5px 5px;
  background: linear-gradient(135deg, #f7f9fb 0%, #cfd6de 48%, #eef2f5 100%);
  box-shadow: inset -5px 0 10px rgba(72, 82, 92, 0.16), 0 2px 5px rgba(70, 24, 10, 0.18);
}

.fridge-visual::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 34%;
  border-top: 2px solid rgba(112, 124, 136, 0.7);
}

.fridge-visual::after {
  content: "";
  position: absolute;
  right: 7px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 999px;
  background: #7f8b96;
  box-shadow: 0 20px 0 #7f8b96;
}

.fridge-visual span {
  position: absolute;
  left: 7px;
  bottom: -5px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: #6d7781;
  box-shadow: 22px 0 0 #6d7781;
}

.prize-cell strong {
  width: 100%;
  color: #5b1c08;
  font-size: clamp(11px, 3.2vw, 16px);
  line-height: 1.12;
  overflow-wrap: anywhere;
  word-break: normal;
}

.start-cell {
  background: #fff9e9;
  box-shadow: inset 0 -5px 0 rgba(255, 207, 116, 0.42), 0 2px 0 rgba(108, 10, 10, 0.18);
}

.draw-orb {
  width: min(78%, 94px);
  aspect-ratio: 1;
  border: 3px solid #fff4a6;
  border-radius: 50%;
  color: var(--red-dark);
  background: radial-gradient(circle at 35% 24%, #fffbc2 0%, #ffd83f 42%, #ffad00 100%);
  box-shadow: inset 0 -8px 0 rgba(144, 61, 0, 0.22), 0 8px 0 #8f1e0b, 0 13px 18px rgba(91, 16, 6, 0.28);
  cursor: pointer;
  font-size: clamp(17px, 5vw, 25px);
  font-weight: 1000;
  line-height: 1;
  padding: 0;
}

.draw-orb:disabled {
  opacity: 1;
  color: #8f4a04;
  background: radial-gradient(circle at 35% 24%, #fff7b0 0%, #f5c932 46%, #dc9600 100%);
  box-shadow: inset 0 -5px 0 rgba(144, 61, 0, 0.18), 0 4px 0 #8f1e0b, 0 9px 14px rgba(91, 16, 6, 0.2);
}

.primary-cta, .redeem-button, .secondary-button, .chat-composer button {
  border: 0;
  border-radius: 8px;
  min-height: 52px;
  padding: 0 24px;
  cursor: pointer;
  font-weight: 900;
}

.primary-cta, .redeem-button, .chat-composer button {
  color: #fff;
  background: linear-gradient(135deg, var(--red), #e34b31);
  box-shadow: 0 14px 28px rgba(197, 31, 47, 0.24);
}

.secondary-button {
  color: var(--red-dark);
  background: #fff0d0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  box-shadow: none;
}

.draw-orb:disabled {
  box-shadow: inset 0 -5px 0 rgba(144, 61, 0, 0.18), 0 4px 0 #8f1e0b, 0 9px 14px rgba(91, 16, 6, 0.2);
}

.status-line, .redeem-error, .chat-status {
  min-height: 22px;
  color: #ffe8a4;
  font-size: 14px;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(36, 24, 18, 0.42);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.modal-backdrop[hidden] { display: none; }

.floating-support {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 15;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 28px);
  min-height: 44px;
  border: 2px solid #fff4a6;
  border-radius: 999px;
  padding: 0 13px;
  color: var(--red-dark);
  background: linear-gradient(135deg, #fffbc2 0%, #ffd83f 52%, #ffb000 100%);
  box-shadow: 0 8px 20px rgba(65, 0, 10, 0.24);
  cursor: pointer;
  font-weight: 1000;
}

.floating-support strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-modal {
  width: min(100%, 540px);
  background: #fffdf3;
  border-radius: 14px;
  border: 4px solid #ffcf32;
  padding: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.26);
  position: relative;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: #f8ede3;
  color: var(--ink);
  cursor: pointer;
  font-size: 24px;
}

.result-kicker {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 13px;
  font-weight: 900;
}

.result-subtitle {
  color: var(--ink);
  font-size: 17px;
  font-weight: 800;
}

.result-subtitle strong,
.result-card-usage {
  display: block;
}

.result-card-usage {
  margin: 6px auto 10px;
  color: #7b4a00;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.45;
}

.result-details {
  display: grid;
  gap: 10px;
  margin: 20px 0;
}

.result-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.value-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdf9;
  font-weight: 800;
  text-align: left;
}

.value-row.payable {
  background: #fff0f1;
  border-color: rgba(197, 31, 47, 0.24);
  color: var(--red-dark);
}

.value-row.free {
  background: #effaf4;
  border-color: rgba(18, 128, 92, 0.22);
  color: var(--green);
}

.redemption-info {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(227, 26, 47, 0.24);
  border-left: 5px solid var(--red);
  border-radius: 10px;
  padding: 12px;
  background: linear-gradient(135deg, #fff8cf 0%, #ffeceb 100%);
  color: #5b1c08;
  text-align: left;
}

.redemption-info h3 {
  margin: 0;
  color: var(--red-dark);
  font-size: 16px;
  line-height: 1.2;
}

.redemption-info p {
  margin: 0;
  color: #5b1c08;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.55;
}

.redemption-info strong {
  color: var(--red-dark);
  font-size: 15px;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.history-modal {
  max-height: min(720px, calc(100vh - 36px));
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.history-list {
  min-height: 90px;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  margin-top: 16px;
  text-align: left;
}

.history-empty {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fffaf4;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.history-record {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffaf4;
}

.history-record-title {
  display: grid;
  gap: 4px;
}

.history-record-title strong {
  color: var(--red-dark);
  font-size: 16px;
  line-height: 1.25;
}

.history-record-title span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.history-values {
  display: grid;
  gap: 6px;
}

.history-values div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.history-values strong {
  color: var(--ink);
  text-align: right;
  overflow-wrap: anywhere;
}

.history-redeem-button {
  width: 100%;
  min-height: 44px;
}

.chat-panel {
  min-height: min(760px, calc(100vh - 36px));
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.chat-header h1 { font-size: clamp(22px, 5vw, 34px); }

.text-link {
  color: var(--red);
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
}

.support-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.summary-pill {
  border-radius: 999px;
  background: #fff2dd;
  color: #8f4a04;
  font-size: 13px;
  font-weight: 800;
  padding: 7px 10px;
}

.chat-status {
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  background: #fffaf4;
}

.message {
  width: fit-content;
  max-width: min(78%, 520px);
  margin: 0 0 12px;
  border-radius: 16px;
  padding: 10px 12px;
  line-height: 1.55;
  word-break: break-word;
}

.message.customer {
  margin-left: auto;
  color: #fff;
  background: var(--red);
}

.message.agent, .message.system {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.message small {
  display: block;
  margin-top: 5px;
  opacity: 0.72;
  font-size: 12px;
}

.message img {
  display: block;
  max-width: 220px;
  border-radius: 12px;
}

.chat-composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.chat-composer textarea {
  resize: none;
  min-height: 50px;
  max-height: 120px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  outline: 0;
}

.image-input {
  display: grid;
  place-items: center;
  min-width: 56px;
  min-height: 50px;
  border-radius: 16px;
  background: #fff2dd;
  color: #8f4a04;
  font-weight: 900;
  cursor: pointer;
}

.image-input input { display: none; }

@media (min-width: 720px) {
  .page-shell { padding: 24px; }
  .reward-card { padding: 22px; }
  .lucky-board { gap: 10px; padding: 10px; }
}

@media (max-width: 520px) {
  .page-shell, .chat-shell { padding: 10px; }
  .reward-card { padding: 12px 8px; border-width: 4px; }
  .top-actions { justify-content: center; }
  .lucky-board { gap: 6px; padding: 6px; }
  .prize-cell, .start-cell { padding: 5px 3px; }
  .result-modal { padding: 20px 14px; }
  .result-actions { grid-template-columns: 1fr; }
  .floating-support {
    right: 10px;
    bottom: 10px;
    max-width: 180px;
    font-size: 13px;
  }
  .chat-composer { grid-template-columns: auto 1fr; }
  .chat-composer button { grid-column: 1 / -1; }
}

@keyframes boardBulbs {
  from {
    opacity: 0.55;
    filter: drop-shadow(0 0 1px rgba(255, 246, 166, 0.2));
  }
  to {
    opacity: 0.95;
    filter: drop-shadow(0 0 5px rgba(255, 238, 102, 0.72));
  }
}

@keyframes winningCellPulse {
  0%, 100% {
    transform: scale(1.045);
    box-shadow: 0 0 0 4px #ffe600, 0 0 16px rgba(255, 246, 0, 0.82);
  }
  50% {
    transform: scale(1.09);
    box-shadow: 0 0 0 6px #fff, 0 0 26px rgba(255, 41, 41, 0.9);
  }
}
