:root {
  color-scheme: dark;
  --bg: #111111;
  --surface: #171717;
  --surface-raised: #1d1d1d;
  --surface-input: #0d0d0d;
  --border: #333333;
  --border-soft: #262626;
  --text: #f2f2f2;
  --muted: #a1a1a1;
  --accent: #bd1e23;
  --accent-hover: #d1282e;
  --display: "Chakra Petch", "Segoe UI", sans-serif;
  --body: "Mulish", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
}

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

button, select, input[type="range"] { cursor: pointer; }

.page-shell { min-height: 100vh; }

.topbar {
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 4vw, 64px);
  background: #141414;
  border-bottom: 1px solid var(--border-soft);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--accent);
  font: 700 21px/1 var(--display);
  clip-path: polygon(0 0, 78% 0, 100% 22%, 100% 100%, 22% 100%, 0 78%);
}

.brand strong,
.brand small { display: block; }

.brand strong {
  font: 700 18px/1 var(--display);
  letter-spacing: .08em;
}

.brand small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.system-status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #c8c8c8;
  font-size: 13px;
  font-weight: 700;
}

.topbar-actions { display: flex; align-items: center; gap: clamp(18px, 3vw, 40px); }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  border-bottom: 2px solid transparent;
  color: #8f8f8f;
  font: 700 11px/1 var(--display);
  letter-spacing: .06em;
  text-decoration: none;
  text-transform: uppercase;
}
.topnav a:hover { color: #fff; }
.topnav a.active { border-bottom-color: var(--accent); color: #fff; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #49b675;
  box-shadow: 0 0 0 4px rgba(73, 182, 117, .12);
}

.workspace {
  min-height: calc(100vh - 82px);
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(400px, .75fr);
}

.robot-panel {
  position: relative;
  min-height: 650px;
  overflow: hidden;
  isolation: isolate;
  background: #151515 url("assets/workshop.png") center center / cover no-repeat;
  border-right: 1px solid var(--border-soft);
}

.robot-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: rgba(8, 8, 8, var(--stage-shade, .28));
}

.robot-panel::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 38%;
  z-index: 0;
  background: linear-gradient(180deg, rgba(17, 17, 17, 0), rgba(17, 17, 17, .82));
  pointer-events: none;
}

.robot-kicker {
  position: absolute;
  top: 28px;
  left: clamp(20px, 4vw, 54px);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #d7d7d7;
  font: 700 11px/1 var(--display);
  letter-spacing: .09em;
  text-transform: uppercase;
}

.robot-kicker span { width: 22px; height: 2px; background: var(--accent); }

#robotFrame {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
}

.robot-floor {
  position: absolute;
  left: 50%;
  bottom: 10%;
  z-index: 0;
  width: min(36vw, 460px);
  height: 42px;
  transform: translateX(-50%);
  border: 1px solid rgba(189, 30, 35, .55);
  border-radius: 50%;
  background: rgba(189, 30, 35, .08);
}

.speech-bubble {
  position: absolute;
  top: 24%;
  right: 0;
  z-index: 4;
  width: min(300px, 40%);
  min-height: 138px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 22px;
  background: rgba(13, 13, 13, .94);
  border: 1px solid #404040;
  border-top: 2px solid var(--accent);
  transition: border-color 160ms ease, background 160ms ease;
}

.speech-bubble::after { display: none; }

