:root {
  color-scheme: dark;
  --bg: #090a0c;
  --surface: #111317;
  --surface-2: #171a1f;
  --surface-3: #1d2127;
  --border: #292d34;
  --border-strong: #3a4049;
  --text: #f4f5f6;
  --muted: #9298a2;
  --accent: #b8ef65;
  --accent-dark: #11180a;
  --danger: #ff7272;
  --danger-bg: #2a1518;
  --success: #7de2a1;
  --radius: 12px;
  --sidebar: 224px;
  --content: 1040px;
}

* { box-sizing: border-box; }
html { min-width: 0; background: var(--bg); }
body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; }
a { color: inherit; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 2px;
}
.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  transform: translateY(-160%);
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
}
.skip-link:focus { transform: none; }

header {
  position: fixed;
  z-index: 20;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--sidebar);
  min-width: 0;
  flex-direction: column;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: #0c0d10f2;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 6px 30px;
  color: var(--text);
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -.35px;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-dark);
  font-size: 15px;
}
header nav { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 4px; }
.nav-user {
  margin: 0 8px 12px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-user::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: var(--success); }
.nav-link, .nav-logout {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
}
.nav-link:hover, .nav-logout:hover, .nav-link.active { background: var(--surface-2); color: var(--text); }
.nav-link.active { font-weight: 650; }
.nav-icon { width: 18px; color: inherit; text-align: center; }
.logout-form { margin: auto 0 0; }

