:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-soft: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f5f7fb;
  --muted: rgba(245, 247, 251, 0.64);
  --gold: #f4c76c;
  --gold-strong: #ffdd95;
  --accent: #7c5cff;
  --danger: #ff5e73;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(124, 92, 255, 0.18), transparent 28%),
    radial-gradient(circle at top right, rgba(244, 199, 108, 0.12), transparent 24%),
    linear-gradient(180deg, #090909 0%, #050505 100%);
  color: var(--text);
}

body {
  padding: 32px;
}

button,
textarea,
input {
  font: inherit;
}

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.eyebrow,
.panel-label {
  margin: 0 0 10px;
  color: var(--gold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
}

.hero h1,
.panel-header h2,
.drawer-header h3,
.edit-board-card h4,
.library-item h4,
.editor-card h4 {
  margin: 0;
}

.hero h1 {
  font-size: clamp(36px, 4vw, 56px);
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.hero-text {
  max-width: 760px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.hero-badge,
.panel-tag {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.panel-tag {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--gold-strong);
}

.badge-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold) 0%, #fff1c8 100%);
  box-shadow: 0 0 20px rgba(244, 199, 108, 0.85);
}

.workspace {
  display: block;
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.03)),
    rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 24%, transparent 76%, rgba(244, 199, 108, 0.08));
  pointer-events: none;
}

.panel-chat {
  padding: 24px;
  min-height: 760px;
}

.panel-header,
.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-header {
  margin-bottom: 20px;
}

.panel-header h2,
.drawer-header h3 {
  font-size: 28px;
  letter-spacing: -0.03em;
}

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 510px;
  max-height: 510px;
  padding: 8px 2px 8px 0;
  overflow: auto;
}

.chat-box::-webkit-scrollbar,
.library-list::-webkit-scrollbar,
.storyboard-editor-list::-webkit-scrollbar {
  width: 8px;
}

.chat-box::-webkit-scrollbar-thumb,
.library-list::-webkit-scrollbar-thumb,
.storyboard-editor-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.message {
  display: flex;
  gap: 12px;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.95), rgba(244, 199, 108, 0.82));
  box-shadow: 0 10px 24px rgba(124, 92, 255, 0.22);
}

.message.user .message-avatar {
  background: linear-gradient(135deg, rgba(244, 199, 108, 0.95), rgba(255, 255, 255, 0.9));
  box-shadow: 0 10px 24px rgba(244, 199, 108, 0.18);
}

.message-bubble {
  max-width: min(82%, 760px);
  padding: 16px 18px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.message.user .message-bubble {
  background: linear-gradient(135deg, rgba(244, 199, 108, 0.12), rgba(255, 255, 255, 0.05));
}

.message-role {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message-text {
  margin: 0;
  color: rgba(245, 247, 251, 0.9);
  line-height: 1.75;
  white-space: pre-line;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.message-action-btn {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid rgba(244, 199, 108, 0.28);
  background: linear-gradient(135deg, rgba(244, 199, 108, 0.14), rgba(124, 92, 255, 0.16));
  color: var(--gold-strong);
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.message-action-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(244, 199, 108, 0.42);
}

.message-action-btn:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
}

.composer-area {
  margin-top: 18px;
}

.toolbar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.action-btn,
.icon-btn,
#sendBtn,
.skill-option,
.library-item,
.category-pill {
  border: 1px solid var(--border);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
  cursor: pointer;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-weight: 600;
}

.action-btn-primary {
  background: linear-gradient(135deg, rgba(244, 199, 108, 0.22), rgba(124, 92, 255, 0.18));
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.14);
}

.skill-picker {
  position: relative;
}

.skill-trigger {
  border-color: rgba(255, 94, 115, 0.55);
  color: #ff7a8c;
}

.skill-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.skill-caret svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.skill-trigger[aria-expanded="true"] .skill-caret {
  transform: rotate(180deg);
}

.action-btn:hover,
.icon-btn:hover,
#sendBtn:hover,
.skill-option:hover,
.library-item:hover,
.category-pill:hover {
  transform: translateY(-1px);
  border-color: rgba(244, 199, 108, 0.36);
}

.btn-icon,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
}

.btn-icon svg,
.icon-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.skills-panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  width: 360px;
  max-width: min(360px, 80vw);
  padding: 12px;
  border-radius: 22px;
  background: rgba(36, 36, 36, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  z-index: 5;
}

.skill-option {
  width: 100%;
  padding: 16px 18px;
  border-radius: 16px;
  text-align: left;
  background: transparent;
  color: var(--text);
}

.skill-option-title,
.skill-option-desc {
  display: block;
}

.skill-option-title {
  color: #fff1f3;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.06em;
}

.skill-option-desc {
  margin-top: 8px;
  color: rgba(245, 247, 251, 0.58);
  font-size: 15px;
}

.composer-shell {
  padding: 12px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 12px;
}

.input-frame {
  display: flex;
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  min-height: 136px;
}

.input-frame:focus-within {
  border-color: rgba(244, 199, 108, 0.46);
  box-shadow: 0 0 0 4px rgba(244, 199, 108, 0.08);
}

.rich-input {
  width: 100%;
  min-height: 104px;
  outline: none;
  color: var(--text);
  line-height: 1.7;
  font-size: 18px;
  white-space: pre-wrap;
  word-break: break-word;
}