.speech-bubble.speaking { border-color: #5a3436; border-top-color: var(--accent-hover); background: rgba(16, 16, 16, .97); }

.bubble-name {
  display: block;
  margin-bottom: 7px;
  color: #df5257;
  font: 700 11px/1 var(--display);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.speech-bubble p { margin: 0; color: #e8e8e8; font-size: 15px; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.speech-bubble.speaking p::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -.12em;
  background: var(--accent);
  animation: type-caret .7s steps(1, end) infinite;
}

@keyframes type-caret { 50% { opacity: 0; } }

.graphic-actions {
  position: absolute;
  left: 50%;
  bottom: 28px;
  z-index: 5;
  display: flex;
  gap: 10px;
  transform: translateX(-50%);
}

.graphic-action-button {
  min-width: 180px;
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid #f04a50;
  background: rgba(189, 30, 35, .94);
  color: #fff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
  font: 700 13px/1 var(--display);
  letter-spacing: .04em;
  text-transform: uppercase;
  transition: background 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.graphic-action-button:hover:not(:disabled) { background: var(--accent-hover); border-color: #ff666b; }
.graphic-action-button:disabled { opacity: .45; cursor: not-allowed; }
.graphic-action-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.graphic-listen-button { border-color: #686868; background: rgba(20, 20, 20, .94); }
.graphic-listen-button:hover:not(:disabled) { border-color: #f04a50; background: rgba(35, 35, 35, .97); }
.graphic-listen-button.listening { border-color: #f04a50; background: var(--accent); animation: listening-pulse 1s ease-in-out infinite alternate; }

@keyframes listening-pulse { from { box-shadow: 0 0 0 0 rgba(209, 40, 46, .15); } to { box-shadow: 0 0 0 8px rgba(209, 40, 46, 0); } }

.control-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(36px, 4vw, 64px);
  background: var(--surface);
}

.eyebrow {
  margin-bottom: 14px;
  color: #df5257;
  font: 700 12px/1 var(--display);
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1 {
  max-width: 540px;
  margin: 0;
  font: 700 clamp(32px, 4.2vw, 55px)/.98 var(--display);
  letter-spacing: -.035em;
  text-transform: uppercase;
}

.intro { max-width: 560px; margin: 20px 0 32px; color: var(--muted); font-size: 15px; line-height: 1.65; }

form > label,
.field label {
  display: block;
  margin-bottom: 9px;
  color: #dcdcdc;
  font: 700 12px/1 var(--display);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.textarea-wrap { position: relative; }

textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0;
  outline: none;
  background: var(--surface-input);
  color: var(--text);
  transition: border-color 140ms ease;
}

textarea {
  min-height: 150px;
  resize: vertical;
  padding: 16px 17px 36px;
  font-size: 16px;
  line-height: 1.55;
}

textarea:focus,
select:focus { border-color: var(--accent); }

#characterCount {
  position: absolute;
  right: 13px;
  bottom: 12px;
  color: #737373;
  font-size: 11px;
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 21px 18px;
  margin-top: 22px;
}

.field-wide { grid-column: 1 / -1; }

select { height: 47px; padding: 0 40px 0 13px; }

.field small { display: block; margin-top: 7px; color: #777; font-size: 11px; }

.range-label { display: flex; align-items: center; justify-content: space-between; }

.range-label output { color: #df5257; font: 700 12px/1 var(--display); }

input[type="range"] {
  width: 100%;
  height: 4px;
  margin: 9px 0;
  appearance: none;
  background: #3a3a3a;
  accent-color: var(--accent);
}

input[type="range"]::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
  appearance: none;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.save-settings-button {
  width: 100%;
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 22px;
  border: 1px solid #474747;
  background: #202020;
  color: #e5e5e5;
  font: 700 12px/1 var(--display);
  letter-spacing: .04em;
  text-transform: uppercase;
  transition: border-color 140ms ease, background 140ms ease;
}

.save-settings-button:hover { border-color: var(--accent); background: #252525; }
.save-settings-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }

.actions { display: flex; gap: 11px; margin-top: 30px; }

.actions button {
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid transparent;
  padding: 0 20px;
  font: 700 13px/1 var(--display);
  letter-spacing: .035em;
  text-transform: uppercase;
}

.actions svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.primary-button { flex: 1; background: var(--accent); color: white; }
.primary-button:hover { background: var(--accent-hover); }
.secondary-button { background: transparent; border-color: var(--border) !important; color: #d5d5d5; }
.secondary-button:hover:not(:disabled) { border-color: #666 !important; }
.secondary-button:disabled { opacity: .42; cursor: not-allowed; }

.live-status {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  padding: 12px 15px;
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
}

.live-status > span:last-child { min-width: 0; }
.live-status strong, .live-status small { display: block; }
.live-status strong { font: 700 12px/1 var(--display); letter-spacing: .05em; text-transform: uppercase; }
.live-status small { margin-top: 5px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.live-icon { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; gap: 3px; background: #242424; }
.live-icon i { width: 2px; height: 7px; background: #767676; }
.live-status.speaking .live-icon i { background: #df5257; animation: equalize .65s ease-in-out infinite alternate; }
.live-status.speaking .live-icon i:nth-child(2) { animation-delay: -.22s; }
.live-status.speaking .live-icon i:nth-child(3) { animation-delay: -.44s; }
.live-status.listening .live-icon i { background: #df5257; animation: equalize .42s ease-in-out infinite alternate; }
.live-status.listening .live-icon i:nth-child(2) { animation-delay: -.14s; }
.live-status.listening .live-icon i:nth-child(3) { animation-delay: -.28s; }

@keyframes equalize { from { height: 5px; } to { height: 19px; } }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .robot-panel { min-height: 520px; border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .control-panel { padding: 54px clamp(20px, 8vw, 72px) 70px; }
  .speech-bubble { top: 24%; right: 0; width: 280px; min-height: 128px; }
}

@media (max-width: 560px) {
  .topbar { height: 72px; padding: 0 18px; }
  .system-status span:last-child { display: none; }
  .topbar-actions { gap: 8px; }
  .topnav a { padding: 0 8px; font-size: 10px; }
  .workspace { min-height: calc(100vh - 72px); }
  .robot-panel { min-height: 430px; }
  .speech-bubble { top: 58px; right: 0; width: 220px; min-height: 112px; padding: 15px 16px; }
  .speech-bubble p { font-size: 14px; }
  .graphic-actions { bottom: 14px; width: calc(100% - 28px); gap: 8px; }
  .graphic-action-button { min-width: 0; min-height: 46px; flex: 1; padding: 0 10px; font-size: 11px; }
  .control-panel { padding: 42px 18px 52px; }
  h1 { font-size: 35px; }
  .field-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .actions { flex-direction: column; }
  .actions button { width: 100%; }
}

body.reduced-motion *,
body.reduced-motion *::before,
body.reduced-motion *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