main {
  width: calc(100% - var(--sidebar));
  max-width: calc(var(--content) + clamp(48px, 8vw, 128px));
  min-width: 0;
  margin-left: var(--sidebar);
  padding: 42px clamp(24px, 5vw, 64px) 72px;
}
main > * { min-width: 0; }
h1, h2, h3 { color: var(--text); letter-spacing: -.45px; }
h1 { margin: 0 0 8px; font-size: clamp(28px, 4vw, 36px); line-height: 1.12; }
h2 { margin: 0; font-size: 19px; }
p { overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.page-head { display: flex; min-width: 0; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-head p { margin: 5px 0 0; }
.back { display: inline-flex; margin-bottom: 20px; color: var(--muted); font-size: 13px; text-decoration: none; }
.back:hover { color: var(--text); }

.card {
  width: 100%;
  min-width: 0;
  margin: 18px 0;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.card h2 { margin-bottom: 18px; }
.notice, .error {
  width: 100%;
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid #496130;
  border-radius: 9px;
  background: #16200f;
  color: #d7f7ab;
  overflow-wrap: anywhere;
}
.error { border-color: #71363c; background: var(--danger-bg); color: #ffc2c2; }
.empty { padding: 52px 24px; color: var(--muted); text-align: center; }

form { min-width: 0; }
label {
  display: block;
  margin: 17px 0 7px;
  color: #c4c8ce;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .055em;
  text-transform: uppercase;
}
input, textarea, select {
  display: block;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0c0e11;
  color: var(--text);
}
input, select { height: 44px; padding: 0 13px; }
textarea { min-height: 120px; padding: 12px 13px; resize: vertical; }
input:hover, textarea:hover, select:hover { border-color: var(--border-strong); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
::placeholder { color: #626873; opacity: 1; }
button, .button, .new-post {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
  padding: 0 16px;
  border: 1px solid var(--text);
  border-radius: 9px;
  background: var(--text);
  color: #101114;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
}
button:hover, .button:hover, .new-post:hover { filter: brightness(.9); }
button:disabled { cursor: not-allowed; opacity: .4; filter: none; }
.secondary-button { width: 100%; border-color: var(--border-strong); background: transparent; color: var(--text); }
.danger-button { border-color: #733a40; background: transparent; color: var(--danger); }
.mini-note { color: var(--muted); font-size: 12px; }
.mini-note a { color: var(--accent); }
.prompt-studio { margin: 22px 0; border-block: 1px solid var(--border); padding: 20px 0; }
.case-filter-grid { display: grid; min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.case-filter-grid > label { min-width: 0; }
#prompt-case { width: 100%; min-width: 0; max-width: 100%; text-overflow: ellipsis; }
.case-toolbar { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 9px; color: var(--muted); font-size: 12px; }
.case-toolbar .compact-button { width: auto; min-height: 36px; margin: 0; padding: 0 12px; }
.case-note { min-width: 0; margin: 10px 0 0; color: #b8bdc5; font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }
.prompt-advanced { min-width: 0; margin: 18px 0; border: 1px solid var(--border); border-radius: 9px; background: #0c0e11; }
.prompt-advanced summary { padding: 12px 13px; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 700; }
.prompt-advanced .prompt-grid { padding: 0 13px 13px; }
.prompt-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; min-width: 0; }
.prompt-grid > label { min-width: 0; }
.prompt-grid select { width: 100%; min-width: 0; }
#image-prompt { min-height: 220px; font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }
.prompt-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.prompt-meta a { color: var(--accent); white-space: nowrap; }
.generate-form button[aria-busy="true"] { cursor: wait; opacity: .72; }

.feed-shell { width: 100%; max-width: 900px; min-width: 0; }
.feed-header { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.feed-header p { margin: 5px 0 0; }
.new-post { flex: none; margin: 0; }
.feed-toolbar {
  position: sticky;
  z-index: 8;
  top: 0;
  display: flex;
  min-width: 0;
  min-height: 54px;
  align-items: center;
  gap: 14px;
  padding: 8px 2px;
  border-block: 1px solid var(--border);
  background: #090a0cf2;
  backdrop-filter: blur(12px);
}
.select-control { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--text); font-size: 13px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.select-control input, .feed-check { width: 17px; height: 17px; min-height: 0; margin: 0; padding: 0; accent-color: var(--accent); }
.selection-count { margin-right: auto; color: var(--muted); font-size: 12px; }
.feed-bulk { min-height: 34px; margin: 0; padding: 0 12px; border-color: #733a40; border-radius: 999px; background: transparent; color: var(--danger); font-size: 12px; }
.feed-list { min-width: 0; }
.feed-item { display: flex; min-width: 0; align-items: flex-start; gap: 13px; padding: 18px 2px; border-bottom: 1px solid var(--border); }
.feed-item:hover, .feed-item.is-selected { background: #ffffff04; }
.feed-item.is-selected { box-shadow: inset 3px 0 var(--accent); }
.feed-check { flex: none; margin-top: 5px; }
.feed-thumb { width: 64px; height: 64px; flex: none; border-radius: 10px; background: var(--surface-2); object-fit: cover; }
.feed-placeholder { display: grid; place-items: center; color: var(--accent); }
.feed-main { min-width: 0; flex: 1; }
.feed-title { overflow: hidden; color: var(--text); font-weight: 720; text-overflow: ellipsis; white-space: nowrap; }
.feed-caption { display: -webkit-box; margin-top: 3px; overflow: hidden; color: #adb1b8; font-size: 13px; line-height: 1.45; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.feed-url { display: block; max-width: 100%; margin-top: 6px; overflow: hidden; color: var(--accent); font-size: 12px; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.feed-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 9px; }
.feed-actions form { display: inline; margin: 0; }
.feed-actions a, .action-delete, .action-copy { min-height: 0; margin: 0; padding: 0; border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600; text-decoration: none; }
.feed-actions a:hover, .action-copy:hover { color: var(--text); filter: none; }
.action-delete:hover { color: var(--danger); filter: none; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 2px 0; color: var(--muted); font-size: 12px; }
.pagination a { color: var(--text); text-decoration: none; }
.pagination a:hover { color: var(--accent); }
.pagination .disabled { opacity: .35; }

.search-form { display: flex; min-width: 0; gap: 8px; margin-bottom: 14px; }
.search-form input { flex: 1; }
.search-form button { min-height: 44px; flex: none; margin: 0; }
.search-clear { display: inline-flex; align-items: center; padding: 0 8px; color: var(--muted); font-size: 13px; text-decoration: none; }
.search-clear:hover { color: var(--text); }

.settings-head { margin-bottom: 20px; }
.settings-head p { margin: 5px 0 0; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 18px; max-width: 980px; align-items: start; }
.settings-grid > * { min-width: 0; }
.settings-card { margin: 0 0 18px; }
.settings-section { margin-top: 32px; }

.preview-card { max-width: 760px; margin: 0 auto; }
.preview-image { display: block; width: auto; max-width: 100%; max-height: 560px; margin: 0 auto 22px; border-radius: 10px; }
.preview-title { font-size: clamp(26px, 5vw, 34px); }
.preview-caption { color: #c4c7cd; font-size: 16px; line-height: 1.7; white-space: pre-wrap; }
.preview-link { margin-top: 18px; overflow-wrap: anywhere; }
.preview-link a { color: var(--accent); }
.edit-image, .generated-image { display: block; width: auto; max-width: 100%; max-height: 420px; margin-bottom: 18px; border-radius: 10px; }
.login-card { max-width: 430px; margin: clamp(30px, 10vh, 100px) auto 0; }
.login-card h1 { margin-bottom: 22px; }
.api-result { margin: 10px 0; padding: 13px; border: 1px solid var(--border); border-radius: 9px; background: #0c0e11; }
.api-result-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.api-detail { max-height: 180px; margin: 9px 0 0; padding: 10px; overflow: auto; border-radius: 7px; background: #07080a; color: #adb2bb; font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.status-ok { color: var(--success); font-weight: 750; }
.status-fail { color: var(--danger); font-weight: 750; }

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

@media (max-width: 760px) {
  :root { --sidebar: 0px; }
  header {
    position: sticky;
    inset: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
  }
  .brand { flex: none; margin: 0 auto 0 0; font-size: 15px; }
  .brand-mark { width: 25px; height: 25px; }
  header nav { flex: none; flex-direction: row; align-items: center; gap: 2px; }
  .nav-user, .nav-icon { display: none; }
  .nav-link, .nav-logout { width: auto; min-height: 38px; padding: 8px 9px; font-size: 12px; }
  .logout-form { margin: 0; }
  main { width: 100%; max-width: none; margin: 0; padding: 26px 14px 48px; }
  .feed-toolbar { top: 59px; }
  .feed-header { align-items: center; }
  .feed-header .muted { display: none; }
  .feed-thumb { width: 54px; height: 54px; }
  .settings-card, .card { padding: 19px; }
  .case-filter-grid { grid-template-columns: 1fr; }
  .prompt-grid { grid-template-columns: 1fr; }
  .prompt-meta { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 480px) {
  .brand-text { display: none; }
  .page-head, .feed-header { align-items: stretch; }
  .feed-header h1 { font-size: 27px; }
  .new-post { min-height: 40px; padding: 0 13px; font-size: 13px; }
  .selection-count { display: none; }
  .select-control span { display: none; }
  .feed-item { gap: 10px; }
  .feed-thumb { width: 48px; height: 48px; }
  .feed-actions { gap: 13px; }
  .search-form { flex-wrap: wrap; }
  .search-form input { flex-basis: calc(100% - 90px); }
  .pagination { gap: 8px; }
  .page-status { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
