/* -----------------------------------------------------------
 * style.css – Dark Editorial Redesign (v3)
 * -----------------------------------------------------------
 * Dark luxury / editorial aesthetic
 * DM Serif Display headings, Plus Jakarta Sans body
 * Amber/gold accent (#d4a853), glass-morphism, noise texture
 * ----------------------------------------------------------- */

/* ============ 1. Design Tokens ============ */
:root {
  /* Typography */
  --font-heading: "DM Serif Display", Georgia, serif;
  --font-body: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Layout */
  --radius: 0.75rem;
  --ease: 150ms ease-in-out;

  /* Dark palette (default) */
  --bg: #0a0a0b;
  --surface: #161619;
  --surface-alpha: rgba(22, 22, 25, 0.72);
  --text: #f0ece4;
  --text-muted: #8a857c;
  --accent: #d4a853;
  --accent-dim: rgba(212, 168, 83, 0.15);
  --accent-glow: rgba(212, 168, 83, 0.25);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(212, 168, 83, 0.4);
  --error: #e05c5c;
  --error-dim: rgba(224, 92, 92, 0.25);
  --input-bg: rgba(255, 255, 255, 0.04);
  --input-border: rgba(255, 255, 255, 0.1);
  --toggle-bg: rgba(255, 255, 255, 0.08);
  --toggle-icon: #f0ece4;
  --checkerboard-a: rgba(255, 255, 255, 0.03);
  --checkerboard-b: transparent;
}

/* ============ Light mode overrides ============ */
body.light-mode {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-alpha: rgba(255, 255, 255, 0.78);
  --text: #1a1814;
  --text-muted: #7a7568;
  --accent: #b8923f;
  --accent-dim: rgba(184, 146, 63, 0.12);
  --accent-glow: rgba(184, 146, 63, 0.2);
  --border: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(184, 146, 63, 0.45);
  --error: #d94f4f;
  --error-dim: rgba(217, 79, 79, 0.2);
  --input-bg: rgba(0, 0, 0, 0.03);
  --input-border: rgba(0, 0, 0, 0.12);
  --toggle-bg: rgba(0, 0, 0, 0.06);
  --toggle-icon: #1a1814;
  --checkerboard-a: rgba(0, 0, 0, 0.05);
  --checkerboard-b: transparent;
}

/* ============ 2. Global Layout ============ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 20px;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.4s ease;
}

/* Noise texture overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* ============ 3. Container (glass-morphism) ============ */
.container {
  position: relative;
  z-index: 1;
  background: var(--surface-alpha);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  width: 800px;
  max-width: 100%;
  padding: 32px 32px 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.35);
  transition: background 0.4s ease, border-color 0.4s ease,
    box-shadow 0.4s ease;
  margin: 0 auto;
  animation: containerReveal 0.6s ease-out both;
}

body.light-mode .container {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* ============ 4. Typography ============ */
h1 {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: 1.8rem;
  color: var(--text);
  text-align: center;
  margin-bottom: 28px;
  position: relative;
  letter-spacing: 0.01em;
}

h1::after {
  content: "";
  display: block;
  width: 48px;
  height: 2px;
  background: var(--accent);
  margin: 10px auto 0;
  border-radius: 2px;
}

h3 {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: 1.15rem;
  color: var(--text);
}

label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
  color: var(--text-muted);
}

/* ============ 5. Form Controls ============ */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

textarea,
input,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--input-border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: border-color var(--ease), box-shadow var(--ease),
    background var(--ease);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

textarea::placeholder,
input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

textarea:hover,
input:hover,
select:hover {
  border-color: var(--border-hover);
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-dim);
}

input[type="file"] {
  cursor: pointer;
  padding: 9px;
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: background var(--ease);
}

input[type="file"]::file-selector-button:hover {
  background: var(--accent-glow);
}

input[type="color"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============ 6. Buttons ============ */
.button-container {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 24px 0;
  justify-content: center;
}

button {
  flex: 1 1 120px;
  max-width: 200px;
  padding: 12px 20px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  transition: background var(--ease), box-shadow var(--ease),
    transform var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

#download-btn {
  position: relative;
  max-width: 100%;
  width: 100%;
  background: var(--accent);
  border: none;
  color: #0a0a0b;
  font-weight: 700;
  letter-spacing: 0.08em;
  overflow: hidden;
  transition: all var(--ease);
}

/* Ambient glow behind download button */
#download-btn::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: var(--radius);
  background: var(--accent);
  opacity: 0;
  filter: blur(14px);
  z-index: -1;
  transition: opacity 0.3s ease;
  animation: glowPulse 3s ease-in-out infinite;
}

#download-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

#download-btn:hover::before {
  opacity: 0.5;
}

#download-btn:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
  filter: none;
}

body.light-mode #download-btn {
  color: #fff;
}

/* ============ 7. Main Layout ============ */
.main-content {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  align-items: start;
}