.rich-input:empty::before {
  content: attr(data-placeholder);
  color: rgba(245, 247, 251, 0.38);
  pointer-events: none;
}

.skill-token {
  display: inline-flex;
  align-items: center;
  margin-right: 12px;
  margin-bottom: 6px;
  padding: 2px 0;
  background: transparent;
  color: var(--danger);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.01em;
  user-select: none;
}

.skill-token.is-selected {
  outline: 1px solid rgba(255, 94, 115, 0.45);
  border-radius: 8px;
}

.rich-input br {
  content: "";
}

#sendBtn {
  border-radius: 18px;
  background: linear-gradient(135deg, var(--gold), #ffe7b2);
  color: #121212;
  font-weight: 800;
}

.side-overlay {
  position: fixed;
  top: 24px;
  right: 24px;
  bottom: 24px;
  width: min(520px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
  transform: translateX(calc(100% + 32px));
  transition: transform 220ms ease;
  z-index: 20;
}

.side-overlay.open {
  transform: translateX(0);
}

.drawer-header {
  margin-bottom: 18px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.44);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  z-index: 10;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.overlay-panel {
  height: calc(100% - 82px);
}

.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.category-pill {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.category-pill.active {
  background: linear-gradient(135deg, rgba(244, 199, 108, 0.14), rgba(124, 92, 255, 0.12));
  color: var(--gold-strong);
  border-color: rgba(244, 199, 108, 0.3);
}

.library-list,
.storyboard-editor-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100% - 52px);
  overflow: auto;
  padding-right: 4px;
}

.library-item {
  width: 100%;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: 18px;
  text-align: left;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.library-item.active {
  border-color: rgba(244, 199, 108, 0.46);
  background: linear-gradient(135deg, rgba(244, 199, 108, 0.12), rgba(255, 255, 255, 0.04));
}

.book-cover {
  width: 74px;
  height: 98px;
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(124, 92, 255, 0.72), rgba(244, 199, 108, 0.7));
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.92);
}

.library-content {
  min-width: 0;
}

.library-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.confirm-btn {
  min-width: 96px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255, 94, 115, 0.18), rgba(124, 92, 255, 0.18));
  border: 1px solid rgba(255, 94, 115, 0.34);
  color: #ffd4da;
  font-weight: 700;
}

.confirm-btn:hover {
  border-color: rgba(255, 94, 115, 0.55);
  transform: translateY(-1px);
}

.library-meta,
.script-meta,
.editor-meta {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.library-item p,
.edit-board-card p,
.editor-card p,
.editor-card textarea {
  margin: 0;
  line-height: 1.7;
}

.edit-board-top {
  margin-bottom: 16px;
}

.storyboard-tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.storyboard-copy-btn,
.editor-edit-btn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(244, 199, 108, 0.28);
  background: linear-gradient(135deg, rgba(244, 199, 108, 0.14), rgba(124, 92, 255, 0.16));
  color: var(--gold-strong);
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.storyboard-copy-btn:hover,
.editor-edit-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(244, 199, 108, 0.42);
}

.storyboard-copy-btn:disabled,
.editor-edit-btn:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
}

.edit-board-card,
.editor-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.editor-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.edit-board-label {
  margin-bottom: 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(244, 199, 108, 0.12);
  color: var(--gold-strong);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}

.editor-card textarea {
  width: 100%;
  min-height: 86px;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  resize: vertical;
  outline: none;
}

.editor-card textarea[readonly] {
  opacity: 0.72;
}

.editor-card textarea:focus {
  border-color: rgba(244, 199, 108, 0.38);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-tag-button {
  cursor: pointer;
}

.panel-tag-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.panel-tag-caret svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.model-picker {
  position: relative;
}

.model-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 280px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(36, 36, 36, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  z-index: 6;
}

.model-option {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.model-option.active {
  background: rgba(244, 199, 108, 0.1);
  border-color: rgba(244, 199, 108, 0.18);
}

.model-option-name,
.model-option-id {
  display: block;
}

.model-option-name {
  font-weight: 700;
}

.model-option-id {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  z-index: 24;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.history-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(760px, calc(100vw - 32px));
  max-height: min(78vh, 880px);
  padding: 22px;
  border-radius: 28px;
  border: 1px solid var(--border);
  background: rgba(14, 14, 14, 0.98);
  backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
  transform: translate(-50%, calc(-50% + 20px));
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 220ms ease,
    transform 220ms ease;
  z-index: 25;
}

.history-modal.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.history-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.history-modal h3 {
  margin: 0;
  font-size: 26px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(78vh - 110px);
  overflow: auto;
  padding-right: 4px;
}

.history-item {
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}

.history-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.history-item h4,
.history-empty h4 {
  margin: 0;
}

.history-item-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.history-item p,
.history-empty p {
  margin: 0;
  color: rgba(245, 247, 251, 0.82);
  line-height: 1.7;
}

.history-empty {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}

@media (max-width: 720px) {
  body {
    padding: 18px;
  }

  .hero {
    flex-direction: column;
  }

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

  .skills-panel {
    width: min(360px, calc(100vw - 60px));
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .library-item {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .confirm-btn {
    grid-column: 2;
    justify-self: start;
    margin-top: 4px;
  }

  #sendBtn {
    min-height: 52px;
  }

  .side-overlay {
    top: 16px;
    right: 16px;
    bottom: 16px;
    width: calc(100vw - 32px);
  }

  .history-modal {
    width: calc(100vw - 24px);
  }
}
