
/*
 * Lodcer Code Playground
 * File: css/playground.css
 * Scope: all selectors are prefixed with .play- or .msg- to avoid polluting the existing site.
 */

:root {
  --play-bg: var(--color-bg, #ffffff);
  --play-bg-secondary: var(--color-bg-secondary, #f8fafc);
  --play-bg-soft: var(--color-surface, #f1f5f9);
  --play-text: var(--color-text, #0f172a);
  --play-text-muted: var(--color-text-secondary, #64748b);
  --play-accent: var(--color-accent, #1E293B);
  --play-border: var(--color-border, #e2e8f0);
  --play-font-sans: var(--font-sans, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
  --play-font-mono: var(--font-mono, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace);
  --play-radius-sm: var(--radius-sm, 8px);
  --play-radius-md: var(--radius-md, 12px);
  --play-radius-lg: var(--radius-lg, 18px);
  --play-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);
  --play-shadow-md: 0 12px 30px rgba(15, 23, 42, 0.10);
  --play-shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.18);
  --play-sidebar-width: 260px;
  --play-topbar-height: 56px;
  --play-status-height: 30px;
}

html.playground-page,
html.playground-page body {
  height: 100%;
  overflow: hidden;
}

body.playground-page {
  margin: 0;
  background: var(--play-bg);
  color: var(--play-text);
  font-family: var(--play-font-sans);
}

.play-container,
.play-container * {
  box-sizing: border-box;
}

.play-container {
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at top right, rgba(30, 41, 59, 0.06), transparent 36vw),
    linear-gradient(180deg, rgba(248, 250, 252, 0.72), rgba(255, 255, 255, 0.94));
  color: var(--play-text);
  isolation: isolate;
}

.play-topbar {
  height: var(--play-topbar-height);
  min-height: var(--play-topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--play-border);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(16px);
  z-index: 30;
}

.play-topbar-left,
.play-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.play-title-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.play-title {
  font-size: 15px;
  font-weight: 720;
  letter-spacing: -0.02em;
  color: var(--play-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.play-subtitle {
  font-size: 12px;
  color: var(--play-text-muted);
  line-height: 1.2;
}

.play-icon-btn,
.play-text-btn,
.play-send-btn,
.play-chip,
.play-action-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--play-text);
  font: inherit;
  cursor: pointer;
  user-select: none;
  transition: transform .16s ease, background-color .16s ease, border-color .16s ease, color .16s ease, opacity .16s ease, box-shadow .16s ease;
}

.play-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--play-text-muted);
}

.play-icon-btn:hover,
.play-text-btn:hover,
.play-chip:hover,
.play-action-btn:hover {
  background: var(--play-bg-soft);
  color: var(--play-accent);
  border-color: var(--play-border);
}

.play-icon-btn:active,
.play-send-btn:active,
.play-text-btn:active,
.play-chip:active,
.play-action-btn:active {
  transform: translateY(1px) scale(0.98);
}

.play-text-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--play-text-muted);
  font-size: 13px;
}

.play-hamburger {
  display: none;
}

.play-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.play-sidebar {
  width: var(--play-sidebar-width);
  min-width: 200px;
  max-width: 400px;
  border-right: 1px solid var(--play-border);
  background: rgba(248, 250, 252, 0.72);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 20;
}

.play-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 14px 10px;
}

.play-sidebar-title {
  font-weight: 720;
  color: var(--play-accent);
  font-size: 14px;
}

.play-history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 14px;
}

.play-history-group {
  margin: 14px 0;
}

.play-history-date {
  padding: 0 8px 8px;
  color: var(--play-text-muted);
  font-size: 12px;
  font-weight: 650;
}

.play-history-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
  padding: 10px 8px 10px 10px;
  color: var(--play-text);
  cursor: pointer;
  text-align: left;
  transition: background-color .16s ease, border-color .16s ease, transform .16s ease;
  position: relative;
}

.play-history-item:hover {
  background: rgba(255, 255, 255, 0.78);
  border-color: var(--play-border);
}

.play-history-item.is-active {
  background: #ffffff;
  border-color: rgba(30, 41, 59, 0.16);
  box-shadow: var(--play-shadow-sm);
}

.play-history-main {
  min-width: 0;
}

