:root{
  --bg:#f6f8ff;
  --bg2:#eef3ff;
  --card:rgba(255,255,255,.68);
  --card-solid:#ffffff;
  --text:#0f172a;
  --text-soft:#475569;
  --border:rgba(148,163,184,.25);
  --shadow:0 20px 45px rgba(15,23,42,.12);
  --accent:#5b8dff;
  --accent-2:#a855f7;
  --success:#10b981;
  --danger:#ef4444;
  --radius-xl:24px;
  --radius-md:14px;
}

body.dark{
  --bg:#050816;
  --bg2:#0e1630;
  --card:rgba(15,23,42,.72);
  --card-solid:#0f172a;
  --text:#e2e8f0;
  --text-soft:#a5b4cf;
  --border:rgba(148,163,184,.2);
  --shadow:0 28px 55px rgba(0,0,0,.45);
  --accent:#6ea8ff;
  --accent-2:#c084fc;
}

*{ box-sizing:border-box; }
html,body{ min-height:100%; }

body{
  margin:0;
  font-family:"Inter","Segoe UI",Arial,sans-serif;
  color:var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(130,95,255,.22), transparent 60%),
    radial-gradient(1200px 600px at 90% 0%, rgba(0,207,255,.2), transparent 60%),
    linear-gradient(130deg,var(--bg),var(--bg2));
  background-attachment:fixed;
  transition:background .45s ease,color .28s ease;
  overflow-x:hidden;
}

body::before{
  content:"";
  position:fixed;
  inset:-25%;
  z-index:-1;
  background:conic-gradient(from 0deg,rgba(59,130,246,.12),rgba(147,51,234,.1),rgba(20,184,166,.1),rgba(59,130,246,.12));
  filter:blur(52px);
  animation:meshSpin 26s linear infinite;
}

@keyframes meshSpin{
  from{ transform:rotate(0deg) scale(1.05); }
  to{ transform:rotate(360deg) scale(1.05); }
}

.wrapper{ padding:22px clamp(14px,2.2vw,30px) 100px; }

.container{
  max-width:1200px;
  margin:auto;
  padding:clamp(14px,2vw,26px);
  border:1px solid var(--border);
  background:var(--card);
  backdrop-filter:blur(16px);
  border-radius:30px;
  box-shadow:var(--shadow);
}

