:root {
  color-scheme: dark;
  --bg: #080e1c;
  --surface: #101a30;
  --surface-2: #0d162a;
  --surface-3: #15213a;
  --border: #2c3a57;
  --border-bright: #445476;
  --text: #f4f1ee;
  --muted: #98a7c8;
  --muted-2: #7282a3;
  --violet: #7557ff;
  --violet-light: #9b87ff;
  --coral: #ff786e;
  --danger: #ff8b83;
  --radius: 16px;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
  font-family: "Segoe UI Variable Text", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -10%, rgba(54, 71, 120, 0.2), transparent 38%),
    linear-gradient(160deg, #0a1122 0%, #080e1c 68%, #080c18 100%);
  overflow-x: hidden;
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, .dropzone:focus-visible {
  outline: 2px solid var(--violet-light);
  outline-offset: 3px;
}

.hidden { display: none !important; }

.ambient {
  position: fixed;
  pointer-events: none;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.12;
}
.ambient-one { width: 420px; height: 420px; background: var(--violet); left: -260px; top: 16%; }
.ambient-two { width: 360px; height: 360px; background: var(--coral); right: -280px; bottom: 8%; }

.edge-glow { position: relative; isolation: isolate; }
.edge-glow::before {
  content: "";
  position: absolute;
  inset: -1px;
  padding: 1px;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--violet) 0%, rgba(117, 87, 255, 0.12) 52%, var(--coral) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  z-index: 2;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 29px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -1.5px;
}
.brand span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--coral));
  box-shadow: 0 0 18px rgba(117, 87, 255, 0.7);
}
.brand-large { font-size: 52px; justify-content: center; }
.brand-large span { width: 13px; height: 13px; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 48px 20px;
  position: relative;
}