/* ============ 8. Preview Area (pedestal) ============ */
#qrcode-preview-container {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  transition: background 0.4s ease, border-color 0.4s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  position: relative;
  /* Subtle inner glow */
  box-shadow: inset 0 0 40px rgba(212, 168, 83, 0.03);
}

/* Accent gradient line at bottom ("pedestal") */
#qrcode-preview-container::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent),
    transparent
  );
  opacity: 0.6;
  animation: shimmer 3s ease-in-out infinite;
}

body.light-mode #qrcode-preview-container {
  box-shadow: inset 0 0 30px rgba(184, 146, 63, 0.04);
}

#qrcode {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  /* Checkerboard for transparency preview */
  background-image: linear-gradient(
      45deg,
      var(--checkerboard-a) 25%,
      transparent 25%
    ),
    linear-gradient(-45deg, var(--checkerboard-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checkerboard-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checkerboard-a) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

#qrcode > canvas,
#qrcode > img {
  max-width: 100%;
  height: auto !important;
  object-fit: contain;
}

#no-input-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ============ 9. Color Presets ============ */
.preset-container {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  width: fit-content;
}

.color-preset {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
    border-color var(--ease), box-shadow var(--ease);
  padding: 0;
  appearance: none;
  background-size: cover;
  flex: 1;
}

.color-preset:hover {
  transform: scale(1.18);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.color-preset:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ============ 10. Color Row ============ */
.color-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
  color: var(--text-muted);
}

/* ============ 11. Theme Toggle ============ */
#theme-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 46px;
  height: 46px;
  padding: 8px;
  border-radius: 50%;
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease),
    transform var(--ease);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 1000;
}

#theme-toggle:hover {
  transform: scale(1.08);
  border-color: var(--accent);
}

#theme-toggle:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#theme-toggle svg {
  width: 24px;
  height: 24px;
  fill: var(--toggle-icon);
  transition: fill var(--ease);
}

/* Dark mode (default): show sun, hide moon */
.sun-icon {
  display: block;
}
.moon-icon {
  display: none;
}

/* Light mode: show moon, hide sun */
body.light-mode .sun-icon {
  display: none;
}
body.light-mode .moon-icon {
  display: block;
}

/* ============ 12. History Section ============ */
.history-section {
  margin-top: 32px;
  padding-top: 24px;
  position: relative;
}

/* Accent gradient divider */
.history-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent),
    transparent
  );
  opacity: 0.4;
}

.history-section h3 {
  text-align: center;
  margin-bottom: 16px;
}

#history-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  justify-content: center;
}

.history-item {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.history-item:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.history-item canvas,
.history-item img {
  max-width: 100px;
  height: auto !important;
  border-radius: calc(var(--radius) - 4px);
}

.history-item p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
  word-break: break-all;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ============ 13. Responsiveness ============ */
@media (max-width: 768px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  .container {
    width: 100%;
    padding: 24px 20px;
  }
}

@media (max-width: 480px) {
  html {
    padding: 0;
  }
  body {
    padding: 8px 0;
  }
  .container {
    width: 100%;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 20px 16px;
  }
  h1 {
    font-size: 1.4rem;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  #theme-toggle {
    bottom: 15px;
    right: 15px;
  }
  #history-container {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============ 14. Login Page ============ */
.login-card {
  position: relative;
  z-index: 1;
  background: var(--surface-alpha);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  width: 380px;
  max-width: 100%;
  padding: 40px 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.35);
  margin: auto;
  animation: containerReveal 0.6s ease-out both;
}

.login-card h1 {
  margin-bottom: 32px;
}

.login-card .form-group {
  margin-bottom: 20px;
}

.login-submit {
  width: 100%;
  max-width: 100%;
  background: var(--accent);
  border: none;
  color: #0a0a0b;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 14px;
  margin-top: 8px;
  transition: all var(--ease);
}

.login-submit:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

body.light-mode .login-submit {
  color: #fff;
}

.login-error {
  font-size: 0.82rem;
  color: var(--error);
  margin-top: 12px;
  text-align: center;
  min-height: 1.2em;
}

/* ============ 15. Logout Button ============ */
#logout-btn {
  position: fixed;
  bottom: 74px;
  right: 20px;
  width: 46px;
  height: 46px;
  padding: 8px;
  border-radius: 50%;
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  flex: none;
  max-width: none;
}

#logout-btn:hover {
  transform: scale(1.08);
  border-color: var(--error);
}

#logout-btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--error-dim);
}

#logout-btn svg {
  width: 20px;
  height: 20px;
  fill: var(--toggle-icon);
  transition: fill var(--ease);
}

#logout-btn:hover svg {
  fill: var(--error);
}

/* login.html body centering */
body:has(.login-card) {
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 480px) {
  #logout-btn {
    bottom: 69px;
    right: 15px;
  }
}
