/* @hara-lang/live — live-coding card styles.
   Everything is scoped under .hara-live-card; theme via custom properties. */

.hara-live-card {
  --hara-live-bg: #060b14;
  --hara-live-panel: #0a1220;
  --hara-live-ink: #dff4ff;
  --hara-live-muted: #9ab3c7;
  --hara-live-accent: #41f5e4;
  --hara-live-accent-2: #ff2e88;
  --hara-live-border: #1c2c40;
  --hara-live-error: #ff5470;
  --hara-live-mono-font: "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  color: var(--hara-live-ink);
  background: var(--hara-live-bg);
  border: 1px solid var(--hara-live-border);
  border-radius: 10px;
  font-family: var(--hara-live-mono-font);
  font-size: 14px;
  line-height: 1.5;
}

/* Example selection is the top edge of the embed. Runtime controls live in a
   separate row underneath so tabs never compete with Eval/Run for width. */
.hara-live-card-header {
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0 8px;
  padding: 0 12px 8px;
  background: var(--hara-live-panel);
  border-bottom: 1px solid var(--hara-live-border);
}

.hara-live-card-status {
  grid-column: 1;
  grid-row: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 88px;
  color: var(--hara-live-muted);
  font-size: 12px;
  white-space: nowrap;
}

.hara-live-card-connection {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  background: var(--hara-live-muted);
  border-radius: 50%;
}

.hara-live-card[data-connection-state="loading"] .hara-live-card-connection,
.hara-live-card[data-connection-state="busy"] .hara-live-card-connection {
  background: var(--hara-live-accent);
  animation: hara-live-pulse 1s ease-in-out infinite;
}

.hara-live-card[data-connection-state="ready"] .hara-live-card-connection {
  background: var(--hara-live-accent);
}

.hara-live-card[data-connection-state="error"] .hara-live-card-connection {
  background: var(--hara-live-error);
}

@keyframes hara-live-pulse {
  50% { opacity: 0.35; }
}

.hara-live-card-header button,
.hara-live-card-playground {
  min-height: 30px;
  box-sizing: border-box;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
}

