:root {
  --bg: #f5f8fd;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: #ffffff;
  --surface-muted: #eef3fb;
  --text: #13213d;
  --muted: #66748f;
  --border: rgba(19, 33, 61, 0.08);
  --border-strong: rgba(19, 33, 61, 0.14);
  --blue: #235bff;
  --blue-soft: #eef3ff;
  --teal: #0ea5a3;
  --shadow: 0 24px 50px rgba(35, 61, 112, 0.09);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans TC", "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(35, 91, 255, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(14, 165, 163, 0.12), transparent 24%),
    var(--bg);
}

.app-notice {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 9999;
  max-width: min(720px, calc(100vw - 24px));
  padding: 14px 18px;
  border-radius: 16px;
  transform: translateX(-50%);
  border: 1px solid rgba(19, 33, 61, 0.08);
  background: rgba(19, 33, 61, 0.92);
  color: #fff;
  box-shadow: 0 20px 50px rgba(19, 33, 61, 0.24);
  line-height: 1.5;
}

.app-notice.error {
  background: rgba(169, 29, 58, 0.96);
}

.app-notice.success {
  background: rgba(12, 122, 108, 0.96);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 28px 22px;
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), #4a89ff);
  box-shadow: 0 16px 30px rgba(35, 91, 255, 0.24);
}

.brand-name,
.brand-subtitle,
.eyebrow,
.section-label,
.sidebar-card-label,
.message-role,
.compact-row h3 {
  margin: 0;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.92rem;
}

.primary-action,
.secondary-action,
.ghost-action {
  border: 0;
  border-radius: 14px;
  transition: 180ms ease;
}

.primary-action {
  padding: 14px 18px;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(135deg, var(--blue), #3d7aff);
  box-shadow: 0 16px 30px rgba(35, 91, 255, 0.22);
}

.primary-action:hover,
.secondary-action:hover,
.ghost-action:hover,
.nav-item:hover {
  transform: translateY(-1px);
}

.secondary-action,
.ghost-action {
  padding: 12px 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-muted);
}

.link-action {
  align-self: flex-start;
  border: 0;
  padding: 0;
  color: var(--blue);
  background: transparent;
  font-weight: 800;
}

.compact-action {
  padding: 12px 14px;
  box-shadow: none;
}

.nav-list {
  display: grid;
  gap: 10px;
  margin: 18px 0 24px;
}

