:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1b2030;
  --text: #e9edf3;
  --muted: #9aa4b2;
  --accent: #00aaff;
  --accent-hover: #008fd6;
  --danger: #e54b4b;
  --danger-hover: #cc3f3f;
  --success: #28a745;
  --success-hover: #218838;
  --border: #283041;
  --ring: rgba(0,170,255,.28);
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: 'Kanit', sans-serif; color: var(--text); background: var(--bg); }

/* ===== Topbar ===== */
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,0));
  border-bottom: 1px solid var(--border);
}
.brand{ display:flex; align-items:center; gap:10px; color: var(--muted); }
.brand .logo{
  display:inline-grid; place-items:center;
  width:34px; height:34px; border-radius:10px;
  background: linear-gradient(135deg, #0ea5e9, #22d3ee);
  color: white; font-weight: 700;
}
.top-actions{ display:flex; gap:10px; }

/* ===== Buttons ===== */
.btn{
  padding:10px 14px; border:none; border-radius:10px; cursor:pointer;
  font-size:.96rem; transition: .18s ease; color: #fff;
}
.btn.primary{ background: var(--accent); }
.btn.primary:hover{ background: var(--accent-hover); }
.btn.danger{ background: var(--danger); }
.btn.danger:hover{ background: var(--danger-hover); }
.btn.success{ background: var(--success); }
.btn.success:hover{ background: var(--success-hover); }
.btn.ghost{ background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover{ background: rgba(255,255,255,.04); }
.btn.upload{ background: var(--accent); color: #fff; }
.btn.upload:hover{ background: var(--accent-hover); }
.w-100{ width:100%; }

/* ===== Layout ===== */
.editor-container{
  display:flex; height: calc(100vh - 64px);
  width: min(96vw, 1600px);
  margin: 12px auto;
  background: var(--panel);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}

/* Sidebar */
.controls{
  width: 340px; background: var(--panel-2);
  padding: 18px; overflow-y:auto;
  border-right:1px solid var(--border);
}
.controls::-webkit-scrollbar{ width: 10px; }
.controls::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.08); border-radius:8px; }
.panel-header h2{ margin: 0; color: var(--text); font-weight:600; }
.panel-header p{ margin: 0; color: var(--muted); font-size: .94rem; }
.separator{ border-bottom: 1px dashed var(--border); margin: 12px 0; }

/* Tool sections */
.tool-section {
  background: #1d2333;
  border: 1px solid #2a3550;
  border-radius: 12px;
  margin-bottom: 16px;
  padding: 12px;
}
.tool-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: #cfe9ff;
}

.control-group{ display:flex; flex-direction:column; gap:8px; margin-bottom: 10px; }
.slider-group label{ display:flex; justify-content:space-between; align-items:center; font-size:.95rem; }
.val{ color: var(--muted); font-size: .9rem; }

input[type="range"]{
  appearance:none; width:100%; height:6px; border-radius:6px; outline:none; cursor:pointer;
  background: linear-gradient(90deg, rgba(0,170,255,.35), rgba(255,255,255,.12));
}
input[type="range"]::-webkit-slider-thumb{
  appearance:none; width:16px; height:16px; border-radius:10px; background: #fff; border: 3px solid var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}

.resize-grid{ display:grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checkbox{ display:flex; align-items:center; gap:8px; color: var(--muted); }

.button-group{ display:flex; gap:10px; margin-top:10px; }

/* Canvas Area */
.image-area{
  flex:1; display:flex; align-items:center; justify-content:center; background:#0f1115; position:relative;
}
.canvas-container{ position:relative; display:flex; align-items:center; justify-content:center; width:100%; height:100%; }
#placeholder{
  position:absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  text-align:center;
  display:flex; flex-direction:column; align-items:center; gap:14px;
}
.big-upload-btn{ font-size: 1.1rem; padding: 14px 24px; border-radius: 12px; }
canvas{
  max-width: 100%; max-height: 92%;
  border-radius: 12px; background: #0a0d14;
  border:1px solid #1b2233;
}
canvas.cropping{ cursor: crosshair; }
.hidden{ display:none !important; }

/* เส้นแบ่งหมวด RGB */
.rgb-separator {
  border-top: 1px dashed var(--border);
  margin: 12px 0;
}



/* 🆕 Resize box */
/* ปรับ layout ให้บาลานซ์ */
.resize-box {
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* ช่องซ้าย × กลาง × ช่องขวา */
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.resize-input {
  display: flex;
  flex-direction: column;
}

.resize-input input {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: #1e1e1e;
  color: #fff;
  font-size: 0.9rem;
  width: 100%;
  box-sizing: border-box;
}

.times {
  color: #aaa;
  font-size: 1.5rem;
  text-align: center;
  width: 20px;
}


/* ✅ Primary button */
.primary-btn, .save-btn-modern {
  background: var(--accent-color);
  color: #fff;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all .2s ease;
}
.primary-btn:hover, .save-btn-modern:hover {
  background: var(--hover-color);
  transform: translateY(-1px);
}
.primary-btn:active, .save-btn-modern:active {
  transform: scale(0.98);
}
.w-100 { width: 100%; }

/* 🪙 Modern Select */
.modern-select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  background: #1e1e1e;
  color: #fff;
  border: 1px solid var(--border-color);
  font-size: 0.95rem;
}
.modern-select:focus {
  outline: 2px solid var(--accent-color);
}

/* Quality slider */
.quality-box {
  margin-top: 12px;
}
.quality-box label {
  display: flex;
  justify-content: space-between;
  color: #bbb;
  margin-bottom: 6px;
}
.quality-box input[type="range"] {
  width: 100%;
}





#apply-resize-btn {
  background: linear-gradient(135deg, #3a9efd, #2f80ed);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  width: 100%;
  transition: all 0.25s ease;
  box-shadow: 0 4px 12px rgba(63, 142, 252, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
}

#apply-resize-btn:hover {
  background: linear-gradient(135deg, #2f80ed, #1f6edc);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(63, 142, 252, 0.45);
}

#apply-resize-btn:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(63, 142, 252, 0.25);
}

#apply-resize-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #555;
  box-shadow: none;
}


#save-btn-bottom {
  background: linear-gradient(135deg, #00c6ff, #0072ff);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0, 114, 255, 0.3);
  transition: all 0.25s ease;
  margin-top: 20px;
}

#save-btn-bottom:hover {
  background: linear-gradient(135deg, #0072ff, #005cd1);
  box-shadow: 0 6px 18px rgba(0, 114, 255, 0.45);
  transform: translateY(-2px);
}

#save-btn-bottom:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(0, 114, 255, 0.25);
}

#save-btn-bottom:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #555;
  box-shadow: none;
}

.back-home-btn {
  display: inline-block;
  background: #1e88e5;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: bold;
  transition: 0.2s;
}
.back-home-btn:hover {
  background: #1565c0;
}