:root {
  --bg-page: #0d0a07;
  --bg-card: #1a1410;
  --bg-card-hover: #241c14;
  --border: rgba(204, 170, 120, 0.2);
  --border-focus: rgba(204, 153, 102, 0.45);
  --text: #f5ede4;
  --text-muted: #b8a08a;
  --accent: #cc9966;
  --accent-dim: rgba(204, 153, 102, 0.22);
  --radius: 10px;
  --radius-sm: 6px;
}

* {
  box-sizing: border-box;
}

body[data-page="chatlog"] {
  margin: 0;
  font-family: "Barlow", -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.chatlog-shell {
  width: min(1500px, 100% - 28px);
  margin: 18px auto 36px;
  display: block;
}

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px;
}

/* Header */
.header {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
}

.logo-wrap {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.logo-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.logo-text {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
  flex: 1;
  min-width: 200px;
}

/* Main grid */
.main {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 960px) {
  .main {
    grid-template-columns: 1fr;
  }
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.15s, background 0.15s;
}

.card:hover {
  background: var(--bg-card-hover);
}

.card-head {
  margin-bottom: 14px;
}

.card-head--row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.card-label {
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Screens section */
.screens-section {
  grid-row: 1;
}

.screen-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.screen-tab {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.screen-tab:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.screen-tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.screen-tab .tab-remove {
  margin-left: 6px;
  opacity: 0.6;
  font-size: 14px;
  line-height: 1;
}

.screen-tab .tab-remove:hover {
  opacity: 1;
  color: #f44;
}

.paste-section-inner {
  margin-bottom: 16px;
}

.section-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.screen-bg-section {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.input-hidden {
  position: absolute;
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* Characters */
.characters-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
}

.character-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.character-chip:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.character-chip.selected {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.character-chip .chip-remove {
  margin-left: 2px;
  opacity: 0.6;
  font-size: 14px;
  line-height: 1;
}

.character-chip .chip-remove:hover {
  opacity: 1;
  color: #f44;
}

/* Paste */
.paste-input {
  width: 100%;
  min-height: 160px;
}

.paste-input {
  width: 100%;
  min-height: 200px;
  padding: 14px 16px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  margin-bottom: 12px;
}

.paste-input::placeholder {
  color: var(--text-muted);
}

.paste-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.paste-actions {
  display: flex;
  gap: 10px;
}

/* Buttons */
.btn {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #1a1208;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-dl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--accent);
  border: 1px solid var(--accent-dim);
}

.btn-dl:hover {
  background: var(--accent-dim);
  color: #f5ede4;
}

.btn-icon {
  opacity: 0.9;
}

/* Options panel — scrollable, scrollbar hidden */
.options-panel {
  grid-row: 1 / -1;
  max-height: 90vh;
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.options-panel::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.options-group {
  margin-bottom: 20px;
}

.options-group:last-child {
  margin-bottom: 0;
}

.options-group-title {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 4px;
}

.options-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.option {
  margin-bottom: 12px;
}

.option--indent {
  margin-left: 12px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
}

.option label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.option-val {
  min-width: 36px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.option-num {
  width: 90px;
  padding: 8px 10px;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.option-text {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.option-text::placeholder {
  color: var(--text-muted);
}

.option-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.option input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.option select {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
}

.option input[type="color"] {
  width: 36px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
}

.hex-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-size: 12px;
  font-family: monospace;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.color-overrides {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.color-overrides label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
}

.color-overrides input[type="color"] {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
}

/* Preview */
.preview-section {
  grid-row: 2;
}

.preview-screen-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* Editor layout — Photopea-style, compact */
.editor-section .card-head {
  margin-bottom: 6px;
}

.editor-layout {
  display: flex;
  gap: 0;
  min-height: 360px;
}

.editor-toolbar {
  width: 44px;
  flex-shrink: 0;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  padding: 6px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.tool-btn {
  width: 34px;
  height: 34px;
  margin: 0 5px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.tool-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.tool-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.tool-icon {
  width: 20px;
  height: 20px;
  display: block;
  background: currentColor;
}

.tool-icon-move {
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M5 9l-3 3 3 3M9 5l3-3 3 3M15 19l-3 3-3-3M19 9l3 3-3 3'/%3E%3C/svg%3E") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M5 9l-3 3 3 3M9 5l3-3 3 3M15 19l-3 3-3-3M19 9l3 3-3 3'/%3E%3C/svg%3E") center/contain no-repeat;
}

.tool-icon-crop {
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M6 3v18M18 3v18M3 6h18M3 18h18'/%3E%3C/svg%3E") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M6 3v18M18 3v18M3 6h18M3 18h18'/%3E%3C/svg%3E") center/contain no-repeat;
}

.tool-icon-image {
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E") center/contain no-repeat;
}

.tool-icon-text-fit {
  font-size: 14px;
  font-weight: 700;
  width: auto;
  height: auto;
  background: none;
}

.tool-icon-reset {
  font-size: 18px;
  width: auto;
  height: auto;
  background: none;
}

.tool-sep {
  width: 20px;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.editor-canvas-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #0d0d0f;
  border: 1px solid var(--border);
  border-left: none;
}

.editor-canvas-bar {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
}

.editor-canvas-bar .preview-exact-hint {
  margin: 0;
  font-size: 0.7rem;
}

.editor-download-bar {
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  gap: 6px;
}

.editor-download-bar .btn {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.editor-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.panel-tab {
  flex: 1;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

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

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

.editor-panel-content {
  flex: 1;
  overflow: auto;
  padding: 8px 10px;
}

.editor-panel {
  display: none;
}

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

.layer-props {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.layer-props label {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.layer-opacity-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layer-opacity-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.layer-opacity-target {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.layers-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.layer-item:hover {
  background: rgba(255,255,255,0.04);
}

.layer-item.selected {
  background: var(--accent-dim);
}

.layer-visibility {
  width: 20px;
  cursor: pointer;
  opacity: 0.8;
  font-size: 14px;
  user-select: none;
}

.layer-visibility.hidden {
  opacity: 0.35;
}

.layer-thumb {
  width: 26px;
  height: 26px;
  border-radius: 3px;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.layer-name {
  font-size: 11px;
  flex: 1;
  min-width: 0;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.history-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.history-empty {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

.editor-panel-canvas .options-group-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}

.editor-panel-canvas .option {
  margin-bottom: 6px;
}

.editor-panel-canvas .option label {
  font-size: 10px;
}

.editor-panel-canvas .option-num {
  width: 100%;
  max-width: 100px;
  box-sizing: border-box;
  padding: 4px 6px;
  font-size: 11px;
}

.preview-exact-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: -8px 0 10px 0;
}

.preview-viewport {
  overflow: auto;
  max-height: 70vh;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  background: #0a0a0a;
  box-sizing: border-box;
  display: inline-block;
  position: relative;
}

.preview-viewport--cropped {
  overflow: hidden;
  margin-left: 0;
}

.preview-stage {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.preview-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.preview-bg {
  z-index: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.preview-stage[data-tool="move-image"] .preview-bg {
  pointer-events: auto;
  cursor: move;
}

.preview-overlay {
  z-index: 1;
  background: #000;
}

.preview-text-wrap {
  position: absolute;
  z-index: 2;
  cursor: default;
  max-width: 100%;
  box-sizing: border-box;
}

.preview-stage[data-tool="move-text"] .preview-text-wrap {
  cursor: move;
}

.preview-box {
  font-weight: 700;
  text-align: left;
  word-break: break-word;
  display: inline-block;
  min-width: 80px;
  box-sizing: border-box;
}

.preview-crop {
  position: absolute;
  z-index: 10;
  border: 2px dashed var(--accent);
  box-sizing: border-box;
  pointer-events: none;
}

.preview-crop:not(.hidden) {
  pointer-events: auto;
}

.preview-crop .crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: auto;
  cursor: pointer;
}

.preview-crop .crop-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.preview-crop .crop-n  { top: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
.preview-crop .crop-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.preview-crop .crop-e  { right: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }
.preview-crop .crop-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.preview-crop .crop-s  { bottom: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
.preview-crop .crop-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.preview-crop .crop-w  { left: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }

.preview-crop.hidden {
  display: none !important;
}

/* Export container: no UI chrome so it never appears in downloaded image */
.export-container,
.export-container * {
  outline: none !important;
  box-shadow: none !important;
}
.export-container {
  border: none !important;
}

.preview-box .line {
  display: block;
  margin-bottom: 0.3em;
}

.preview-box .line:last-child {
  margin-bottom: 0;
}

.preview-box .segment {
  white-space: pre-wrap;
}

.download-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Footer */
.footer {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-logo {
  width: 20px;
  height: 20px;
  opacity: 0.7;
  object-fit: contain;
}

/* Conditional option visibility */
#wrapCanvasHeight {
  display: none;
}

.editor-sidebar[data-height-mode="fixed"] #wrapCanvasHeight,
.options-panel[data-height-mode="fixed"] #wrapCanvasHeight {
  display: block;
}

#wrapBgColor {
  display: none;
}

.options-panel[data-bg-custom="true"] #wrapBgColor {
  display: block;
}

body[data-page="chatlog"] .topbar .btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 0.95rem;
}

body[data-page="chatlog"] .topbar .btn-discord {
  background: linear-gradient(145deg, #d9ad80, #cc9966 58%);
  color: #fff;
  box-shadow: 0 10px 24px rgba(204, 153, 102, 0.44);
}

body[data-page="chatlog"] .topbar .btn-discord:hover {
  filter: none;
}

body[data-page="chatlog"] .account-caret {
  opacity: 0.85;
}