h1{
  margin:8px 0;
  text-align:center;
  font-size:clamp(2rem,4.5vw,3.4rem);
  line-height:1.1;
  letter-spacing:-.02em;
  background:linear-gradient(120deg,#60a5fa,#38bdf8,#a855f7,#f472b6);
  background-size:200% 200%;
  color:transparent;
  -webkit-background-clip:text;
  background-clip:text;
  animation:heroFlow 7.5s ease infinite;
}

@keyframes heroFlow{
  0%{ background-position:0 50%; }
  50%{ background-position:100% 50%; }
  100%{ background-position:0 50%; }
}

.hero-subtitle{
  text-align:center;
  margin:0 0 16px;
  color:var(--text-soft);
  font-size:clamp(.95rem,2.1vw,1.1rem);
}

.top-actions{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  justify-content:center;
  margin:10px 0 22px;
}

button,.chip-btn,.tool-toggle-btn{
  border:1px solid rgba(255,255,255,.14);
  border-radius:999px;
  padding:12px 18px;
  background:linear-gradient(135deg,var(--accent),var(--accent-2));
  color:#fff;
  font-weight:800;
  letter-spacing:.01em;
  cursor:pointer;
  transition:transform .2s ease, box-shadow .2s ease, filter .2s ease;
  box-shadow:0 10px 24px rgba(37,99,235,.25), inset 0 1px 0 rgba(255,255,255,.22);
}

button:hover,.chip-btn:hover,.tool-toggle-btn:hover{
  transform:translateY(-2px);
  filter:brightness(1.08);
  box-shadow:0 16px 34px rgba(99,102,241,.32),0 0 18px rgba(56,189,248,.26);
}

button:active,.chip-btn:active,.tool-toggle-btn:active{ transform:translateY(0) scale(.98); }
button.secondary,.secondary-btn{ background:linear-gradient(135deg,#64748b,#334155); }
.hidden{ display:none !important; }

button:focus-visible,.chip-btn:focus-visible,.tool-toggle-btn:focus-visible{
  outline:3px solid rgba(56,189,248,.85);
  outline-offset:2px;
}

/* Tool action buttons: stronger contrast and clear hierarchy */
.section > button,
.section .controls-row button,
.section .mini-actions button{
  min-height:42px;
}

.section > button{
  min-width:168px;
  margin-top:8px;
  margin-bottom:8px;
}

.section .mini-actions button{
  border-radius:12px;
  padding:10px 12px;
  font-size:.8rem;
  font-weight:700;
  background:var(--card-solid);
  color:var(--text);
  border:1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  box-shadow:0 6px 14px rgba(15,23,42,.09);
}

.section .mini-actions button:hover{
  background:linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, #fff), color-mix(in srgb, var(--accent-2) 14%, #fff));
  color:#0b1220;
  box-shadow:0 12px 22px rgba(59,130,246,.2);
}

body.dark .section .mini-actions button{
  background:#111b31;
  color:#e8eefc;
  border-color:rgba(110,168,255,.38);
  box-shadow:0 10px 18px rgba(0,0,0,.3);
}

body.dark .section .mini-actions button:hover{
  background:linear-gradient(135deg, rgba(110,168,255,.25), rgba(192,132,252,.2));
}

.section{
  position:relative;
  margin-bottom:18px;
  border:1px solid var(--border);
  background:var(--card);
  backdrop-filter:blur(14px);
  border-radius:var(--radius-xl);
  padding:18px;
  overflow:hidden;
}

.section h2{ margin:0 0 12px; font-size:1.15rem; }
.section::after{
  content:"";
  position:absolute;
  inset:auto -30% -70% -30%;
  height:120px;
  pointer-events:none;
  background:linear-gradient(120deg,rgba(59,130,246,.1),rgba(168,85,247,.04),transparent);
}

input[type="color"]{
  width:58px;
  height:44px;
  padding:0;
  border:1px solid var(--border);
  border-radius:12px;
  background:transparent;
  cursor:pointer;
  vertical-align:middle;
}

input[type="file"],input[type="text"],input[type="range"],select,textarea{
  width:100%;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--card-solid);
  color:var(--text);
  padding:10px 12px;
}

textarea{ font-family:Consolas,monospace; }

.controls-row{
  display:grid;
  grid-template-columns:repeat(12,minmax(0,1fr));
  gap:10px;
  margin-top:12px;
}

.control{ grid-column:span 4; }
.control.full{ grid-column:1 / -1; }
.control label{
  display:block;
  margin-bottom:4px;
  font-size:.83rem;
  color:var(--text-soft);
}

.color-grid,.shade-grid{
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(105px,1fr));
  gap:10px;
  margin-top:14px;
}

.color-box{
  min-height:90px;
  border-radius:14px;
  position:relative;
  cursor:pointer;
  overflow:hidden;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.18);
  transition:transform .22s ease, box-shadow .22s ease;
}

.color-box:hover{
  transform:translateY(-3px) scale(1.03);
  box-shadow:0 10px 25px rgba(15,23,42,.25),0 0 20px rgba(96,165,250,.3);
}

.color-code{
  position:absolute;
  left:6px;
  right:6px;
  bottom:6px;
  background:rgba(15,23,42,.64);
  color:#fff;
  border-radius:9px;
  padding:6px;
  font-size:10px;
  line-height:1.2;
}

.shade-label{
  position:absolute;
  top:6px;
  left:6px;
  font-size:10px;
  font-weight:700;
  color:#fff;
  background:rgba(15,23,42,.48);
  border-radius:999px;
  padding:4px 8px;
}

.gradient-preview{
  min-height:160px;
  border-radius:18px;
  margin-top:14px;
  border:1px solid var(--border);
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.18);
}

.gradient-code{ margin-top:10px; font-size:.8rem; color:var(--text-soft); }

.palette-preview{
  margin-top:10px;
  display:flex;
  flex-wrap:wrap;
  gap:8px;
}

.palette-preview > div{
  flex:1 1 108px;
  min-height:72px;
  border-radius:12px;
  position:relative;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.26);
}

.palette-preview > div span{
  position:absolute;
  bottom:6px;
  left:6px;
  right:6px;
  font-size:10px;
  color:#fff;
  text-shadow:0 1px 3px rgba(0,0,0,.55);
}

.contrast-result{ margin-top:10px; font-weight:700; line-height:1.45; }
.contrast-preview{
  margin-top:10px;
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px;
}

.analytics-panel{
  position:fixed;
  top:16px;
  right:16px;
  width:min(260px,85vw);
  z-index:90;
  border-radius:18px;
  border:1px solid var(--border);
  background:var(--card);
  backdrop-filter:blur(14px);
  box-shadow:var(--shadow);
  padding:12px;
}

.analytics-panel h3{ margin:0 0 8px; font-size:.92rem; }
.analytics-panel ul{
  margin:0;
  padding:0;
  list-style:none;
  display:grid;
  gap:6px;
  font-size:.82rem;
  color:var(--text-soft);
}

.mini-actions{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:10px;
}