.play-history-name {
  display: block;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.play-history-time {
  display: block;
  color: var(--play-text-muted);
  font-size: 11px;
  margin-top: 2px;
}

.play-history-delete {
  opacity: 0;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--play-text-muted);
  cursor: pointer;
  transition: opacity .16s ease, background-color .16s ease, color .16s ease;
}

.play-history-item:hover .play-history-delete {
  opacity: 1;
}

.play-history-delete:hover {
  background: rgba(239, 68, 68, 0.10);
  color: #ef4444;
}

.play-sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--play-border);
}

.play-new-chat {
  width: 100%;
  justify-content: center;
  background: var(--play-accent);
  color: #fff;
  border-color: var(--play-accent);
}

.play-new-chat:hover {
  background: #0f172a;
  color: #fff;
}

.play-resizer {
  width: 6px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 21;
}

.play-resizer::before {
  content: "";
  position: absolute;
  inset: 0 2px;
  background: transparent;
  transition: background-color .16s ease;
}

.play-resizer:hover::before,
.play-resizer.is-dragging::before {
  background: rgba(30, 41, 59, 0.18);
}

.play-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.play-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px clamp(16px, 3vw, 34px);
  scroll-behavior: smooth;
}

.play-message-list {
  width: min(100%, 980px);
  margin: 0 auto;
}

.play-welcome {
  margin: 30px auto 22px;
  padding: 22px;
  border: 1px solid var(--play-border);
  background: rgba(255, 255, 255, 0.78);
  border-radius: 22px;
  box-shadow: var(--play-shadow-sm);
}

.play-welcome h1 {
  margin: 0 0 8px;
  color: var(--play-accent);
  font-size: clamp(24px, 4vw, 34px);
  letter-spacing: -0.04em;
}

.play-welcome p {
  margin: 0;
  color: var(--play-text-muted);
  line-height: 1.75;
}

.play-prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.play-prompt {
  border: 1px solid var(--play-border);
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  text-align: left;
  color: var(--play-text);
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.play-prompt:hover {
  transform: translateY(-1px);
  border-color: rgba(30, 41, 59, 0.28);
  box-shadow: var(--play-shadow-sm);
}

.play-prompt strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
  color: var(--play-accent);
}

.play-prompt span {
  display: block;
  color: var(--play-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.msg {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  animation: play-msg-in .22s ease both;
}

@keyframes play-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user {
  justify-content: flex-end;
}

.msg-assistant,
.msg-system {
  justify-content: flex-start;
}

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 760;
  font-size: 13px;
  box-shadow: var(--play-shadow-sm);
}

.msg-user .msg-avatar {
  order: 2;
  background: var(--play-accent);
  color: #fff;
}

.msg-assistant .msg-avatar {
  background: #fff;
  color: var(--play-accent);
  border: 1px solid var(--play-border);
}

.msg-bubble {
  max-width: min(760px, calc(100vw - 140px));
  min-width: 0;
}

.msg-user .msg-bubble {
  background: #fff;
  border: 1px solid var(--play-border);
  border-radius: 16px 16px 4px 16px;
  padding: 12px 14px;
  box-shadow: var(--play-shadow-sm);
  position: relative;
}

.msg-user-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.75;
  font-size: 14px;
}

.msg-edited {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  color: var(--play-text-muted);
  font-size: 12px;
}

.msg-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity .16s ease, transform .16s ease;
}

.msg-user:hover .msg-actions,
.msg-assistant:hover .msg-actions {
  opacity: 1;
  transform: translateY(0);
}

.msg-action {
  border: 1px solid var(--play-border);
  background: rgba(248, 250, 252, 0.9);
  color: var(--play-text-muted);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.msg-action:hover {
  color: var(--play-accent);
  background: #fff;
}

.msg-edit-area {
  width: min(640px, 70vw);
  min-height: 80px;
  border: 1px solid rgba(30, 41, 59, 0.22);
  background: #fff;
  color: var(--play-text);
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  line-height: 1.65;
  resize: vertical;
  outline: none;
  box-shadow: 0 0 0 4px rgba(30, 41, 59, 0.07);
}

.msg-assistant .msg-bubble {
  max-width: min(860px, calc(100vw - 140px));
  width: 100%;
}

.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  color: var(--play-accent);
  font-size: 13px;
  font-weight: 720;
  margin-bottom: 4px;
}