.hara-live-card-header > button {
  grid-row: 2;
  padding: 4px 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.hara-live-card-header button:disabled {
  cursor: wait;
  opacity: 0.5;
}

.hara-live-card-eval {
  grid-column: 2;
  color: var(--hara-live-ink);
  background: transparent;
  border: 1px solid var(--hara-live-border);
}

.hara-live-card-eval:hover:not(:disabled),
.hara-live-card-eval:focus-visible {
  border-color: var(--hara-live-muted);
  outline: none;
}

.hara-live-card-run {
  grid-column: 3;
  color: var(--hara-live-bg);
  background: var(--hara-live-accent);
  border: 1px solid var(--hara-live-accent);
}

.hara-live-card-run:hover:not(:disabled),
.hara-live-card-run:focus-visible {
  filter: brightness(1.08);
  outline: none;
}

.hara-live-card-tabs {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  min-width: 0;
  gap: 2px;
  margin: 0 -12px 8px;
  padding: 8px 12px 0;
  overflow-x: auto;
  background: color-mix(in srgb, var(--hara-live-panel) 82%, var(--hara-live-bg));
  border-bottom: 1px solid var(--hara-live-border);
  scrollbar-width: none;
  overscroll-behavior-inline: contain;
}

.hara-live-card-tabs::-webkit-scrollbar {
  display: none;
}

.hara-live-card-tabs button {
  min-height: 34px;
  flex: 0 0 auto;
  padding: 5px 13px 7px;
  color: var(--hara-live-muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 7px 7px 0 0;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.hara-live-card-tabs button:hover:not(:disabled),
.hara-live-card-tabs button:focus-visible {
  color: var(--hara-live-ink);
  background: color-mix(in srgb, var(--hara-live-accent) 7%, transparent);
  outline: none;
}

.hara-live-card-tabs button[aria-selected="true"] {
  color: var(--hara-live-ink);
  background: var(--hara-live-bg);
  border-bottom-color: var(--hara-live-accent);
}

.hara-live-card-playground {
  grid-column: 5;
  grid-row: 2;
  display: inline-flex;
  align-items: center;
  justify-self: end;
  padding: 4px 10px;
  color: var(--hara-live-accent);
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid var(--hara-live-border);
}

.hara-live-card-playground:hover,
.hara-live-card-playground:focus-visible {
  border-color: var(--hara-live-accent);
  outline: none;
}

/* Editor surface: highlight overlay under a transparent textarea,
   same pattern as the workbench (website/v1.html .editor-surface). */
.hara-live-card-editor {
  position: relative;
  height: 230px;
  min-height: 150px;
  max-height: 80vh;
  overflow: hidden;
}

.hara-live-card-editor .code-highlight,
.hara-live-card-editor .code-highlight code,
.hara-live-card-editor textarea {
  margin: 0;
  font-family: var(--hara-live-mono-font);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
}

.hara-live-card-editor .code-highlight code,
.hara-live-card-editor textarea {
  display: block;
  padding: 12px 14px;
}

.hara-live-card-editor .code-highlight {
  position: absolute;
  inset: 0 0 12px;
  overflow: hidden;
  color: var(--hara-live-ink);
  pointer-events: none;
}

.hara-live-card-editor textarea {
  position: absolute;
  inset: 0 0 12px;
  width: 100%;
  height: calc(100% - 12px);
  box-sizing: border-box;
  overflow: auto;
  color: transparent;
  caret-color: var(--hara-live-accent);
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
}

.hara-live-card-editor textarea::selection {
  background: color-mix(in srgb, var(--hara-live-accent) 28%, transparent);
}

.hara-live-card[data-instarepl="true"] .hara-live-card-editor textarea {
  touch-action: pan-y;
}

/* Highlight token colors (classes emitted by highlightHara). */
.hara-live-card .code-highlight .comment { color: #5b7086; }
.hara-live-card .code-highlight .string { color: #ffd479; }
.hara-live-card .code-highlight .keyword { color: var(--hara-live-accent-2); }
.hara-live-card .code-highlight .paren-0 { color: #41f5e4; }
.hara-live-card .code-highlight .paren-1 { color: #ff2e88; }
.hara-live-card .code-highlight .paren-2 { color: #ffd479; }
.hara-live-card .code-highlight .paren-3 { color: #8af579; }
.hara-live-card .code-highlight .paren-4 { color: #7da7ff; }
.hara-live-card .code-highlight .paren-5 { color: #d18aff; }
.hara-live-card .code-highlight .unmatched {
  color: var(--hara-live-error);
  text-decoration: underline wavy;
}
.hara-live-card .code-highlight .eval-target {
  background: color-mix(in srgb, var(--hara-live-accent) 18%, transparent);
}

.hara-live-card-resizer {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  height: 12px;
  cursor: ns-resize;
  touch-action: none;
  background:
    linear-gradient(90deg, transparent, var(--hara-live-border) 35%, var(--hara-live-border) 65%, transparent)
    center / 52px 1px no-repeat,
    var(--hara-live-panel);
  border-top: 1px solid color-mix(in srgb, var(--hara-live-border) 72%, transparent);
}

.hara-live-card-resizer::after {
  position: absolute;
  top: 3px;
  left: calc(50% - 12px);
  width: 24px;
  height: 4px;
  content: "";
  border-top: 1px solid var(--hara-live-muted);
  border-bottom: 1px solid var(--hara-live-muted);
  opacity: 0.55;
}

.hara-live-card-resizer:hover,
.hara-live-card-resizer:focus-visible,
[data-resizing="true"] > .hara-live-card-resizer {
  background-color: color-mix(in srgb, var(--hara-live-accent) 8%, var(--hara-live-panel));
  outline: none;
}

.hara-live-card-output {
  min-height: 1.5em;
  padding: 10px 14px;
  color: var(--hara-live-ink);
  border-top: 1px solid var(--hara-live-border);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.hara-live-card-output[data-mode="eval"]::before {
  color: var(--hara-live-accent);
  content: "=> ";
}

.hara-live-card-output[data-state="pending"] { color: var(--hara-live-muted); }
.hara-live-card-output[data-state="error"] { color: var(--hara-live-error); }
.hara-live-card-output[data-state="error"]::before { color: var(--hara-live-error); }

/* Canvas panel */
.hara-live-card-canvas-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: min(500px, 52vh);
  min-height: 220px;
  max-height: 80vh;
  box-sizing: border-box;
  overflow: hidden;
  padding-bottom: 12px;
  border-top: 1px solid var(--hara-live-border);
}

.hara-live-card-canvas-panel[hidden] {
  display: none;
}

.hara-live-card-canvas-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  color: var(--hara-live-muted);
  background: var(--hara-live-panel);
  font-size: 11px;
  letter-spacing: 0.06em;
}

.hara-live-card-canvas-meta output[data-state="ready"] { color: var(--hara-live-accent); }
.hara-live-card-canvas-meta output[data-state="error"] { color: var(--hara-live-error); }

.hara-live-card-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #02050b;
  outline: none;
}

/* Kernel progress is intentionally represented only by the connection dot.
   An overlay obscures the editor/canvas and is especially disruptive on phones. */
.hara-live-card-toast {
  display: none !important;
}

@media (max-width: 760px) {
  .hara-live-card-header {
    grid-template-columns: auto auto auto minmax(0, 1fr);
    gap: 0 6px;
    padding: 0 8px 7px;
  }

  .hara-live-card-tabs {
    margin-inline: -8px;
    padding-inline: 8px;
  }

  .hara-live-card-status {
    min-width: 14px;
  }

  .hara-live-card-status small {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .hara-live-card-header > button {
    padding-inline: 11px;
  }

  .hara-live-card-playground {
    grid-column: 4;
    padding-inline: 8px;
  }

  .hara-live-card-editor {
    height: 210px;
    min-height: 170px;
  }

  .hara-live-card-canvas-panel {
    height: min(420px, 58vh);
  }
}

@media (max-width: 430px) {
  .hara-live-card-header {
    grid-template-columns: auto auto auto minmax(0, 1fr);
  }

  .hara-live-card-playground {
    font-size: 10px;
    letter-spacing: -0.01em;
  }
}
