:root {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #172033;
  --line: #263347;
  --text: #eef4ff;
  --muted: #8ea0b8;
  --accent: #20d4a8;
  --blue: #2f80ed;
  --danger: #ef4444;
  --radius: 8px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(32, 212, 168, 0.11), transparent 32%),
    linear-gradient(315deg, rgba(47, 128, 237, 0.16), transparent 38%),
    var(--bg);
  color: var(--text);
}

body.auth-locked {
  overflow: hidden;
}

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

button, select, input, textarea {
  border-radius: var(--radius);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 72px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 17, 32, 0.86);
  backdrop-filter: blur(18px);
}

.brand, .top-actions, .transport, .background-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 230px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: #04111d;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

h1, h2, p {
  margin: 0;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 10, 20, 0.9);
  backdrop-filter: blur(12px);
}

.auth-gate[hidden] {
  display: none;
}

.auth-card {
  width: min(100%, 420px);
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  box-shadow: var(--shadow);
}

.auth-card .brand-mark {
  width: 52px;
  height: 52px;
}

.auth-card h2 {
  font-size: 24px;
  line-height: 1.1;
}

.auth-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.auth-card .btn {
  margin-top: 4px;
  min-height: 44px;
}

.auth-help-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  text-align: center;
}

.auth-register-link {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.auth-register-link:hover {
  text-decoration: underline;
}

.inline-status {
  min-height: 18px;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.15;
  font-weight: 800;
}

.brand p, .panel-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.top-actions {
  gap: 10px;
}

select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0f172a;
  color: var(--text);
  outline: none;
}

select, input {
  height: 38px;
  padding: 0 11px;
  font-size: 13px;
}

textarea {
  min-height: 86px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.4;
  font-size: 13px;
}

.msg-text {
  min-height: 72px;
  padding: 10px 11px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f172a;
  color: var(--text);
  outline: none;
  font-size: 13px;
}

select:focus, input:focus, textarea:focus, .msg-text:focus {
  border-color: color-mix(in srgb, var(--accent), white 10%);
  box-shadow: 0 0 0 3px rgba(32, 212, 168, 0.14);
}

.btn, .icon-btn {
  border: 0;
  cursor: pointer;
  min-height: 38px;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn {
  padding: 0 14px;
  font-size: 13px;
  font-weight: 800;
}

.btn:hover, .icon-btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--accent);
  color: #03110e;
}

.btn.secondary {
  border: 1px solid var(--line);
  background: #182235;
  color: var(--text);
}

.btn.ghost {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(420px, 1fr) minmax(280px, 340px);
  gap: 16px;
  padding: 16px;
}

.panel, .preview-stage {
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--line);
  background: rgba(17, 24, 39, 0.88);
  box-shadow: var(--shadow);
}

.panel {
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 15px;
  line-height: 1.2;
  font-weight: 850;
}

.icon-btn {
  width: 34px;
  height: 34px;
  background: var(--accent);
  color: #03110e;
  font-size: 22px;
  font-weight: 700;
}

.speaker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.profile-upload {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.profile-upload .btn {
  min-height: 34px;
}

label, .control-group > label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.message-list {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.message-item {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: 78px 1fr 30px;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #0f172a;
  margin-bottom: 9px;
}

.message-item:focus-within {
  border-color: rgba(32, 212, 168, 0.38);
}

.message-item .side {
  height: 36px;
  padding: 0 8px;
}

.message-item .msg-text {
  min-width: 0;
}

.message-content {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.message-image-tools {
  display: flex;
  gap: 8px;
}

.message-image-tools .btn {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.message-image-tools .remove-image {
  display: none;
}

.message-image-tools .remove-image.visible {
  display: inline-flex;
  align-items: center;
}

.message-image-preview img {
  display: block;
  width: 100%;
  max-height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.message-image-preview span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.message-item .delete {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.preview-stage {
  border-radius: 14px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 58px;
  padding: 14px;
}

.canvas-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 11px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.07), transparent),
    #070b14;
}

#previewCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
}

.preview-stage[data-format="vertical"] #previewCanvas,
.preview-stage[data-format="square"] #previewCanvas {
  width: auto;
  height: 100%;
}

.preview-stage[data-format="landscape"] #previewCanvas {
  width: 100%;
  height: auto;
}

.transport {
  gap: 12px;
  padding: 12px 4px 0;
}

.progress-track {
  position: relative;
  flex: 1;
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #0f172a;
}

#progressFill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--blue));
}

#timeReadout {
  width: 42px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.settings-panel {
  padding-bottom: 4px;
  overflow: auto;
}

.settings-panel .control-group,
.settings-panel .control-row {
  margin: 14px 16px 0;
}

.ai-tools {
  padding-bottom: 2px;
}

.ai-grid {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 10px;
}

.gif-search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.gif-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  min-height: 0;
  max-height: 168px;
  overflow: auto;
}

.gif-result {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  cursor: pointer;
}

.gif-result img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.emoji-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.emoji-picker button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  cursor: pointer;
  font-size: 18px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f172a;
}

.segmented button {
  min-height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.segmented button.active {
  background: var(--accent);
  color: #03110e;
}

.background-actions {
  gap: 8px;
}

.inline-status {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: none;
}

.inline-check input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.render-actions {
  margin: 14px 16px 0;
}

.render-status {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px;
  border-radius: 10px;
  background: #0f172a;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

#statusDot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(32, 212, 168, 0.12);
}

.download-link {
  display: none;
  margin-top: 10px;
  padding: 11px 14px;
  border-radius: 8px;
  background: #e0f2fe;
  color: #075985;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 850;
}

.download-link.ready {
  display: block;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
}

@media (max-width: 1120px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-stage {
    min-height: 720px;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  .top-actions {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .top-actions > * {
    min-width: 0;
    width: 100%;
  }

  .top-actions .btn {
    font-size: 12px;
    padding: 0 10px;
  }

  .workspace {
    display: block;
    width: 100vw;
    max-width: 100vw;
    padding: 10px;
    overflow-x: hidden;
  }

  .panel,
  .preview-stage {
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    margin-bottom: 16px;
  }

  .message-list {
    overflow-x: hidden;
  }

  .speaker-grid {
    grid-template-columns: 1fr;
  }

  .message-item {
    grid-template-columns: minmax(0, 1fr);
    padding-right: 10px;
  }

  .message-item .side {
    width: 82px;
  }

  .message-item .msg-text {
    width: 100%;
    max-width: 100%;
    font-size: 12px;
    overflow-x: hidden;
  }

  .message-item .delete {
    position: static;
    width: 100%;
    height: 34px;
  }
}