.nav-item {
  text-align: left;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.nav-item.active {
  color: var(--text);
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.sidebar-card {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 16px 32px rgba(31, 57, 102, 0.04);
}

.compact-row {
  align-items: flex-start;
  margin-bottom: 14px;
}

.compact-row h3 {
  margin-top: 6px;
  font-size: 1rem;
}

.sidebar-card-label,
.section-label,
.eyebrow,
.message-role {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.73rem;
  color: var(--muted);
  font-weight: 800;
}

.tiny-pill {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.tips {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.card-hint {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.workspace {
  padding: 28px;
}

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

.topbar h1,
.section-title-row h2 {
  margin: 8px 0 0;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 22px rgba(31, 57, 102, 0.05);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.language-switcher > span {
  padding: 0 4px 0 8px;
}

.language-option {
  min-width: 40px;
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.language-option.active {
  color: var(--text);
  background: var(--surface-muted);
  box-shadow: inset 0 0 0 1px var(--border);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--border);
  box-shadow: 0 10px 22px rgba(31, 57, 102, 0.05);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.mode-panel {
  display: none;
}

.mode-panel.active {
  display: block;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.9fr);
  gap: 22px;
}

.panel-grid.single-focus {
  grid-template-columns: 1fr;
}

.conversation-panel,
.inspector-panel,
.studio-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.conversation-panel,
.inspector-panel,
.studio-panel {
  padding: 22px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.messages {
  display: grid;
  gap: 14px;
  min-height: 360px;
  max-height: 56vh;
  overflow: auto;
  padding-right: 6px;
}

.message {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
}

.message.assistant {
  background: linear-gradient(180deg, rgba(238, 243, 255, 0.95), rgba(255, 255, 255, 0.95));
}

.message-body {
  margin-top: 10px;
  color: var(--text);
  line-height: 1.72;
  white-space: pre-wrap;
}

.composer,
.tool-form {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.composer textarea,
.field input,
.field textarea,
.field select,
.raw-output {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.98);
  border-radius: 16px;
  padding: 14px 15px;
  color: var(--text);
}

.composer textarea,
.field textarea {
  resize: vertical;
}

.composer-actions,
.form-row {
  display: grid;
  gap: 14px;
}

.composer-actions {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.form-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.account-panel {
  display: grid;
  gap: 12px;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
}

.inline-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.segmented-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.segmented-tab {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  font-weight: 800;
  padding: 12px 14px;
}

.segmented-tab.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 28px rgba(31, 57, 102, 0.08);
}

.verify-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.drop-input {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 18px;
  border: 1px dashed var(--border-strong);
  background: rgba(255, 255, 255, 0.84);
}

.drop-input small,
.upload-dropzone small {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.drag-over {
  border-color: var(--blue) !important;
  background: var(--blue-soft) !important;
}

.file-upload-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.upload-dropzone {
  position: relative;
  display: grid;
  gap: 8px;
  min-height: 132px;
  padding: 18px;
  border-radius: 20px;
  border: 1px dashed var(--border-strong);
  background: rgba(255, 255, 255, 0.9);
  place-items: center;
  text-align: center;
  overflow: hidden;
}

.upload-dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-dropzone strong {
  font-size: 1rem;
  color: var(--text);
}

.upload-dropzone.has-preview {
  padding: 14px;
  place-items: start;
  text-align: left;
}

.upload-preview {
  width: 96px;
  height: 96px;
  max-height: none;
  border-radius: 12px;
  object-fit: cover;
  background: #edf2fb;
  border: 1px solid var(--border);
  margin-bottom: 6px;
}

.upload-meta {
  display: grid;
  gap: 4px;
}

.upload-meta strong {
  font-size: 0.96rem;
}

.upload-meta small {
  display: block;
}

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

.field.compact span {
  font-size: 0.82rem;
}

.raw-output {
  min-height: 540px;
  margin: 0;
  overflow: auto;
  background: #0f172a;
  color: #d9e6ff;
  white-space: pre-wrap;
  line-height: 1.6;
}

.pixel-buddy-shell {
  display: grid;
  gap: 20px;
  align-items: center;
  justify-items: center;
  min-height: 360px;
  padding: 18px;
  border-radius: 24px;
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.18), transparent 45%),
    linear-gradient(180deg, rgba(241, 245, 249, 0.96), rgba(226, 232, 240, 0.92));
  border: 1px solid rgba(148, 163, 184, 0.22);
}

.pixel-buddy-stage {
  position: relative;
  display: grid;
  justify-items: center;
  width: 100%;
}

.pixel-buddy {
  position: relative;
  width: 132px;
  height: 132px;
  image-rendering: pixelated;
  transition: transform 180ms ease, filter 180ms ease;
}

.pixel-buddy-face,
.pixel-buddy-eye,
.pixel-buddy-mouth,
.pixel-buddy-blush {
  position: absolute;
  display: block;
}

.pixel-buddy-face {
  inset: 16px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, #f8fafc 0%, #fde68a 0%, #fde68a 72%, #f59e0b 72%, #f59e0b 100%);
  box-shadow:
    0 0 0 6px #0f172a,
    inset 0 -10px 0 rgba(194, 65, 12, 0.18);
}

.pixel-buddy-eye {
  top: 48px;
  width: 18px;
  height: 18px;
  background: #0f172a;
  box-shadow: 0 0 0 4px #ffffff;
}

.pixel-buddy-eye-left {
  left: 38px;
}

.pixel-buddy-eye-right {
  right: 38px;
}

.pixel-buddy-mouth {
  left: 50%;
  bottom: 36px;
  width: 34px;
  height: 10px;
  margin-left: -17px;
  background: #0f172a;
}

.pixel-buddy-blush {
  top: 72px;
  width: 14px;
  height: 8px;
  background: rgba(248, 113, 113, 0.7);
}

.pixel-buddy-blush-left {
  left: 26px;
}

.pixel-buddy-blush-right {
  right: 26px;
}

.pixel-buddy-shadow {
  width: 92px;
  height: 16px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.14);
  filter: blur(2px);
}

.pixel-buddy[data-mood="idle"] .pixel-buddy-mouth {
  height: 6px;
}

.pixel-buddy[data-mood="thinking"] {
  transform: translateY(-4px) scale(1.02);
  filter: saturate(1.08);
}

.pixel-buddy[data-mood="thinking"] .pixel-buddy-mouth {
  width: 18px;
  height: 18px;
  margin-left: -9px;
  border-radius: 999px;
}

.pixel-buddy[data-mood="thinking"]::after,
.pixel-buddy[data-mood="success"]::after,
.pixel-buddy[data-mood="error"]::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  box-shadow: 0 0 0 4px #0f172a;
}

.pixel-buddy[data-mood="thinking"]::after {
  background: #93c5fd;
}

.pixel-buddy[data-mood="success"] {
  transform: translateY(-6px) scale(1.04);
}

.pixel-buddy[data-mood="success"] .pixel-buddy-mouth {
  width: 38px;
  height: 14px;
  margin-left: -19px;
  border-radius: 0 0 14px 14px;
}

.pixel-buddy[data-mood="success"]::after {
  background: #4ade80;
}

.pixel-buddy[data-mood="error"] {
  transform: translateY(2px);
}

.pixel-buddy[data-mood="error"] .pixel-buddy-eye {
  height: 10px;
  top: 56px;
}

.pixel-buddy[data-mood="error"] .pixel-buddy-mouth {
  width: 36px;
  height: 6px;
  margin-left: -18px;
}

.pixel-buddy[data-mood="error"]::after {
  background: #f87171;
}

.pixel-buddy-copy {
  display: grid;
  gap: 8px;
  text-align: center;
}

.pixel-buddy-status {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

.pixel-buddy-hint {
  margin: 0;
  max-width: 28ch;
  color: var(--muted);
  line-height: 1.7;
}

.raw-output-wrap {
  margin-top: 18px;
}

.raw-output-wrap summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 12px;
}

.raw-output-wrap .raw-output {
  min-height: 220px;
}

.results-grid {
  display: grid;
  gap: 18px;
  margin-top: 22px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 320px));
  align-items: start;
}

.result-card {
  overflow: hidden;
  max-width: 320px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 18px 34px rgba(31, 57, 102, 0.08);
}

.result-card img {
  display: block;
  width: 100%;
  height: clamp(180px, 24vw, 260px);
  object-fit: contain;
  background: #edf2fb;
  cursor: zoom-in;
}

.result-card .result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 16px;
}

.result-card a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 48px;
  background: rgba(9, 16, 32, 0.82);
  backdrop-filter: blur(10px);
}

.image-lightbox.hidden {
  display: none;
}

.image-lightbox img {
  max-width: min(1120px, 92vw);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.38);
  background: #fff;
}

.lightbox-close {
  position: fixed;
  top: 20px;
  right: 24px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  font-size: 2rem;
  line-height: 1;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--border-strong);
  border-radius: 20px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.72);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

@media (max-width: 760px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .section-title-row,
  .composer-actions,
  .form-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar {
    gap: 16px;
  }

  .inline-actions {
    grid-template-columns: 1fr;
  }

  .verify-row,
  .file-upload-row {
    grid-template-columns: 1fr;
  }

  .pixel-buddy-shell {
    min-height: 280px;
    padding: 16px;
  }

  .pixel-buddy {
    width: 108px;
    height: 108px;
  }

  .pixel-buddy-face {
    inset: 14px;
  }

  .pixel-buddy-eye {
    top: 40px;
  }

  .pixel-buddy-eye-left {
    left: 28px;
  }

  .pixel-buddy-eye-right {
    right: 28px;
  }
}
