/* ==========================================================================
   ต้นไม้ของพ่อ - Modern Glassmorphism & Blueprint Styling
   ========================================================================== */

:root {
  --bg-dark: #0f172a;
  --bg-canvas: #1e293b;
  --panel-bg: rgba(15, 23, 42, 0.82);
  --panel-border: rgba(255, 255, 255, 0.12);
  --panel-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.45);
  --accent-green: #10b981;
  --accent-green-hover: #059669;
  --accent-gold: #f59e0b;
  --accent-pink: #ec4899;
  --accent-blue: #3b82f6;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --danger: #ef4444;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* Canvas Container */
#viewport-container {
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  background-color: #0b0f19;
  cursor: crosshair;
}

#viewport-container.panning {
  cursor: grab;
}

#viewport-container.panning:active {
  cursor: grabbing;
}

#viewport-container.erasing {
  cursor: cell;
}

canvas {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
}

/* Glassmorphism Panels */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  box-shadow: var(--panel-shadow);
  border-radius: var(--radius-lg);
  color: var(--text-main);
  z-index: 10;
}

/* Unified Left Sidebar */
.toolbox-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 280px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.toolbox-panel::-webkit-scrollbar {
  width: 4px;
}
.toolbox-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

/* Brand Section inside Sidebar */
.brand-section {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 2px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  background: linear-gradient(135deg, #059669, #10b981);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
  stroke: #ffffff;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.72rem;
  font-weight: 500;
  color: #34d399;
  background: rgba(16, 185, 129, 0.15);
  padding: 2px 7px;
  border-radius: 12px;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.sidebar-divider {
  height: 1px;
  background: var(--panel-border);
  margin: -2px 0 2px 0;
}

/* Top-Right Actions Bar */
.top-right-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

/* Tool Section */
.tool-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Mode Grid */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 8px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn svg {
  width: 16px;
  height: 16px;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.mode-btn.active {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--accent-green);
  color: #34d399;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.25);
}

/* Tree Size Selector (2 Sizes: 12m & 7m) */
.size-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.size-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.size-card:hover {
  background: rgba(255, 255, 255, 0.09);
  transform: translateY(-2px);
}

.size-card.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: var(--accent-green);
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.3);
}

.size-circle {
  background: rgba(255, 255, 255, 0.1);
  border: 2px dashed rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.size-card.active .size-circle {
  border-color: var(--accent-green);
  background: rgba(16, 185, 129, 0.2);
}

.size-circle.large {
  width: 44px;
  height: 44px;
}

.size-circle.medium {
  width: 30px;
  height: 30px;
}

.size-title {
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.size-meter {
  font-size: 0.76rem;
  color: #34d399;
  font-weight: 700;
}

.size-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Tree Species Palette */
.type-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.type-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: all 0.15s ease;
}

.type-card:hover {
  background: rgba(255, 255, 255, 0.09);
  transform: translateY(-2px);
}

.type-card.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: var(--accent-green);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.25);
}

.type-img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  margin-bottom: 4px;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
}

.type-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

/* Options / Toggles */
.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.option-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: .2s;
  border-radius: 20px;
}

.slider-toggle:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}

input:checked + .slider-toggle {
  background-color: var(--accent-green);
}

input:checked + .slider-toggle:before {
  transform: translateX(16px);
}

/* Opacity Slider Container */
.opacity-slider-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.22);
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  transition: opacity .15s;
  cursor: pointer;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-green);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
  border: 2px solid white;
  transition: transform 0.1s ease;
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.range-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-green);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
  border: 2px solid white;
}

.opacity-presets {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.preset-btn {
  flex: 1;
  padding: 4px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-family);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text-main);
}

.preset-btn.active {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--accent-green);
  color: #34d399;
}

/* Statistics Box */
.stats-box {
  background: rgba(0, 0, 0, 0.28);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
}

.stat-badge {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.78rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font-family);
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, #059669, #10b981);
  border-color: #10b981;
  color: white;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #047857, #059669);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.45);
}

.btn-danger {
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.btn-icon-only {
  padding: 8px;
  border-radius: var(--radius-md);
}

/* Bottom Bar / Scale & Controls */
.bottom-center-panel,
.bottom-left-panel {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  z-index: 10;
  white-space: nowrap;
}

.scale-bar-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.scale-bar-line {
  height: 4px;
  background: white;
  border-left: 2px solid white;
  border-right: 2px solid white;
  width: 100px;
  transition: width 0.1s ease-out;
}

.scale-bar-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #e2e8f0;
}

.bottom-right-panel {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
}

.zoom-level-text {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0 8px;
  color: var(--text-muted);
  min-width: 52px;
  text-align: center;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 90%;
  max-width: 460px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 76px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--accent-green);
  border-radius: var(--radius-md);
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateX(120%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  transform: translateX(0);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .toolbox-panel {
    width: calc(100vw - 32px);
    max-height: 340px;
    bottom: 70px;
    top: auto;
  }
}