.msg-time {
  color: var(--play-text-muted);
  font-weight: 500;
  font-size: 12px;
}

.msg-content {
  display: block;
  width: 100%;
}

.msg-text {
  margin: 8px 0;
  line-height: 1.8;
  color: var(--play-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-text strong {
  color: var(--play-accent);
}

.msg-text ul {
  margin: 8px 0 8px 22px;
}

.msg-system {
  justify-content: center;
  margin: 12px 0;
}

.msg-system-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 70%;
  border: 1px solid var(--play-border);
  background: rgba(248, 250, 252, 0.86);
  color: var(--play-text-muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
}

/* Thinking block */
.thinking-block {
  border: 1px solid rgba(30, 41, 59, 0.08);
  background: var(--play-bg-secondary);
  border-radius: var(--play-radius-md);
  margin: 10px 0;
  overflow: hidden;
}

.thinking-head {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--play-text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 720;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.thinking-body {
  padding: 0 14px 12px;
  color: var(--play-text-muted);
  font-size: 13px;
  line-height: 1.75;
  font-style: italic;
  white-space: pre-wrap;
}

.thinking-block.is-collapsed .thinking-body {
  display: none;
}

.thinking-collapsed-note {
  display: none;
  padding: 0 14px 12px;
  font-size: 13px;
  color: var(--play-text-muted);
}

.thinking-block.is-collapsed .thinking-collapsed-note {
  display: block;
}

/* Tool cards */
.tool-flow {
  margin: 10px 0;
  position: relative;
}

.tool-flow::before {
  content: "";
  position: absolute;
  left: 14px;
  top: -6px;
  bottom: -6px;
  width: 1px;
  background: linear-gradient(to bottom, transparent, var(--play-border), transparent);
  opacity: .8;
}

.tool-card {
  border: 1px solid var(--play-border);
  border-radius: var(--play-radius-md);
  background: rgba(255, 255, 255, 0.92);
  margin: 10px 0 10px 28px;
  overflow: hidden;
  box-shadow: var(--play-shadow-sm);
  position: relative;
}

.tool-card::before {
  content: "";
  position: absolute;
  left: -29px;
  top: 14px;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 5px var(--play-bg);
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 720;
  color: var(--play-accent);
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.86), rgba(255, 255, 255, 0.9));
}

.tool-name {
  flex: 1;
  min-width: 0;
}

.tool-status {
  color: var(--play-text-muted);
  font-weight: 650;
  font-size: 12px;
}

.tool-card-body {
  border-top: 1px solid var(--play-border);
  padding: 10px 12px 12px;
  font-size: 13px;
  color: var(--play-text);
  line-height: 1.65;
}

.tool-card.is-collapsed .tool-card-body {
  display: none;
}

.tool-param {
  color: var(--play-text-muted);
  margin-bottom: 8px;
}

.tool-param code,
.tool-result code,
.search-block code,
.diff-block code {
  font-family: var(--play-font-mono);
  font-size: .95em;
  background: rgba(15, 23, 42, 0.05);
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-radius: 6px;
  padding: 1px 5px;
}

.tool-result {
  border-top: 1px dashed var(--play-border);
  padding-top: 8px;
  white-space: pre-wrap;
}

.tool-duration {
  margin-top: 8px;
  color: var(--play-text-muted);
  font-size: 12px;
}

.tool-read { color: #3B82F6; border-left: 3px solid #3B82F6; }
.tool-write { color: #22C55E; border-left: 3px solid #22C55E; }
.tool-edit { color: #F59E0B; border-left: 3px solid #F59E0B; }
.tool-bash { color: #8B5CF6; border-left: 3px solid #8B5CF6; }
.tool-glob { color: #06B6D4; border-left: 3px solid #06B6D4; }
.tool-grep { color: #EC4899; border-left: 3px solid #EC4899; }
.tool-webfetch { color: #6366F1; border-left: 3px solid #6366F1; }

/* Diff */
.diff-block {
  border: 1px solid var(--play-border);
  border-radius: var(--play-radius-md);
  background: #fff;
  margin: 12px 0;
  overflow: hidden;
  box-shadow: var(--play-shadow-sm);
  font-size: 13px;
}

.diff-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--play-bg-secondary);
  border-bottom: 1px solid var(--play-border);
}

.diff-file {
  font-family: var(--play-font-mono);
  font-weight: 720;
  color: var(--play-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diff-meta {
  color: var(--play-text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.diff-code {
  overflow-x: auto;
  background: #fff;
  font-family: var(--play-font-mono);
}

.diff-line {
  display: grid;
  grid-template-columns: 44px 22px minmax(0, 1fr);
  min-width: 620px;
  line-height: 1.55;
  border-left: 3px solid transparent;
}

.diff-line-num {
  color: #94a3b8;
  text-align: right;
  padding: 2px 8px 2px 0;
  user-select: none;
  background: rgba(248, 250, 252, 0.65);
}

.diff-prefix {
  padding: 2px 0;
  text-align: center;
  color: #94a3b8;
  user-select: none;
}

.diff-source {
  padding: 2px 12px 2px 0;
  white-space: pre;
  color: #334155;
}

.diff-line.add {
  background: rgba(34, 197, 94, 0.08);
  border-left-color: #22C55E;
}

.diff-line.add .diff-prefix {
  color: #16a34a;
}

.diff-line.remove {
  background: rgba(239, 68, 68, 0.08);
  border-left-color: #EF4444;
}

.diff-line.remove .diff-prefix {
  color: #dc2626;
}

.diff-line.context .diff-prefix {
  color: transparent;
}

.diff-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--play-border);
  background: rgba(248, 250, 252, 0.52);
  flex-wrap: wrap;
}

.diff-page {
  margin-right: auto;
  color: var(--play-text-muted);
  font-size: 12px;
}

.diff-btn {
  border: 1px solid var(--play-border);
  background: #fff;
  color: var(--play-text);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}

.diff-btn:hover {
  border-color: rgba(30, 41, 59, 0.22);
  color: var(--play-accent);
}

.diff-btn.accept {
  background: rgba(34, 197, 94, 0.10);
  color: #15803d;
  border-color: rgba(34, 197, 94, 0.25);
}

.diff-btn.reject {
  background: rgba(239, 68, 68, 0.08);
  color: #b91c1c;
  border-color: rgba(239, 68, 68, 0.22);
}

.diff-final {
  padding: 12px;
  color: var(--play-text-muted);
  font-size: 13px;
}

/* Terminal */
.terminal-block {
  border-radius: var(--play-radius-md);
  background: #1E1E1E;
  color: #D4D4D4;
  margin: 12px 0;
  overflow: hidden;
  box-shadow: var(--play-shadow-md);
  border: 1px solid rgba(15, 23, 42, .4);
}

.terminal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  color: #f8fafc;
  font-size: 13px;
  font-weight: 720;
  background: rgba(255,255,255,.04);
}

.terminal-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  background: #64748b;
}

.terminal-dot:nth-child(1) { background: #ef4444; }
.terminal-dot:nth-child(2) { background: #f59e0b; }
.terminal-dot:nth-child(3) { background: #22c55e; }

.terminal-title {
  margin-left: 4px;
}

.terminal-body {
  padding: 14px 16px 12px;
  overflow-x: auto;
  font-family: var(--play-font-mono);
  font-size: 13px;
  line-height: 1.58;
  white-space: pre;
}

.term-cmd { color: #93c5fd; }
.term-ok { color: #86efac; }
.term-error { color: #fca5a5; }
.term-url { color: #60a5fa; text-decoration: underline; }
.term-muted { color: #94a3b8; }

/* Search results */
.search-block {
  border: 1px solid var(--play-border);
  border-radius: var(--play-radius-md);
  background: #fff;
  margin: 12px 0;
  overflow: hidden;
  box-shadow: var(--play-shadow-sm);
}

.search-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--play-border);
  background: var(--play-bg-secondary);
  font-size: 13px;
  font-weight: 720;
  color: var(--play-accent);
}

.search-body {
  padding: 10px 12px;
}

.search-file {
  margin: 10px 0 12px;
}

.search-file-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--play-font-mono);
  font-size: 13px;
  color: var(--play-accent);
  cursor: pointer;
}

.search-file-title:hover {
  text-decoration: underline;
}

.search-line {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  font-family: var(--play-font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: #475569;
}

.search-line-no {
  color: #94a3b8;
  text-align: right;
  padding-right: 10px;
  user-select: none;
}

.search-line.hit {
  background: rgba(250, 204, 21, 0.16);
  border-radius: 6px;
}

.search-line.hit .search-code {
  color: #1e293b;
  font-weight: 650;
}

.search-summary {
  border-top: 1px dashed var(--play-border);
  padding-top: 10px;
  color: var(--play-text-muted);
  font-size: 12px;
}

/* Input */
.play-inputbar {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 12px clamp(16px, 3vw, 34px) 16px;
  position: relative;
}

.play-input-shell {
  border: 1px solid var(--play-border);
  background: rgba(255, 255, 255, .9);
  border-radius: 20px;
  box-shadow: var(--play-shadow-md);
  overflow: hidden;
}

.play-composer {
  width: 100%;
  min-height: 58px;
  max-height: 180px;
  border: 0;
  background: transparent;
  color: var(--play-text);
  font: inherit;
  font-size: 14px;
  line-height: 1.65;
  resize: none;
  outline: none;
  padding: 14px 16px 8px;
}

.play-composer::placeholder {
  color: #94a3b8;
}

.play-input-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid rgba(226, 232, 240, .72);
}

.play-model-btn {
  min-width: 190px;
  justify-content: flex-start;
  background: var(--play-bg-secondary);
  border-color: var(--play-border);
}

.play-model-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.play-tool-spacer {
  flex: 1;
}

.play-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--play-accent);
  color: #fff;
  border-color: var(--play-accent);
  font-size: 18px;
}

.play-send-btn:disabled {
  cursor: default;
  opacity: .38;
  transform: none;
}

.play-generating {
  position: absolute;
  left: clamp(20px, 3vw, 38px);
  right: clamp(20px, 3vw, 38px);
  bottom: calc(100% - 2px);
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(30, 41, 59, .08);
  display: none;
}

.play-generating.is-visible {
  display: block;
}

.play-generating span {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--play-accent), transparent);
  animation: play-progress 1.1s ease-in-out infinite;
}

@keyframes play-progress {
  from { transform: translateX(-100%); }
  to { transform: translateX(270%); }
}

.play-scroll-latest {
  position: absolute;
  right: clamp(18px, 4vw, 44px);
  bottom: 116px;
  border: 1px solid var(--play-border);
  background: #fff;
  color: var(--play-accent);
  border-radius: 999px;
  padding: 7px 12px;
  box-shadow: var(--play-shadow-md);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
  z-index: 10;
}

.play-scroll-latest.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Popovers / modal */
.play-popover,
.play-modal-panel,
.play-command-panel {
  border: 1px solid var(--play-border);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--play-shadow-lg);
  border-radius: 18px;
  backdrop-filter: blur(18px);
}

.play-popover {
  position: absolute;
  z-index: 60;
  min-width: 310px;
  padding: 10px;
  display: none;
}

.play-popover.is-open {
  display: block;
  animation: play-pop .16s ease both;
}

@keyframes play-pop {
  from { opacity: 0; transform: translateY(4px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.model-option {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid transparent;
  background: transparent;
  color: var(--play-text);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  text-align: left;
}

.model-option:hover,
.model-option.is-selected {
  background: var(--play-bg-secondary);
  border-color: var(--play-border);
}

.model-name {
  font-weight: 720;
  font-size: 13px;
}

.model-desc {
  display: block;
  color: var(--play-text-muted);
  font-size: 12px;
  margin-top: 2px;
}

.model-tag {
  font-size: 11px;
  color: var(--play-accent);
  background: rgba(30, 41, 59, .08);
  border-radius: 999px;
  padding: 3px 7px;
}

.model-custom {
  border-top: 1px solid var(--play-border);
  margin-top: 8px;
  padding-top: 8px;
}

.play-modal,
.play-command {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(15, 23, 42, .24);
}

.play-modal.is-open,
.play-command.is-open {
  display: flex;
}

.play-modal-panel {
  width: min(560px, 96vw);
  max-height: min(720px, 90vh);
  overflow: auto;
  padding: 18px;
}

.play-modal-head,
.play-command-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.play-modal-title,
.play-command-title {
  font-weight: 820;
  color: var(--play-accent);
  letter-spacing: -0.02em;
}

.setting-section {
  border-top: 1px solid var(--play-border);
  padding-top: 14px;
  margin-top: 14px;
}

.setting-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.setting-title {
  font-weight: 780;
  color: var(--play-accent);
  margin-bottom: 10px;
}

.setting-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 56px;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
  font-size: 13px;
  color: var(--play-text-muted);
}

.setting-row input[type="range"] {
  width: 100%;
  accent-color: var(--play-accent);
}

.setting-textarea {
  width: 100%;
  min-height: 84px;
  border: 1px solid var(--play-border);
  background: var(--play-bg-secondary);
  color: var(--play-text);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
  outline: none;
}

.setting-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 9px 0;
  color: var(--play-text);
  font-size: 13px;
}

.setting-check input {
  accent-color: var(--play-accent);
}

.play-command-panel {
  width: min(640px, 94vw);
  overflow: hidden;
}

.play-command-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--play-border);
  background: transparent;
  color: var(--play-text);
  font: inherit;
  font-size: 16px;
  outline: 0;
  padding: 16px 18px;
}

.play-command-list {
  padding: 8px;
}

.play-command-item {
  width: 100%;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 10px;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--play-text);
  border-radius: 12px;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.play-command-item:hover {
  background: var(--play-bg-secondary);
}

.play-command-kbd {
  color: var(--play-text-muted);
  font-size: 12px;
  border: 1px solid var(--play-border);
  border-radius: 6px;
  padding: 2px 6px;
  background: #fff;
}

.play-toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%) translateY(20px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  background: #0f172a;
  color: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--play-shadow-lg);
  transition: opacity .18s ease, transform .18s ease;
}

.play-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.play-statusbar {
  height: var(--play-status-height);
  min-height: var(--play-status-height);
  border-top: 1px solid var(--play-border);
  background: rgba(248, 250, 252, .85);
  color: var(--play-text-muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.play-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, .12);
}

.typing-cursor::after {
  content: '▊';
  animation: play-blink 0.8s step-end infinite;
  color: var(--play-accent);
}

@keyframes play-blink {
  50% { opacity: 0; }
}

.code-kw { color: #7c3aed; font-weight: 650; }
.code-str { color: #15803d; }
.code-fn { color: #2563eb; }
.code-comment { color: #64748b; font-style: italic; }

.play-hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 1024px) {
  :root {
    --play-sidebar-width: 240px;
  }

  .msg-bubble,
  .msg-assistant .msg-bubble {
    max-width: calc(100vw - 110px);
  }
}

@media (max-width: 900px) {
  .play-hamburger {
    display: inline-flex;
  }

  .play-sidebar {
    position: fixed;
    top: var(--play-topbar-height);
    left: 0;
    bottom: var(--play-status-height);
    width: min(82vw, 340px) !important;
    max-width: min(82vw, 340px);
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: var(--play-shadow-lg);
  }

  .play-sidebar.is-open {
    transform: translateX(0);
  }

  .play-resizer {
    display: none;
  }

  .play-sidebar-backdrop {
    position: fixed;
    inset: var(--play-topbar-height) 0 var(--play-status-height) 0;
    background: rgba(15, 23, 42, .18);
    z-index: 19;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }

  .play-sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 768px) {
  .play-topbar {
    padding: 0 10px;
  }

  .play-subtitle {
    display: none;
  }

  .play-text-btn span.optional {
    display: none;
  }

  .play-messages {
    padding: 16px 12px;
  }

  .play-welcome {
    padding: 16px;
  }

  .play-prompt-grid {
    grid-template-columns: 1fr;
  }

  .msg {
    gap: 8px;
  }

  .msg-avatar {
    width: 30px;
    height: 30px;
  }

  .msg-bubble,
  .msg-assistant .msg-bubble {
    max-width: calc(100vw - 68px);
  }

  .msg-user .msg-avatar {
    display: none;
  }

  .msg-user .msg-bubble {
    max-width: calc(100vw - 34px);
  }

  .play-inputbar {
    padding: 10px 10px 12px;
  }

  .play-input-tools {
    gap: 5px;
  }

  .play-model-btn {
    min-width: 0;
    max-width: 48%;
  }

  .play-chip {
    padding-inline: 8px;
  }

  .setting-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .diff-line {
    min-width: 520px;
    grid-template-columns: 38px 20px minmax(0, 1fr);
  }

  .play-statusbar {
    font-size: 11px;
    padding: 0 10px;
  }
}

/* Embedded mode: playground fills full viewport */
body.embedded {
  height: 100vh;
  overflow: hidden;
}
body.embedded #playground-root {
  height: 100vh;
  padding-top: var(--nav-height, 64px);
  display: flex;
  flex-direction: column;
}
body.embedded #playground-root .play-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
body.embedded .play-float-menu {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
}
body.embedded .play-float-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--play-accent, #1E293B);
  color: var(--play-bg, #fff);
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(15,23,42,0.24);
  transition: transform .16s ease, box-shadow .16s ease;
}
body.embedded .play-float-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 24px rgba(15,23,42,0.3);
}
body.embedded .play-float-btn:active {
  transform: scale(0.95);
}
body.embedded .play-float-panel {
  position: absolute;
  bottom: 54px;
  right: 0;
  min-width: 190px;
  background: var(--play-bg, #fff);
  border: 1px solid var(--play-border, #e2e8f0);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(15,23,42,0.18);
  display: none;
  overflow: hidden;
  animation: play-pop .16s ease both;
}
body.embedded .play-float-panel.is-open {
  display: block;
}
body.embedded .play-float-nav a {
  display: block;
  padding: 11px 18px;
  color: var(--play-text, #0f172a);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
body.embedded .play-float-nav a:hover {
  background: var(--play-bg-secondary, #f8fafc);
  color: var(--play-accent, #1E293B);
}
body.embedded .play-float-nav a.active {
  color: var(--play-accent, #1E293B);
  font-weight: 700;
  background: var(--play-bg-secondary, #f8fafc);
}
body.embedded .play-float-bottom {
  border-top: 1px solid var(--play-border, #e2e8f0);
  padding: 10px 18px;
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 12px;
  color: var(--play-text-muted, #64748b);
}
body.embedded .play-float-bottom a {
  color: var(--play-text-muted, #64748b);
  text-decoration: none;
}
body.embedded .play-float-bottom a:hover {
  color: var(--play-accent, #1E293B);
}

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

/* Final optimization: live thinking, stop generation, and runtime notices */
.play-stop-btn {
  min-height: 36px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(239, 68, 68, 0.28);
  background: rgba(254, 242, 242, 0.96);
  color: #b91c1c;
  border-radius: 999px;
  padding: 0 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 720;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(239, 68, 68, 0.08);
  transition: transform .16s ease, background-color .16s ease, border-color .16s ease, opacity .16s ease, box-shadow .16s ease;
}

.play-stop-btn:hover {
  background: #fee2e2;
  border-color: rgba(220, 38, 38, 0.42);
  box-shadow: 0 8px 22px rgba(239, 68, 68, 0.14);
}

.play-stop-btn:active {
  transform: translateY(1px) scale(0.98);
}

.play-stop-btn.is-visible {
  display: inline-flex;
  animation: play-stop-in .16s ease both;
}

@keyframes play-stop-in {
  from { opacity: 0; transform: translateY(4px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.thinking-block-live {
  border-color: rgba(30, 41, 59, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.6), 0 8px 22px rgba(15, 23, 42, 0.05);
}

.thinking-block-live .thinking-head {
  color: var(--play-accent);
}

.thinking-block-live .thinking-body {
  min-height: 24px;
}

.play-runtime-notice,
.play-stop-notice {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: var(--play-radius-md);
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid var(--play-border);
  background: rgba(248, 250, 252, 0.92);
  color: var(--play-text-muted);
}

.play-stop-notice {
  border-color: rgba(239, 68, 68, 0.24);
  background: rgba(254, 242, 242, 0.9);
  color: #991b1b;
}

@media (max-width: 768px) {
  .play-stop-btn {
    min-width: 36px;
    width: 36px;
    padding: 0;
    font-size: 0;
  }
  .play-stop-btn::before {
    content: '■';
    font-size: 13px;
  }
}
