:root {
  --font-ui: 'Poppins', system-ui, sans-serif;
  --font-display: 'Lobster', cursive, sans-serif;
  --bg-dark: #0a0612;
  --glass-bg: rgba(20, 15, 30, 0.75);
  --glass-border: rgba(255, 255, 255, 0.1);
  --gold: #F7C948;
  --coral-start: #FF8A65;
  --coral-end: #FF6B35;
  --text-primary: #FFFFFF;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --input-bg: #2a2535;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

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

html, body {
  max-width: 100%;
  overflow-x: clip;
  font-family: var(--font-ui);
  color: var(--text-primary);
}
@supports not (overflow: clip) {
  html, body { overflow-x: hidden; }
}

.bg-fixed {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url('img/background.png') center center / cover no-repeat;
}

.bg-veil {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse at center, rgba(10, 6, 18, 0.55) 0%, rgba(10, 6, 18, 0.85) 100%);
  pointer-events: none;
}

.dg-app-header {
  position: sticky;
  z-index: 1000;
  top: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(10, 6, 18, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.dg-app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1400px;
  min-height: 66px;
  margin: 0 auto;
  padding: 8px 24px;
}

.dg-app-brand { display: inline-flex; flex: 0 1 auto; align-items: center; min-width: 0; }
.dg-app-brand img { display: block; width: min(190px, 28vw); max-height: 42px; object-fit: contain; }
.dg-app-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 9px; }
.dg-app-link { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; border: 1px solid rgba(255, 255, 255, .2); border-radius: 999px; padding: 8px 14px; color: rgba(255, 255, 255, .86); font-size: .76rem; font-weight: 600; text-decoration: none; transition: border-color .2s ease, color .2s ease, background .2s ease, transform .2s ease; }
.dg-app-link:hover { transform: translateY(-1px); border-color: rgba(247, 201, 72, .62); color: #fff; }
.dg-app-games { border-color: transparent; }
.dg-app-profile { border-color: rgba(247, 201, 72, .42); color: #ffe08a; }
.dg-app-register { border-color: rgba(247, 201, 72, .55); background: linear-gradient(135deg, #ff8a65, #ff6b35); color: #fff; }
.dg-app-register:hover { background: linear-gradient(135deg, #ff9a78, #ff7c4a); }
.dg-app-user { max-width: 180px; overflow: hidden; color: rgba(255, 255, 255, .58); font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 700px) {
  .dg-app-nav { flex-wrap: wrap; gap: 8px 12px; padding: 8px 14px; }
  .dg-app-brand img { width: min(165px, 45vw); max-height: 36px; }
  .dg-app-actions { width: 100%; justify-content: flex-end; gap: 5px; }
  .dg-app-link { min-height: 34px; padding: 6px 10px; font-size: .68rem; }
  .dg-app-user { display: none; }
}

.specialty-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 4px 0;
}

.specialty-card {
  width: 100%;
  text-align: center;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.specialty-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: none;
  background: rgba(40, 35, 50, 0.8);
  transition: box-shadow 0.3s ease, opacity 0.3s ease;
}

.specialty-card:hover img {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7), 0 4px 12px rgba(255, 255, 255, 0.15);
}

.specialty-card.active img {
  box-shadow: inset 0 0 0 2px rgba(10, 6, 18, 0.55), inset 0 0 0 4px var(--gold), 0 8px 20px rgba(247, 201, 72, 0.25);
}

.specialty-card span {
  display: block;
  font-size: 0.7rem;
  margin-top: 4px;
  opacity: 0.8;
}

.app-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px;
  min-height: calc(100vh - 130px);
}

.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transform: translateZ(0);
  will-change: backdrop-filter;
}

.control-section {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  transform: translateZ(0);
  will-change: backdrop-filter;
}

.step-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.step-num {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--coral-start), var(--coral-end));
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 3px rgba(247, 201, 72, 0.25), 0 4px 14px rgba(255, 107, 53, 0.4);
}

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0;
}

.input-wrapper {
  position: relative;
}

.input-wrapper input[type="text"] {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 36px 10px 14px;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.3s ease;
}

.input-wrapper input[type="text"]:focus {
  border-color: var(--gold);
}

.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.clear-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 30px;
  justify-self: center;
  align-self: center;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: box-shadow 0.2s ease, opacity 0.2s ease;
  outline: none;
}

.color-swatch:hover {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85);
}

.color-swatch.active {
  box-shadow: inset 0 0 0 2px rgba(10, 6, 18, 0.6), inset 0 0 0 3.5px var(--gold), 0 0 10px rgba(247, 201, 72, 0.5);
}

.custom-color-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 10px;
  margin-top: 8px;
  border: 1px solid var(--glass-border);
  border-radius: 50px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.custom-color-swatch input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border: none;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  overflow: hidden;
}
.custom-color-swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color-swatch input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
.custom-color-swatch input[type="color"]::-moz-color-swatch { border: none; border-radius: 50%; }

