.hapc-chat {
  --hapc-border: #d8dee7;
  --hapc-text: #18212f;
  --hapc-muted: #687386;
  --hapc-user: #0b6f63;
  --hapc-panel: #f5f7fa;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 780px;
  min-height: 560px;
  overflow: hidden;
  border: 1px solid var(--hapc-border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--hapc-text);
  font-family: Arial, Helvetica, sans-serif;
}

.hapc-embed-body {
  margin: 0;
  padding: 0;
  background: #ffffff;
}

.hapc-embed-body .hapc-chat {
  width: 100vw;
  max-width: none;
  min-height: 100vh;
  border: 0;
  border-radius: 0;
}

.hapc-chat *,
.hapc-chat *::before,
.hapc-chat *::after {
  box-sizing: border-box;
}

.hapc-chat__header {
  display: flex;
  align-items: center;
  min-height: 70px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--hapc-border);
  background: #fbfcfe;
}

.hapc-chat__title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.hapc-chat__subtitle {
  margin-top: 3px;
  color: var(--hapc-muted);
  font-size: 13px;
  line-height: 1.35;
}

.hapc-chat__messages {
  flex: 1;
  min-height: 330px;
  max-height: 560px;
  overflow-y: auto;
  padding: 16px;
  background: #ffffff;
}

.hapc-embed-body .hapc-chat__messages {
  max-height: none;
}

.hapc-message {
  width: fit-content;
  max-width: min(88%, 660px);
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.hapc-message--assistant {
  margin-right: auto;
  border: 1px solid #e4e9f0;
  background: var(--hapc-panel);
}

.hapc-message--user {
  margin-left: auto;
  background: var(--hapc-user);
  color: #ffffff;
}

.hapc-chat__form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--hapc-border);
  background: #fbfcfe;
}

.hapc-chat__input {
  width: 100%;
  min-height: 54px;
  max-height: 170px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--hapc-border);
  border-radius: 6px;
  color: var(--hapc-text);
  font: inherit;
  line-height: 1.45;
}

.hapc-chat__send {
  min-width: 78px;
  height: 54px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: #17202f;
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
}

.hapc-chat__send:disabled,
.hapc-chat__input:disabled {
  opacity: 0.65;
  cursor: wait;
}

.hapc-chat__status {
  min-height: 28px;
  padding: 0 14px 10px;
  background: #fbfcfe;
  color: var(--hapc-muted);
  font-size: 13px;
}

.hapc-sim {
  border-top: 1px solid var(--hapc-border);
  background: #f8fafc;
  padding: 12px 14px;
}