.mini-actions button{
  padding:9px 11px;
  font-size:.78rem;
}

.favorites-row,.recent-row{
  margin-top:10px;
  display:flex;
  flex-wrap:wrap;
  gap:8px;
}

.color-dot{
  width:36px;
  height:36px;
  border-radius:50%;
  border:2px solid rgba(255,255,255,.7);
  cursor:pointer;
  box-shadow:0 8px 16px rgba(0,0,0,.2);
}

.toast{
  position:fixed;
  left:50%;
  bottom:20px;
  transform:translateX(-50%) translateY(14px);
  opacity:0;
  background:rgba(15,23,42,.92);
  color:#fff;
  border-radius:999px;
  padding:10px 14px;
  font-size:.85rem;
  z-index:120;
  transition:all .24s ease;
}

.toast.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}

.drop-zone{
  border:2px dashed var(--border);
  border-radius:14px;
  padding:14px;
  text-align:center;
  margin-top:10px;
  color:var(--text-soft);
  min-height:120px;
  display:flex;
  align-items:center;
  justify-content:center;
  flex-direction:column;
  gap:8px;
}

.drop-zone.drag{
  border-color:var(--accent);
  background:rgba(59,130,246,.08);
}

.drop-zone.has-image{
  border-style:solid;
  background:rgba(59,130,246,.06);
}

.drop-zone img{
  display:block;
  width:auto;
  max-width:100%;
  max-height:180px;
  border-radius:12px;
  border:1px solid var(--border);
  object-fit:contain;
}

.drop-zone .drop-caption{
  font-size:.8rem;
  color:var(--text-soft);
  word-break:break-word;
}

.image-action-title{
  margin:12px 0 6px;
  font-size:.95rem;
  color:var(--text-soft);
}

.tool-extra-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin:18px 0 2px;
}

.tool-toggle-btn{
  border-radius:14px;
  background:linear-gradient(135deg,#ffffff,#f4f8ff);
  border:1px solid var(--border);
  color:var(--text);
  box-shadow:0 8px 18px rgba(15,23,42,.08);
  min-height:46px;
  font-weight:800;
}

body.dark .tool-toggle-btn{
  background:linear-gradient(135deg,#13213d,#0d182f);
  border-color:rgba(110,168,255,.28);
  color:#e5edff;
}

.popup-overlay{
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  padding:20px;
  background:rgba(2,6,23,.7);
  z-index:9999;
}

.popup-overlay.active{
  display:flex;
  animation:fadeIn .24s ease;
}

.popup-box{
  width:min(760px,100%);
  max-height:calc(100vh - 40px);
  overflow:auto;
  border-radius:24px;
  border:1px solid var(--border);
  background:var(--card-solid);
  color:var(--text);
  box-shadow:var(--shadow);
  padding:24px;
  position:relative;
}

.popup-close{
  position:absolute;
  top:12px;
  right:12px;
  width:36px;
  height:36px;
  border-radius:50%;
  background:var(--bg2);
  color:var(--text);
}

.legal-popup-overlay{
  position:fixed;
  inset:0;
  z-index:10000;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  background:rgba(2,6,23,.66);
}

.legal-popup-box{
  width:min(580px,100%);
  border-radius:24px;
  border:1px solid var(--border);
  background:var(--card-solid);
  color:var(--text);
  box-shadow:var(--shadow);
  text-align:center;
  padding:24px;
}

.legal-popup-icon{ font-size:40px; }
.copy-btn{ margin-top:10px; }

@keyframes fadeIn{
  from{ opacity:0; }
  to{ opacity:1; }
}

.top-ad,.bottom-ad{
  display:flex;
  justify-content:center;
  align-items:center;
  width:100%;
}

.top-ad ins.adsbygoogle,.bottom-ad ins.adsbygoogle{
  display:block !important;
  margin:0 auto;
}

@media (max-width:1000px){
  .analytics-panel{
    position:static;
    width:100%;
    margin-bottom:14px;
  }
}

@media (max-width:760px){
  .wrapper{ padding:10px 10px 90px; }
  .container{ border-radius:22px; padding:12px; }
  .section{ border-radius:18px; padding:12px; }

  .controls-row{ grid-template-columns:repeat(2,minmax(0,1fr)); }
  .control{ grid-column:span 1; }
  .control.full{ grid-column:1 / -1; }
  .color-grid,.shade-grid{ grid-template-columns:repeat(2,minmax(0,1fr)); }

  .top-actions{
    position:sticky;
    top:8px;
    z-index:50;
    border-radius:12px;
    padding:8px;
    background:var(--card);
    backdrop-filter:blur(8px);
  }

  .tool-extra-actions{ flex-direction:column; }
  .tool-toggle-btn{ width:100%; }
}