.canvas-lines {
  position: absolute;
  width: min(1050px, 86vw);
  height: min(680px, 74vh);
  border: 1px dashed rgba(99, 119, 160, 0.3);
  background-image:
    linear-gradient(rgba(70, 91, 132, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(70, 91, 132, 0.1) 1px, transparent 1px);
  background-size: 20% 25%;
  opacity: 0.8;
}
.line-shape { position: absolute; display: block; background: linear-gradient(135deg, rgba(117,87,255,.2), rgba(255,120,110,.18)); }
.shape-a { width: 35%; height: 30%; left: 0; top: 38%; border-radius: 70% 40% 0 0; transform: skewY(-9deg); }
.shape-b { width: 34%; height: 37%; right: 7%; top: 13%; clip-path: polygon(0 20%, 100% 0, 100% 100%, 0 72%); }
.shape-c { width: 46%; height: 26%; left: 22%; bottom: 0; border-radius: 60% 70% 0 0; opacity: .45; }

.login-panel {
  width: min(512px, 100%);
  padding: 56px 46px 34px;
  border-radius: 18px;
  background: rgba(13, 22, 42, 0.94);
  border: 1px solid rgba(66, 82, 116, 0.8);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  z-index: 1;
}
.login-panel h1 { margin: 38px 0 6px; text-align: center; font-size: 32px; letter-spacing: -1.2px; }
.login-copy { margin: 0 0 30px; color: var(--muted); text-align: center; font-size: 16px; }

.field { display: grid; gap: 9px; margin-bottom: 18px; color: var(--text); font-size: 14px; font-weight: 600; }
.input-wrap, .textarea-wrap { display: block; position: relative; }
.input-wrap input, textarea {
  width: 100%;
  border: 1px solid var(--border-bright);
  color: var(--text);
  background: rgba(8, 15, 30, 0.6);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.input-wrap input { height: 58px; border-radius: 11px; padding: 0 52px 0 16px; font-size: 17px; letter-spacing: 2px; }
.input-wrap input:focus, textarea:focus { border-color: var(--violet-light); box-shadow: 0 0 0 3px rgba(117,87,255,.16); background: #0a1428; outline: none; }
.reveal {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.reveal:hover { color: var(--text); background: rgba(255,255,255,.05); }
.reveal svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.primary-button {
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 11px;
  color: white;
  background: linear-gradient(105deg, #6949ff, #815eff);
  box-shadow: 0 12px 30px rgba(93, 61, 255, 0.25);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease, box-shadow 150ms ease;
}
.primary-button:hover { transform: translateY(-1px); filter: brightness(1.08); box-shadow: 0 16px 36px rgba(93,61,255,.33); }
.primary-button:active { transform: translateY(0); }
.primary-button:disabled { opacity: .55; cursor: wait; transform: none; }

.form-error { min-height: 20px; margin: -2px 0 8px; color: var(--danger); font-size: 13px; font-weight: 500; }
.privacy-note {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 34px 0 0;
  padding-top: 25px;
  border-top: 1px solid var(--border);
  color: var(--muted-2);
  font-size: 13px;
}
.privacy-note svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.app-view { width: min(1500px, calc(100% - 56px)); margin: 0 auto; padding-bottom: 48px; }
.app-header { min-height: 82px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(55,70,100,.56); }
.header-brand { display: flex; align-items: center; gap: 18px; }
.header-brand p { margin: 0; color: var(--muted); font-size: 14px; }
.header-actions { display: flex; align-items: center; gap: 28px; }
.usage { padding-right: 28px; border-right: 1px solid var(--border); color: var(--text); font-size: 14px; white-space: nowrap; }
.usage strong { font-weight: 700; }
.logout-button {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 4px; border: 0; background: transparent; color: var(--coral); font-weight: 700; cursor: pointer;
}
.logout-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.logout-button:hover { color: #ff9a92; }

.config-warning {
  margin-top: 18px;
  padding: 14px 18px;
  border: 1px solid rgba(255,120,110,.45);
  border-radius: 11px;
  background: rgba(255,120,110,.08);
  color: #ffd4d1;
}
.config-warning div { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.config-warning span { color: #d8a5a1; font-size: 13px; }

.workspace { display: grid; grid-template-columns: minmax(420px, 0.92fr) minmax(480px, 1.08fr); gap: 18px; padding-top: 22px; }
.editor-panel, .result-panel, .history-section {
  border: 1px solid var(--border);
  background: linear-gradient(145deg, rgba(16,26,48,.96), rgba(10,18,35,.96));
  border-radius: var(--radius);
}
.editor-panel { padding: 28px; }
.section-heading h1, .section-heading h2 { margin: 0; letter-spacing: -.8px; font-size: 24px; line-height: 1.2; }
.section-heading p { margin: 6px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.dropzone {
  min-height: 210px;
  display: grid;
  place-items: center;
  margin: 22px 0 24px;
  border: 1px dashed #627295;
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 0%, rgba(96,118,177,.14), transparent 30%),
    radial-gradient(circle at 90% 100%, rgba(117,87,255,.08), transparent 36%),
    rgba(8,15,29,.38);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--violet-light); background-color: rgba(117,87,255,.06); }
.drop-empty { display: flex; flex-direction: column; align-items: center; text-align: center; }
.drop-empty svg { width: 52px; margin-bottom: 12px; fill: none; stroke: #9aa8d4; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.drop-empty strong { font-size: 15px; }
.drop-empty span { margin-top: 6px; color: var(--muted); font-size: 12px; }
.drop-preview { position: relative; width: 100%; height: 210px; }
.drop-preview img { width: 100%; height: 100%; object-fit: contain; background: #070d1a; }
.replace-image { position: absolute; right: 12px; bottom: 12px; padding: 7px 10px; border-radius: 8px; background: rgba(5,10,20,.82); color: white; font-size: 12px; font-weight: 600; backdrop-filter: blur(8px); }

.prompt-field { margin-bottom: 18px; }
textarea { height: 120px; resize: vertical; min-height: 100px; max-height: 220px; padding: 14px 16px 30px; border-radius: 10px; font-size: 14px; line-height: 1.5; }
textarea::placeholder { color: #7181a3; }
.textarea-wrap small { position: absolute; right: 12px; bottom: 10px; color: var(--muted-2); font-size: 11px; font-weight: 500; }

.options-row { display: flex; align-items: stretch; gap: 22px; margin-bottom: 20px; }
.options-row fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.options-row legend { display: flex; align-items: center; gap: 7px; margin-bottom: 10px; color: #dbe1ee; font-size: 12px; font-weight: 600; }
.options-row legend svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.option-divider { width: 1px; background: var(--border); }
.segmented { display: flex; gap: 6px; }
.fixed-option { width: 48px; height: 38px; display: grid; place-items: center; border: 1px solid var(--violet-light); border-radius: 8px; background: rgba(117,87,255,.22); color: white; font-size: 12px; font-weight: 700; box-shadow: inset 0 0 0 1px rgba(117,87,255,.2); }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { min-width: 48px; height: 38px; display: grid; place-items: center; border: 1px solid var(--border-bright); border-radius: 8px; color: #d9e0ef; font-size: 12px; font-weight: 600; transition: 150ms ease; }
.segmented label:hover span { border-color: #64749a; }
.segmented input:checked + span { border-color: var(--violet-light); background: rgba(117,87,255,.22); color: white; box-shadow: inset 0 0 0 1px rgba(117,87,255,.2); }
.segmented input:focus-visible + span { outline: 2px solid var(--violet-light); outline-offset: 2px; }
.edit-button { display: flex; align-items: center; justify-content: center; gap: 9px; }
.edit-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }

.result-panel { min-height: 682px; overflow: hidden; display: grid; place-items: center; }
.result-panel::after {
  content: ""; position: absolute; inset: auto -10% -34% 18%; height: 62%; border-radius: 50% 50% 0 0; border-top: 1px solid rgba(117,87,255,.34); background: radial-gradient(ellipse at top, rgba(117,87,255,.12), transparent 64%); pointer-events: none;
}
.result-empty, .result-loading { position: relative; z-index: 1; width: min(420px, 80%); text-align: center; }
.result-empty > svg { width: 76px; fill: rgba(117,87,255,.14); stroke: var(--violet-light); stroke-width: 1.4; }
.result-empty h2, .result-loading h2 { margin: 22px 0 8px; font-size: 26px; letter-spacing: -1px; }
.result-empty p, .result-loading p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.result-loading { animation: fadeIn 240ms ease; }
.loader-orbit { width: 68px; height: 68px; margin: 0 auto; border: 2px solid rgba(117,87,255,.2); border-top-color: var(--violet-light); border-radius: 50%; animation: spin 1s linear infinite; }
.loader-orbit span { width: 9px; height: 9px; display: block; margin: -3px auto 0; border-radius: 50%; background: var(--coral); box-shadow: 0 0 15px var(--coral); }
.result-ready { position: relative; z-index: 1; width: 100%; height: 100%; min-height: 682px; display: flex; flex-direction: column; animation: fadeIn 260ms ease; }
.result-ready > img { width: 100%; flex: 1; min-height: 0; object-fit: contain; background: #060b16; }
.result-actions { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-top: 1px solid var(--border); background: rgba(10,17,32,.94); }
.result-actions div { display: grid; gap: 3px; }
.result-actions strong { font-size: 14px; }
.result-actions span { color: var(--muted); font-size: 12px; }
.download-button { display: inline-flex; align-items: center; gap: 8px; padding: 11px 15px; border-radius: 9px; background: var(--text); color: #11182a; text-decoration: none; font-size: 13px; font-weight: 700; }
.download-button:hover { background: white; }
.download-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.history-section { margin-top: 18px; padding: 24px 28px 28px; }
.history-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; }
.history-heading h2 { font-size: 20px; }
#remaining-label { color: var(--muted); font-size: 12px; }
.history-empty { min-height: 125px; margin-top: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px dashed rgba(90,108,146,.55); border-radius: 11px; color: var(--muted); }
.history-empty svg { width: 40px; margin-bottom: 8px; fill: none; stroke: #8190b3; stroke-width: 1.6; }
.history-empty strong { color: #cbd4e8; font-size: 13px; }
.history-empty span { margin-top: 4px; font-size: 11px; }
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 13px; margin-top: 18px; }
.history-card { overflow: hidden; border: 1px solid var(--border); border-radius: 11px; background: #0a1325; transition: transform 150ms ease, border-color 150ms ease; }
.history-card:hover { transform: translateY(-2px); border-color: #526486; }
.history-card img { display: block; width: 100%; height: 150px; object-fit: cover; background: #050a14; }
.history-card-content { padding: 12px; }
.history-card-content p { height: 36px; margin: 0 0 10px; overflow: hidden; color: #d8dfed; font-size: 12px; line-height: 1.45; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.history-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-card-footer span { color: var(--muted-2); font-size: 10px; }
.history-card-footer a { color: var(--violet-light); font-size: 11px; font-weight: 700; text-decoration: none; }
.history-card-footer a:hover { color: white; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 10; max-width: min(480px, calc(100% - 32px)); padding: 12px 17px; border: 1px solid var(--border-bright); border-radius: 10px; background: #141f35; color: white; box-shadow: var(--shadow); font-size: 13px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; transition: 200ms ease; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 980px) {
  .app-view { width: min(100% - 32px, 760px); }
  .workspace { grid-template-columns: 1fr; }
  .result-panel, .result-ready { min-height: 560px; }
  .header-brand p { display: none; }
}

@media (max-width: 620px) {
  .login-view { padding: 24px 16px; }
  .canvas-lines { width: 92vw; height: 78vh; }
  .login-panel { padding: 40px 22px 26px; }
  .brand-large { font-size: 43px; }
  .login-panel h1 { margin-top: 30px; font-size: 27px; }
  .app-view { width: calc(100% - 24px); padding-bottom: 24px; }
  .app-header { min-height: 70px; }
  .brand { font-size: 24px; }
  .header-actions { gap: 14px; }
  .usage { padding-right: 14px; font-size: 12px; }
  .logout-button { font-size: 0; }
  .logout-button svg { width: 22px; }
  .workspace { padding-top: 14px; }
  .editor-panel { padding: 20px 16px; }
  .section-heading h1 { font-size: 21px; }
  .dropzone { min-height: 190px; }
  .options-row { gap: 12px; flex-wrap: wrap; }
  .option-divider { display: none; }
  .result-panel, .result-ready { min-height: 460px; }
  .result-empty h2, .result-loading h2 { font-size: 22px; }
  .result-actions { align-items: flex-start; }
  .history-section { padding: 20px 16px; }
  .history-heading { align-items: flex-start; }
  .history-grid { grid-template-columns: 1fr 1fr; }
  .history-card img { height: 120px; }
}

@media (max-width: 420px) {
  .history-grid { grid-template-columns: 1fr; }
  .options-row fieldset:first-child { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