.hapc-sim__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.hapc-sim__title {
  color: var(--hapc-text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}

.hapc-sim__sub {
  margin-top: 2px;
  color: var(--hapc-muted);
  font-size: 12px;
}

.hapc-sim__time {
  min-width: 58px;
  padding: 5px 8px;
  border: 1px solid #d7dee8;
  border-radius: 6px;
  background: #ffffff;
  color: #111827;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.hapc-sim__step {
  min-height: 28px;
  margin: -2px 0 10px;
  padding: 6px 8px;
  border: 1px solid #d7dee8;
  border-radius: 6px;
  background: #ffffff;
  color: #17202f;
  font-size: 12px;
  line-height: 1.35;
}

.hapc-sim__controls {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

.hapc-sim__controls label {
  color: var(--hapc-muted);
  font-size: 12px;
  line-height: 1.35;
}

.hapc-sim__controls input {
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  border: 1px solid #d7dee8;
  border-radius: 6px;
  background: #ffffff;
  color: var(--hapc-text);
  font: inherit;
}

.hapc-sim__play,
.hapc-sim__reset {
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.hapc-sim__play {
  background: #0b6f63;
  color: #ffffff;
}

.hapc-sim__reset {
  border: 1px solid #d7dee8;
  background: #ffffff;
  color: #17202f;
}

.hapc-sim__relays {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.hapc-sim__relays--circuit {
  grid-template-columns: 1fr;
}

.hapc-sim__relays--board {
  display: block;
}

.hapc-sim__relays--photo {
  display: block;
}

.hapc-photo-board {
  position: relative;
  width: min(100%, 620px);
  margin: 6px auto 12px;
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.hapc-photo-board__image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.hapc-photo-board__missing {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  color: var(--hapc-muted);
  background: #f8fafc;
  font-size: 13px;
}

.hapc-sim__relay.hapc-photo-led {
  position: absolute;
  display: block;
  min-height: 0;
  padding: 0;
  gap: 0;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 50%;
  background: rgba(30, 41, 59, 0.08);
  box-shadow: 0 0 0 1px rgba(80, 80, 80, 0.28);
  z-index: 6;
  pointer-events: none;
}

.hapc-photo-led span {
  position: absolute;
  inset: 24%;
  border-radius: 50%;
  background: rgba(30, 41, 59, 0.22);
}

.hapc-photo-led .hapc-circuit-state,
.hapc-photo-led small {
  display: none;
}

.hapc-sim__relay.hapc-photo-led.is-on {
  border-color: #ffffff;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.92) 0 12%, rgba(255, 224, 74, 0.7) 20%, rgba(255, 0, 0, 0.42) 54%, rgba(255, 0, 0, 0.18) 100%);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 1),
    0 0 8px rgba(255, 255, 255, 0.98),
    0 0 18px rgba(255, 230, 80, 0.98),
    0 0 34px rgba(255, 35, 0, 0.98),
    0 0 62px rgba(255, 0, 0, 0.9),
    0 0 92px rgba(255, 145, 0, 0.58);
}

.hapc-photo-led.is-on span {
  inset: 10%;
  background: radial-gradient(circle, #ffffff 0 18%, #fff36d 28%, #ff2a2a 62%, #b90000 100%);
  box-shadow:
    0 0 8px rgba(255, 255, 255, 1),
    0 0 18px rgba(255, 238, 70, 1),
    0 0 34px rgba(255, 42, 42, 0.98);
}

.hapc-board {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 1.08;
  margin: 6px auto 12px;
  border-radius: 7px;
  background:
    radial-gradient(circle at 9% 9%, #d7e7ff 0 2px, transparent 3px),
    radial-gradient(circle at 91% 9%, #d7e7ff 0 2px, transparent 3px),
    radial-gradient(circle at 9% 91%, #d7e7ff 0 2px, transparent 3px),
    radial-gradient(circle at 91% 91%, #d7e7ff 0 2px, transparent 3px),
    linear-gradient(135deg, #126cc7 0%, #0c57ac 55%, #0a4594 100%);
  box-shadow: 0 18px 30px rgba(15, 23, 42, 0.22);
  transform: perspective(850px) rotateX(52deg) rotateZ(-18deg);
  transform-origin: center;
  overflow: visible;
  transform-style: preserve-3d;
}

.hapc-board::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(205, 231, 255, 0.38);
  border-radius: 5px;
  pointer-events: none;
}

.hapc-board::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 18px, rgba(255,255,255,0.08) 19px, transparent 20px),
    repeating-linear-gradient(0deg, transparent 0 22px, rgba(255,255,255,0.06) 23px, transparent 24px);
  opacity: 0.42;
  pointer-events: none;
}

.hapc-board__silk,
.hapc-board__terminal,
.hapc-board__relay,
.hapc-board__chip,
.hapc-board__header,
.hapc-board__cap,
.hapc-board__parts,
.hapc-board__trace {
  transform-style: preserve-3d;
}

.hapc-board > * {
  transform: translateZ(8px);
}

.hapc-board::before {
  transform: translateZ(2px);
}

.hapc-board__silk {
  position: absolute;
  color: rgba(226, 244, 255, 0.86);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  z-index: 2;
}

.hapc-board__silk--title {
  left: 39%;
  bottom: 8%;
}

.hapc-board__terminal {
  position: absolute;
  display: grid;
  gap: 5px;
  z-index: 5;
}

.hapc-board__terminal span {
  display: block;
  position: relative;
  width: 30px;
  height: 28px;
  border: 2px solid #0573c5;
  border-radius: 4px;
  background: linear-gradient(145deg, #48baff, #1194e8 70%, #0877ca);
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.42), 0 8px 0 #0567ad, 0 14px 12px rgba(0,0,0,0.28);
  transform: translateZ(24px);
}

.hapc-board__terminal span::after {
  content: "";
  position: absolute;
  top: 8px;
  left: 9px;
  width: 9px;
  height: 9px;
  border: 2px solid rgba(3, 63, 112, 0.72);
  border-radius: 50%;
  background: #d8f3ff;
}

.hapc-board__terminal--left {
  left: 5%;
  bottom: 14%;
  grid-template-columns: 1fr;
}

.hapc-board__terminal--right {
  right: 4%;
  top: 9%;
  grid-template-columns: 1fr;
}

.hapc-board__terminal--top {
  left: 25%;
  top: 4%;
  grid-template-columns: repeat(4, 1fr);
}

.hapc-board__relay {
  position: absolute;
  right: 15%;
  width: 34%;
  height: 16%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  column-gap: 7px;
  padding: 7px 8px;
  border: 2px solid #096eb8;
  border-radius: 6px;
  background: linear-gradient(145deg, #3bb7fa, #128dda 62%, #0b70bc);
  color: #e7f7ff;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.36), 0 12px 0 #075f9e, 0 20px 16px rgba(0,0,0,0.32);
  transform: translateZ(32px);
  z-index: 7;
}

.hapc-board__relay--1 { top: 8%; }
.hapc-board__relay--2 { top: 27%; }
.hapc-board__relay--3 { top: 46%; }
.hapc-board__relay--4 { top: 65%; }

.hapc-board__relay strong {
  grid-column: 2;
  font-size: 10px;
  color: #f0fbff;
  line-height: 1.1;
}

.hapc-board__relay small {
  grid-column: 2;
  color: rgba(232, 248, 255, 0.9);
  font-size: 9px;
}

.hapc-board__relay .hapc-circuit-state {
  grid-column: 3;
  grid-row: 1 / span 2;
  min-width: 30px;
  padding: 3px 4px;
  border-radius: 4px;
  background: rgba(0, 64, 111, 0.38);
  color: #e4f5ff;
  font-size: 10px;
}

.hapc-board__relay-led {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #b8c8d6;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
}

.hapc-board__relay.is-on {
  border-color: #7dd3fc;
  filter: saturate(1.18) brightness(1.08);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.42), 0 12px 0 #075f9e, 0 0 0 3px rgba(16,185,129,0.22), 0 22px 18px rgba(0,0,0,0.34);
}

.hapc-board__relay.is-on .hapc-board__relay-led {
  background: #39ff8a;
  box-shadow: 0 0 0 4px rgba(57,255,138,0.18), 0 0 12px rgba(57,255,138,0.82);
}

.hapc-board__relay.is-on .hapc-circuit-state {
  background: #10b981;
  color: #ffffff;
}

.hapc-board__chip,
.hapc-board__header,
.hapc-board__cap,
.hapc-board__parts,
.hapc-board__trace {
  position: absolute;
  z-index: 4;
}

.hapc-board__chip {
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: #202a38;
  color: #dbeafe;
  font-size: 9px;
  font-weight: 700;
  box-shadow: 0 5px 0 #111827, 0 11px 10px rgba(0,0,0,0.32);
  transform: translateZ(18px);
}

.hapc-board__chip--stm {
  left: 33%;
  top: 44%;
  width: 17%;
  height: 13%;
  transform: rotate(90deg);
}

.hapc-board__chip--rf {
  left: 22%;
  top: 26%;
  width: 20%;
  height: 10%;
}

.hapc-board__header {
  left: 18%;
  bottom: 13%;
  display: grid;
  grid-template-columns: repeat(4, 9px);
  gap: 5px;
}

.hapc-board__header span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #c6d6e6;
  box-shadow: inset 0 0 0 2px #7f97ad, 0 5px 0 #5f748a;
  transform: translateZ(14px);
}

.hapc-board__cap {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f9fafb, #9aa4af 38%, #263241 70%);
  box-shadow: 0 9px 0 #4b5563, 0 15px 12px rgba(0,0,0,0.28);
  transform: translateZ(22px);
}

.hapc-board__cap--1 {
  left: 37%;
  bottom: 15%;
}

.hapc-board__cap--2 {
  left: 47%;
  bottom: 16%;
}

.hapc-board__parts {
  width: 25%;
  height: 18%;
  background:
    linear-gradient(90deg, #d9e2ea 0 9%, transparent 9% 18%, #17202f 18% 33%, transparent 33% 44%, #d9e2ea 44% 53%, transparent 53% 62%, #17202f 62% 77%, transparent 77% 100%),
    linear-gradient(#cbd5e1, #cbd5e1);
  opacity: 0.9;
  box-shadow: 0 4px 0 rgba(15, 23, 42, 0.35);
  transform: translateZ(12px);
}

.hapc-board__parts--1 {
  left: 21%;
  top: 41%;
}

.hapc-board__parts--2 {
  left: 21%;
  top: 54%;
}

.hapc-board__trace {
  left: 49%;
  width: 28%;
  height: 2px;
  background: rgba(172, 225, 255, 0.72);
  transform-origin: left center;
}

.hapc-board__trace--1 { top: 16%; }
.hapc-board__trace--2 { top: 35%; }
.hapc-board__trace--3 { top: 54%; }
.hapc-board__trace--4 { top: 73%; }

.hapc-circuit-overview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr) 24px minmax(0, 1.25fr);
  gap: 8px;
  align-items: stretch;
  margin-bottom: 2px;
}

.hapc-circuit-chip {
  min-height: 56px;
  padding: 9px 10px;
  border: 1px solid #cfd8e3;
  border-radius: 6px;
  background: #ffffff;
}

.hapc-circuit-chip--main {
  border-color: #0b6f63;
  background: #f0fdfa;
}

.hapc-circuit-chip span,
.hapc-circuit-chip small {
  display: block;
  color: var(--hapc-muted);
  font-size: 11px;
  line-height: 1.25;
}

.hapc-circuit-chip strong {
  display: block;
  margin: 3px 0;
  color: #17202f;
  font-size: 13px;
  line-height: 1.25;
}

.hapc-circuit-arrow {
  position: relative;
  min-height: 56px;
}

.hapc-circuit-arrow::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 4px;
  height: 2px;
  background: #94a3b8;
}

.hapc-circuit-arrow::after {
  content: "";
  position: absolute;
  top: calc(50% - 5px);
  right: 0;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid #94a3b8;
}

.hapc-sim__relay {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px;
  border: 1px solid #d7dee8;
  border-radius: 6px;
  background: #ffffff;
  color: #233044;
  font-size: 12px;
}

.hapc-sim__relays--circuit .hapc-sim__relay {
  grid-template-columns: 1fr 1fr 1.2fr 1.2fr auto;
  min-height: 54px;
  gap: 8px;
}

.hapc-circuit-control,
.hapc-circuit-driver,
.hapc-circuit-coil,
.hapc-circuit-contact {
  min-height: 38px;
  padding: 7px 8px;
  border: 1px solid #d7dee8;
  border-radius: 6px;
  background: #ffffff;
}

.hapc-circuit-control {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 7px;
  align-items: center;
}

.hapc-circuit-control small {
  grid-column: 2;
}

.hapc-circuit-driver span,
.hapc-circuit-coil span,
.hapc-circuit-contact span,
.hapc-circuit-contact b,
.hapc-circuit-control strong {
  display: block;
  color: #17202f;
  font-size: 12px;
  line-height: 1.25;
}

.hapc-circuit-driver small,
.hapc-circuit-coil small,
.hapc-circuit-control small {
  display: block;
  color: var(--hapc-muted);
  font-size: 11px;
  line-height: 1.25;
}

.hapc-circuit-contact {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  align-items: center;
  text-align: center;
}

.hapc-circuit-contact b {
  padding: 3px 4px;
  border-radius: 4px;
  background: #eef2f7;
  font-weight: 700;
}

.hapc-sim__relays--circuit .hapc-sim__relay.is-on .hapc-circuit-driver,
.hapc-sim__relays--circuit .hapc-sim__relay.is-on .hapc-circuit-coil {
  border-color: #0b6f63;
  background: #ecfdf7;
}

.hapc-sim__relays--circuit .hapc-sim__relay.is-on .hapc-circuit-contact b:last-child {
  background: #10b981;
  color: #ffffff;
}

.hapc-sim__relays--circuit .hapc-sim__relay:not(.is-on) .hapc-circuit-contact b:nth-child(2) {
  background: #94a3b8;
  color: #ffffff;
}

.hapc-circuit-state {
  align-self: center;
  min-width: 38px;
  text-align: center;
}

.hapc-sim__relay strong {
  color: #718096;
  font-size: 11px;
}

.hapc-sim__relay.is-on {
  border-color: #0b6f63;
  background: #ecfdf7;
}

.hapc-sim__relay.is-on strong {
  color: #0b6f63;
}

.hapc-sim__lamp {
  display: block;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: #cbd5e1;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.hapc-sim__relay.is-on .hapc-sim__lamp {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.14);
}

.hapc-sim__note {
  margin-top: 8px;
  color: var(--hapc-muted);
  font-size: 12px;
  line-height: 1.45;
}

.hapc-board .hapc-board__relay {
  position: absolute;
  right: 15%;
  width: 34%;
  height: 16%;
  min-height: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  gap: 0 7px;
  padding: 7px 8px;
  border: 2px solid #096eb8;
  border-radius: 6px;
  background: linear-gradient(145deg, #3bb7fa, #128dda 62%, #0b70bc);
  color: #e7f7ff;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.36), 0 12px 0 #075f9e, 0 20px 16px rgba(0,0,0,0.32);
  transform: translateZ(32px);
}

.hapc-board .hapc-board__relay--1 { top: 8%; }
.hapc-board .hapc-board__relay--2 { top: 27%; }
.hapc-board .hapc-board__relay--3 { top: 46%; }
.hapc-board .hapc-board__relay--4 { top: 65%; }

.hapc-board .hapc-board__relay strong {
  grid-column: 2;
  color: #f0fbff;
  font-size: 10px;
  line-height: 1.1;
}

.hapc-board .hapc-board__relay small {
  grid-column: 2;
  color: rgba(232, 248, 255, 0.9);
  font-size: 9px;
  line-height: 1.1;
}

.hapc-board .hapc-circuit-state {
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
  min-width: 30px;
  padding: 3px 4px;
  border-radius: 4px;
  background: rgba(0, 64, 111, 0.38);
  color: #e4f5ff;
  font-size: 10px;
  text-align: center;
}

.hapc-error {
  padding: 12px;
  border: 1px solid #dc2626;
  border-radius: 6px;
  color: #991b1b;
  background: #fff5f5;
}

@media (max-width: 520px) {
  .hapc-chat {
    min-height: 580px;
  }

  .hapc-chat__form {
    grid-template-columns: 1fr;
  }

  .hapc-chat__send {
    width: 100%;
  }

  .hapc-sim__controls {
    grid-template-columns: 1fr 1fr;
  }

  .hapc-sim__play,
  .hapc-sim__reset {
    width: 100%;
  }

  .hapc-sim__relays {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hapc-sim__relays--circuit,
  .hapc-sim__relays--circuit .hapc-sim__relay,
  .hapc-circuit-overview {
    grid-template-columns: 1fr;
  }

  .hapc-circuit-arrow {
    display: none;
  }
}
