:root {
  --bg: #18181b;
  --bg-panel: #1f1f23;
  --bg-input: #0e0e10;
  --border: #303034;
  --text: #efeff1;
  --text-dim: #adadb8;
  --accent: #9147ff;
  --accent-hover: #772ce8;
}

body.light-mode {
  --bg: #f2f2f5;
  --bg-panel: #ffffff;
  --bg-input: #fafafa;
  --border: #d8d8dc;
  --text: #18181b;
  --text-dim: #53535f;
  --accent: #9147ff;
  --accent-hover: #772ce8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Form controls don't inherit the body font by default in most
   browsers - force them to match so buttons/inputs/textarea look
   consistent with the rest of the UI */
button,
input,
textarea,
select {
  font-family: inherit;
}

button {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}

button:hover {
  border-color: var(--accent);
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  font-weight: 600;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn svg {
  flex-shrink: 0;
}

.delete-btn {
  display: inline-flex;
  align-items: center;
}

/* ---- App shell ---- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.draft-title {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 8px 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.toolbar-hint {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.toolbar-hint svg {
  flex-shrink: 0;
}

.toolbar-dropdown {
  position: relative;
}

.color-swatch-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  z-index: 5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.color-swatch-menu.open {
  display: grid;
}

.color-swatch-menu .swatch {
  font-size: 18px;
  line-height: 1;
  padding: 5px;
  border-radius: 6px;
}

/* ---- Tab bar: quick one-click switching between panels, separate
   from the history drawer (which handles delete/export/import) ---- */

.tab-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px 0;
}

.tab-list {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
}

.tab {
  display: flex;
  align-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  flex-shrink: 0;
  overflow: hidden;
}

.tab.active {
  background: var(--bg-panel);
  border-color: var(--border);
}

.tab-label {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 7px 4px 7px 14px;
  font-size: 13px;
  white-space: nowrap;
  color: var(--text-dim);
}

.tab-label:hover {
  color: var(--text);
}

.tab.active .tab-label {
  color: var(--text);
  font-weight: 600;
}

.tab-delete {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 6px 10px 6px 4px;
  color: var(--text-dim);
  opacity: 0.6;
}

.tab-delete:hover {
  opacity: 1;
  color: var(--text);
}

.tab-add {
  border-radius: 8px;
  font-weight: 700;
  padding: 7px 12px;
}

/* ---- Workspace: two independent panes with breathing room between
   them, instead of bordered dashboard columns ---- */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
  gap: 18px;
  padding: 18px;
  overflow: hidden;
}

.editor-pane,
.preview-pane {
  background: var(--bg-panel);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.editor {
  flex: 1;
  min-height: 280px;
  resize: vertical;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  line-height: 1.6;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.char-count {
  font-size: 12px;
  color: var(--text-dim);
}

.char-count.warn {
  color: #f0a020;
}

.char-count.over {
  color: #ff5c5c;
}

.footer-buttons {
  display: flex;
  gap: 6px;
}

.preview-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preview-pane h2 {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0 0 10px;
}

.preview-disclaimer {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 10px;
}

/* This block mimics Twitch's actual info-panel rendering style.
   It has its own dark/light toggle (independent of the editor's own
   theme) because real Twitch viewers see panels in whichever theme
   *they* picked, not whichever theme the streamer's editor used. */
.twitch-panel-preview {
  background: #18181b;
  color: #efeff1;
  border-radius: 6px;
  padding: 16px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  /* Twitch's actual UI/body font is Inter (Roobert is their custom
     heading font but it isn't publicly distributed) */
  font-family: "Inter", "Hiragino Sans", "Yu Gothic", sans-serif;
}

.twitch-panel-preview.light-theme {
  background: #f7f7f8;
  color: #0e0e10;
}

.twitch-panel-preview.light-theme h1,
.twitch-panel-preview.light-theme h2,
.twitch-panel-preview.light-theme h3 {
  color: #0e0e10;
}

.twitch-panel-preview.light-theme a {
  color: #772ce8;
}

.twitch-panel-preview.light-theme blockquote {
  border-left-color: #c4c4c9;
  color: #53535f;
}

.twitch-panel-preview.light-theme hr {
  border-top-color: #c4c4c9;
}

.preview-title {
  font-weight: 700;
  font-size: 1.05em;
  margin-bottom: 8px;
}

.preview-panel-image {
  display: block;
  max-width: 320px;
  width: 100%;
  height: auto;
  border-radius: 4px;
  margin-bottom: 10px;
}

.twitch-panel-preview h1,
.twitch-panel-preview h2,
.twitch-panel-preview h3 {
  color: #efeff1;
  margin: 0.6em 0 0.3em;
}

.twitch-panel-preview h1 { font-size: 1.4em; }
.twitch-panel-preview h2 { font-size: 1.2em; }
.twitch-panel-preview h3 { font-size: 1.05em; }

.twitch-panel-preview p {
  margin: 0.4em 0;
}

.twitch-panel-preview a {
  color: #bf94ff;
  text-decoration: underline;
}

.twitch-panel-preview blockquote {
  border-left: 3px solid #53535f;
  margin: 0.4em 0;
  padding-left: 10px;
  color: #adadb8;
}

.twitch-panel-preview hr {
  border: none;
  border-top: 1px solid #53535f;
  margin: 0.8em 0;
}

.twitch-panel-preview ul,
.twitch-panel-preview ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}

/* ---- History drawer (off-canvas) ---- */

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

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

.history-drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 280px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 11;
}

.history-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.drawer-header h2 {
  font-size: 15px;
  margin: 0;
}

.history-list {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
}

.history-item {
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.history-item:hover {
  background: var(--bg-input);
}

.history-item.active {
  background: var(--accent);
  color: white;
}

.history-item .item-meta {
  font-size: 11px;
  color: var(--text-dim);
}

.history-item.active .item-meta {
  color: rgba(255, 255, 255, 0.8);
}

.history-item .delete-btn {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  font-size: 14px;
}

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

.drawer-footer {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  gap: 6px;
}

.drawer-footer button {
  flex: 1;
}

/* ---- Modals ---- */

.modal {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  max-width: 420px;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.modal h3 {
  margin-top: 0;
}

.modal ul {
  padding-left: 1.2em;
  font-size: 13px;
  line-height: 1.7;
}

.usage-list {
  margin: 0 0 16px;
}

.usage-item {
  margin-bottom: 12px;
}

.usage-item:last-child {
  margin-bottom: 0;
}

.usage-item dt {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 2px;
}

.usage-item dd {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
}

.modal-note {
  font-size: 12px;
  color: var(--text-dim);
}

.modal-field {
  display: block;
  font-size: 13px;
  margin-bottom: 10px;
}

.modal-field input {
  width: 100%;
  margin-top: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
}

.image-preview-wrap {
  display: none;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.image-preview-wrap.open {
  display: flex;
}

.image-preview-wrap img {
  max-width: 120px;
  max-height: 90px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.spec-table {
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
  margin-bottom: 14px;
}

.spec-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}

.spec-table code {
  background: var(--bg-input);
  padding: 2px 4px;
  border-radius: 4px;
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
}