.preview-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.konva-container {
  width: min(100%, calc(100dvh - 140px));
  max-width: 850px;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.konva-container canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

.konva-placeholder {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.download-area {
  width: 100%;
  margin-top: 16px;
}

.btn-download {
  background: linear-gradient(135deg, var(--coral-start), var(--coral-end));
  border: none;
  color: white;
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 14px 32px;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(255, 107, 53, 0.4);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-download:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 40px rgba(255, 107, 53, 0.5);
}

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

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.fade-in-up {
  animation: fadeInUp 0.6s ease forwards;
}

.konva-container.changing {
  animation: pulse 0.4s ease;
}

@media (min-width: 1025px) {
  .app-main {
    grid-template-columns: repeat(12, 1fr);
    grid-template-areas:
      "specialty specialty specialty specialty specialty specialty specialty specialty specialty specialty specialty specialty"
      "name name name color color output output output output output output output";
    gap: 16px;
    padding: 14px 24px;
    min-height: calc(100vh - 100px);
  }

  .cs-specialty {
    grid-area: specialty;
  }

  .cs-name {
    grid-area: name;
  }

  .cs-color {
    grid-area: color;
  }

  .preview-section {
    grid-area: output;
    justify-self: center;
  }

  #appHeader {
    padding: 8px 24px;
  }

  .logo-img {
    width: min(200px, 60vw);
  }

  .control-section {
    padding: 14px;
  }

  .specialty-bar {
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    align-content: start;
  }

  .specialty-card img {
    border-radius: var(--radius-sm);
  }

  .specialty-card span {
    font-size: 0.58rem;
    margin-top: 2px;
  }

  .konva-container {
    width: 100%;
    max-width: 1000px;
    min-width: 320px;
  }
}

@media (max-width: 1024px) {
  .app-main {
    padding: 16px;
  }
}

@media (max-width: 768px) {
  .app-main {
    padding: 16px 14px 120px;
    gap: 14px;
  }

  .control-section {
    padding: 14px;
    border-radius: var(--radius-md);
  }

  .specialty-bar {
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    padding: 2px 0;
  }

  .specialty-card img {
    border-radius: var(--radius-sm);
    border-width: 1.5px;
  }

  .specialty-card span {
    font-size: 0.55rem;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .glass-panel {
    padding: 18px 16px;
  }

  .step-heading {
    margin-bottom: 8px;
  }

  .color-palette {
    grid-template-columns: repeat(12, 1fr);
    gap: 4px;
  }

  .color-swatch {
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 26px;
    min-width: 18px;
    justify-self: center;
  }

  .step-num {
    width: 26px;
    height: 26px;
    font-size: 0.8rem;
  }

  .section-title {
    font-size: 0.9rem;
  }

  .download-area {
    margin-top: 12px;
  }

  .btn-download {
    width: 100%;
    justify-content: center;
  }
}

.app-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 24px 22px;
  border-top: 1px solid var(--glass-border);
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
}

.footer-logo-img {
  width: 90px;
  height: auto;
  opacity: 0.9;
}

.footer-year {
  font-family: 'Lobster', cursive;
  font-size: 1rem;
  color: var(--gold);
}

.footer-credit {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.footer-credit a {
  font-weight: 600;
  color: var(--gold);
  text-decoration: none;
}

.footer-credit a:hover {
  text-decoration: underline;
}

.footer-spacer {
  flex: 0 0 auto;
  width: 0;
}

.footer-platform-signoff {
  flex: 0 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding-top: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.footer-platform-brand {
  display: inline-flex;
  align-items: center;
}

.footer-platform-brand img {
  display: block;
  width: min(154px, 42vw);
  height: auto;
  opacity: 0.92;
  filter: drop-shadow(0 3px 10px rgba(0, 194, 215, 0.18));
}

.footer-platform-link {
  color: var(--gold);
  font-weight: 600;
  text-decoration: none;
}

.footer-platform-link:hover {
  color: #ffe18a;
  text-decoration: underline;
}

@media (max-width: 768px) {
  .app-footer {
    justify-content: center;
    padding: 14px 16px 130px;
    text-align: center;
  }

  .footer-brand {
    margin-right: 0;
  }

  .footer-spacer {
    display: none;
  }
}

@media (min-width: 769px) {
  .footer-spacer {
    width: 260px;
  }
}

.page-loader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: var(--bg-dark);
  transition: opacity 0.5s ease;
}

.page-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.loader-logo {
  width: min(220px, 60vw);
  height: auto;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.konva-container {
  position: relative;
}

.konva-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  background: rgba(10, 6, 18, 0.5);
  z-index: 10;
}

.konva-loader .spinner {
  width: 34px;
  height: 34px;
  border-width: 3px;
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #d4A417);
  border: none;
  color: #171221;
  font-weight: 600;
}

.btn-gold:hover {
  background: linear-gradient(135deg, #ffD96b, var(--gold));
  color: #171221;
}
