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

:root {
  --bg:          #fff5f7;
  --surface:     #ffffff;
  --surface2:    #fff0f4;
  --border:      #f0dde5;
  --accent:      #e84393;
  --accent-hover:#c9377e;
  --accent-light:#f78fb3;
  --text:        #444;
  --text-muted:  #888;
  --success:     #155724;
  --error:       #721c24;
  --radius:      8px;
  --shadow:      0 8px 30px rgba(255, 105, 135, 0.12);
  --font-mono:   "JetBrains Mono", "Fira Code", "Cascadia Code", ui-monospace, monospace;
}

body {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 30%, #ff9a9e 60%, #fecfef 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  padding: 20px 32px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  box-shadow: 0 2px 12px rgba(255, 105, 135, 0.1);
}

header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

header h1 span {
  color: var(--accent);
}

.subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.back-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  opacity: 0.85;
  font-weight: 500;
  transition: opacity 0.15s;
}
.back-link:hover { opacity: 1; }

/* ── Layout ── */
.layout {
  display: flex;
  flex: 1;
  gap: 16px;
  padding: 20px;
  min-height: 0;
  overflow: hidden;
}

/* ── Editor pane ── */
.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 28px;
  gap: 16px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.field-row label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.field-row input[type="text"] {
  flex: 1;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.2s;
}
.field-row input[type="text"]:focus {
  border-color: var(--accent-light);
}

.editor-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

textarea#entry-area {
  flex: 1;
  width: 100%;
  min-height: 0;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.7;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
textarea#entry-area:focus { border-color: var(--accent-light); }
textarea#entry-area::placeholder { color: #ccc; }

.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.hint { font-size: 0.78rem; }

.hint code {
  background: #fff0f4;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
}

/* ── Actions ── */
.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.15s;
  outline: none;
}

button:hover { transform: translateY(-2px); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent) 100%);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { opacity: 0.92; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 2px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent-light); color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  padding: 7px 13px;
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--accent-light); transform: none; }

/* ── Sidebar (history) ── */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}

.sidebar-header {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header span:last-child {
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.history-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.83rem;
}

.history-item {
  padding: 12px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.history-item:hover {
  background: var(--surface2);
  border-color: var(--border);
}

.history-item.active {
  background: #fff0f6;
  border-color: var(--accent-light);
}

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

.history-item-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-item-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.history-item-actions button {
  font-size: 0.75rem;
  padding: 4px 9px;
}

/* ── Status bar ── */
#status-bar {
  min-height: 28px;
  display: flex;
  align-items: center;
  font-size: 0.83rem;
}

#status-bar.show { animation: fadeIn 0.15s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.status-success { color: #2e7d32; }
.status-error   { color: var(--error); }
.status-info    { color: var(--text-muted); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-light); }

/* ── ChatGPT tip ── */
.chatgpt-tip {
  margin: 12px;
  padding: 14px;
  background: #fff5f7;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
}

.chatgpt-tip-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
}

.chatgpt-tip-toggle {
  font-size: 0.7rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.chatgpt-tip.collapsed .chatgpt-tip-content {
  display: none;
}

.chatgpt-tip.collapsed .chatgpt-tip-toggle {
  transform: rotate(-90deg);
}

.chatgpt-tip.collapsed .chatgpt-tip-title {
  margin-bottom: 0;
}

.chatgpt-tip-body {
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

.chatgpt-tip-body code {
  color: var(--accent);
  font-family: var(--font-mono);
}

.chatgpt-prompt {
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  color: #666;
  font-size: 0.76rem;
  line-height: 1.6;
  user-select: all;
  white-space: pre-wrap;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: break-word;
}

.chatgpt-prompt em {
  color: var(--accent);
  font-style: normal;
  font-family: var(--font-mono);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  body { height: auto; overflow: auto; }
  .layout { flex-direction: column; gap: 12px; padding: 14px; overflow: visible; }
  .sidebar { width: 100%; overflow-y: visible; }
  header { padding: 16px 20px 14px; }
  .editor-pane { padding: 18px 16px; overflow: visible; }
  textarea#entry-area { min-height: 300px; }
}
