:root {
  --teal: #2BAEA9;
  --teal-deep: #1A6F6A;
  --ink: #1A1A2E;
  --ink-soft: #4A4A5E;
  --ink-mute: #8A8A95;
  --line: #ECECE6;
  --bg: #FFFFFF;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  font-weight: 400;
  letter-spacing: 0.015em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 640px;
}

/* ===== Top bar ===== */
.topbar {
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: #FFFFFF;
}
.brand-name {
  font-family: "Cormorant Garamond", serif;
  font-weight: 700;
  font-size: 19px;
  color: var(--teal);
  letter-spacing: 0.18em;
  line-height: 1;
}
.brand-tagline {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 4px;
  letter-spacing: 0.06em;
}
.brand-en {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  color: var(--ink-mute);
  margin-left: 4px;
}
.reset-btn {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 16px;
  font-size: 11.5px;
  color: var(--ink-mute);
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.06em;
  transition: all 0.2s;
}
.reset-btn:hover:not(:disabled) {
  border-color: var(--teal);
  color: var(--teal);
}
.reset-btn:disabled { cursor: default; opacity: 0.5; }

/* ===== Main split ===== */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== Layers panel ===== */
.layers-panel {
  flex: 1 1 52%;
  padding: 22px 24px;
  overflow-y: auto;
  background: linear-gradient(180deg, #FBFAF6 0%, #FFFFFF 100%);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.layers-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 18px;
}
.layers-eyebrow {
  font-family: "Cormorant Garamond", serif;
  font-size: 10.5px;
  color: var(--teal);
  letter-spacing: 0.28em;
  font-weight: 700;
}
.layers-title {
  font-size: 15px;
  color: var(--ink);
  font-weight: 600;
  margin-top: 5px;
  letter-spacing: 0.06em;
}
.active-counter {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.05em;
  transition: color 0.3s;
}
.active-counter.active { color: var(--teal); }

#layers-container { flex: 1; }

/* ===== Layer row ===== */
.layer-row {
  position: relative;
  margin-bottom: 8px;
  border-radius: 6px;
  overflow: hidden;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0.4;
  transform: translateX(0) scale(1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.layer-row.active {
  opacity: 1;
  transform: translateX(6px) scale(1.01);
  box-shadow: 0 6px 18px rgba(43, 174, 169, 0.30);
}
.seq-badge {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 34px;
  background: var(--teal-deep);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-weight: 700;
  font-size: 15px;
  z-index: 2;
  letter-spacing: 0.03em;
}
.layer-content {
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: padding 0.4s ease-out;
  min-height: 62px;
}
.layer-row.active .layer-content { padding-left: 48px; }
.layer-label {
  min-width: 144px;
  flex-shrink: 0;
}
.layer-id {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  line-height: 1.2;
}
.layer-content.light .layer-id { color: var(--ink-mute); }
.layer-content.dark .layer-id { color: rgba(255,255,255,0.75); }
.layer-cn {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.05em;
  margin-top: 2px;
  line-height: 1.2;
}
.layer-content.light .layer-cn { color: var(--ink); }
.layer-content.dark .layer-cn { color: #FFFFFF; }
.layer-en {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 10.5px;
  margin-top: 2px;
  letter-spacing: 0.02em;
}
.layer-content.light .layer-en { color: var(--ink-mute); }
.layer-content.dark .layer-en { color: rgba(255,255,255,0.65); }
.layer-detail { flex: 1; min-width: 0; }
.layer-desc {
  font-size: 11.5px;
  font-style: italic;
  letter-spacing: 0.02em;
  line-height: 1.5;
}
.layer-content.light .layer-desc { color: var(--ink-mute); }
.layer-content.dark .layer-desc { color: rgba(255,255,255,0.55); }
.layer-role {
  font-size: 13px;
  line-height: 1.55;
  font-weight: 500;
  letter-spacing: 0.02em;
  animation: fadeIn 0.5s ease-out;
}
.layer-content.light .layer-role { color: var(--ink); }
.layer-content.dark .layer-role { color: #FFFFFF; }

.powered-by {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--ink-mute);
  font-style: italic;
  font-family: "Cormorant Garamond", serif;
  letter-spacing: 0.10em;
  text-align: center;
}

/* ===== Chat panel ===== */
.chat-panel {
  flex: 1 1 48%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 12px;
}
.msg {
  margin-bottom: 18px;
  display: flex;
}
.msg-user { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }
.bubble {
  padding: 14px 16px;
  border-radius: 14px 14px 14px 4px;
  font-size: 13.5px;
  line-height: 1.6;
}
.msg-user .bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  background: var(--teal);
  color: #FFFFFF;
  border: none;
}
.msg-assistant .bubble {
  max-width: 95%;
  background: #FAFBFA;
  color: var(--ink);
  border: 1px solid var(--line);
}
.loading-bubble {
  color: var(--ink-mute);
  font-style: italic;
  animation: pulse 1.4s ease-in-out infinite;
}

/* ===== Structured response inside bubble ===== */
.struct-explanation {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 10px;
  font-size: 14px;
  letter-spacing: 0.02em;
  line-height: 1.5;
}
.struct-layers { margin-bottom: 12px; }
.struct-layer {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.5;
  align-items: baseline;
}
.struct-layer.with-border { border-bottom: 1px solid var(--line); }
.struct-seq {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  color: var(--teal);
  font-weight: 700;
  min-width: 20px;
  font-size: 13px;
}
.struct-name {
  font-weight: 600;
  color: var(--ink);
  min-width: 84px;
  flex-shrink: 0;
}
.struct-role { flex: 1; }
.struct-summary {
  padding: 11px 14px;
  background: #EAF6F4;
  border-left: 3px solid var(--teal);
  font-size: 12.5px;
  font-style: italic;
  color: var(--teal-deep);
  line-height: 1.6;
  letter-spacing: 0.02em;
  border-radius: 3px;
}

/* ===== Examples ===== */
.examples {
  padding: 0 24px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.example-chip {
  padding: 6px 12px;
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: 16px;
  font-size: 11.5px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}
.example-chip:hover {
  border-color: var(--teal);
  color: var(--teal);
  background: #F4FBFA;
}

/* ===== Input ===== */
.input-area {
  padding: 12px 24px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.input-area input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  color: var(--ink);
  background: #FFFFFF;
  transition: border-color 0.2s;
}
.input-area input::placeholder { color: var(--ink-mute); }
.input-area input:focus { border-color: var(--teal); }
.input-area button {
  padding: 11px 22px;
  background: var(--teal);
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.08em;
  font-family: inherit;
  transition: background 0.2s;
}
.input-area button:disabled {
  background: #D5D7D4;
  cursor: default;
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ===== Mobile ===== */
@media (max-width: 900px) {
  .main { flex-direction: column; overflow-y: auto; }
  .layers-panel {
    flex: 0 0 auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .chat-panel { flex: 1 1 auto; min-height: 50vh; }
  .topbar { padding: 12px 20px; }
  .layers-panel, .messages { padding-left: 20px; padding-right: 20px; }
  .input-area, .examples { padding-left: 20px; padding-right: 20px; }
}
