* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f8e8;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
}
#app { max-width: 100vw; min-height: 100vh; }

/* Bottom tabs */
#tabs {
  display: flex; position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff; border-top: 1px solid #ddd; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; padding: 8px 0 6px; border: none; background: none;
  font-size: 11px; cursor: pointer; color: #888; transition: color 0.2s;
  font-weight: 500; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab.active { color: #4CAF50; font-weight: 700; }
.tab .icon { width: 16px; height: 16px; display: block; margin: 0 auto 2px; }
.tab-content { display: none; padding-bottom: 56px; }
.tab-content.active { display: block; }

/* Lucide icons */
.icon { width: 16px; height: 16px; vertical-align: -3px; }

/* ===== DRAW SCREEN ===== */
#draw-ui {
  display: flex; flex-direction: column; height: calc(100vh - 56px);
  padding: 4px; gap: 4px;
}
#type-toggle { display: flex; justify-content: center; gap: 8px; flex-shrink: 0; }
.type-btn {
  padding: 5px 18px; border: 2px solid #ddd; border-radius: 20px;
  background: #fff; font-size: 13px; cursor: pointer; font-weight: 500;
}
.type-btn.active { border-color: #4CAF50; background: #e8f5e9; color: #2e7d32; }

/* Color palette — horizontal strip */
#color-palette {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 3px;
  flex-shrink: 0; padding: 2px 0;
}
.color-btn {
  width: 22px; height: 22px; border-radius: 3px; border: 1px solid #999;
  cursor: pointer; padding: 0;
}
.color-btn:active { transform: scale(1.15); }
.color-btn.active-color { border: 2px solid #000; box-shadow: 0 0 0 1px #fff, 0 0 0 2px #4CAF50; }

/* Workspace: canvas fills available space, tools on right */
#draw-workspace {
  display: flex; gap: 4px; flex: 1; min-height: 0; /* crucial for flex shrink */
}
#canvas-wrapper {
  flex: 1; min-width: 0; border: 2px solid #999; border-radius: 6px;
  overflow: hidden; touch-action: none;
  background-image:
    linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
    linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
    linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: #f5f5f5;
  aspect-ratio: 1;
  max-height: 100%;
}
#draw-canvas { display: block; width: 100%; height: 100%; }

/* Tools panel */
#tools-panel {
  display: flex; flex-direction: column; gap: 3px; flex-shrink: 0;
}
#tools-panel .tool-btn {
  width: 36px; height: 36px; padding: 0; display: flex; align-items: center;
  justify-content: center; border-radius: 6px;
}
.tool-divider { height: 1px; background: #ddd; margin: 2px 0; }

/* Tool buttons */
.tool-btn {
  padding: 5px 10px; border: 1px solid #bbb; border-radius: 6px;
  background: #fff; cursor: pointer; font-size: 13px;
  font-weight: 500; color: #333; display: inline-flex; align-items: center; gap: 3px;
}
.tool-btn:active { background: #eee; }
.tool-btn.active { background: #333; color: #fff; border-color: #333; }
.tool-btn.active .icon { stroke: #fff; }

/* Bottom controls */
#draw-bottom {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  flex-shrink: 0; padding: 2px 0;
}
#size-presets { display: flex; align-items: center; gap: 5px; }
.size-preset {
  width: 28px; height: 28px; border: 1px solid #ccc; border-radius: 50%;
  background: #fff; cursor: pointer; display: flex; align-items: center;
  justify-content: center; padding: 0;
}
.size-preset span { display: block; background: #333; border-radius: 50%; }
.size-preset.active { border-color: #4CAF50; background: #e8f5e9; }

.opacity-control {
  display: flex; align-items: center; gap: 6px; font-size: 13px; color: #555;
  width: 100%; max-width: 320px; padding: 0 8px;
}
#opacity-slider { flex: 1; min-width: 0; }
#opacity-value { min-width: 36px; font-weight: 600; font-size: 12px; text-align: right; }

.primary-btn {
  padding: 10px 28px; background: #4CAF50; color: #fff; border: none;
  border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 2px 8px rgba(76,175,80,0.25);
  display: inline-flex; align-items: center; gap: 6px;
}
.primary-btn .icon { width: 18px; height: 18px; }
.primary-btn:active { transform: scale(0.97); }
.primary-btn:disabled { opacity: 0.5; }
#submit-status { font-size: 12px; min-height: 14px; }

/* ===== MEADOW ===== */
#meadow-ui { position: relative; }
#meadow-filters {
  display: flex; gap: 5px; padding: 8px 10px;
  background: rgba(255,255,255,0.9); z-index: 10;
}
.filter-btn {
  padding: 5px 12px; border: 1px solid #ccc; border-radius: 14px;
  background: #fff; font-size: 13px; cursor: pointer; font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
}
.filter-btn.active { background: #4CAF50; color: #fff; border-color: #4CAF50; }
#meadow-canvas { display: block; width: 100%; }
#meadow-bottom {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; position: fixed; bottom: 56px; left: 0; right: 0;
  z-index: 50;
}
#meadow-count { font-size: 11px; color: rgba(255,255,255,0.7); }
.share-btn {
  padding: 8px 18px; background: #ff6b6b; color: #fff; border: none;
  border-radius: 20px; font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  box-shadow: 0 2px 10px rgba(255,107,107,0.4);
  animation: sharePulse 2s ease-in-out infinite;
}
.share-btn .icon { width: 14px; height: 14px; }
@keyframes sharePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
#meadow-info {
  position: fixed; bottom: 65px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.95); padding: 8px 16px; border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  display: flex; align-items: center; gap: 10px; font-size: 13px; z-index: 50;
}
.info-artist { font-weight: 600; }
.info-score { color: #666; }

/* Voting */
.vote-btn {
  padding: 4px 12px; border: 1px solid #ddd; border-radius: 8px;
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 500;
}
.vote-btn:active { background: #eee; }
.vote-up { color: #2e7d32; }
.vote-down { color: #c62828; }

/* ===== RANKING ===== */
#rank-ui { padding: 8px; }
#rank-filters { display: flex; gap: 5px; padding: 4px 4px 10px; justify-content: center; }
.rank-sort {
  padding: 5px 14px; border: 1px solid #ccc; border-radius: 14px;
  background: #fff; font-size: 13px; cursor: pointer; font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
}
.rank-sort.active { background: #4CAF50; color: #fff; border-color: #4CAF50; }
#rank-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 0 4px; }
.rank-card {
  background: #fff; border-radius: 10px; overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.rank-image-wrap {
  position: relative;
  background-image:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  background-color: #f9f9f9;
}
.rank-image { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.rank-type-badge {
  position: absolute; top: 4px; right: 4px;
  font-size: 10px; background: rgba(0,0,0,0.5); color: #fff;
  padding: 2px 6px; border-radius: 8px; font-weight: 500;
}
.rank-meta { padding: 5px 8px 2px; }
.rank-artist { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-score { font-size: 11px; color: #888; }
.rank-votes { display: flex; gap: 4px; padding: 4px 6px 6px; }
.rank-votes .vote-btn {
  flex: 1; font-size: 12px; padding: 5px 3px;
  background: rgba(0,0,0,0.04); border: 1px solid rgba(0,0,0,0.08);
}
.vote-up.voted { background: rgba(46,125,50,0.15); border-color: rgba(46,125,50,0.3); color: #2e7d32; }
.vote-down.voted { background: rgba(198,40,40,0.15); border-color: rgba(198,40,40,0.3); color: #c62828; }
.report-btn {
  padding: 3px 8px; border: 1px solid #ddd; border-radius: 6px;
  background: #fff; cursor: pointer; font-size: 12px; color: #bbb;
  display: flex; align-items: center; justify-content: center;
}
.report-btn:active { color: #e74c3c; }
.rank-card-own { border: 2px solid #4CAF50; position: relative; }
.rank-card-own::after {
  content: 'Ваш'; position: absolute; top: 6px; left: 6px;
  background: #4CAF50; color: #fff; font-size: 9px; font-weight: 600;
  padding: 1px 6px; border-radius: 6px; z-index: 1;
}

/* Modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 14px; padding: 20px;
  width: 100%; max-width: 320px; box-shadow: 0 4px 24px rgba(0,0,0,0.2);
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.modal-input {
  width: 100%; border: 1px solid #ddd; border-radius: 8px;
  padding: 10px; font-size: 14px; resize: none; font-family: inherit;
  outline: none;
}
.modal-input:focus { border-color: #4CAF50; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-btn {
  padding: 8px 18px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 500; cursor: pointer;
}
.modal-cancel { background: #eee; color: #333; }
.modal-submit { background: #e74c3c; color: #fff; }

/* Toast */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 14px; z-index: 300; animation: toastFade 2.5s ease forwards;
}
@keyframes toastFade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Drawing detail modal */
.detail-modal {
  background: #fff; border-radius: 16px; padding: 16px;
  width: 90%; max-width: 340px; box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  text-align: center;
}
.detail-image-wrap {
  background-image:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0px;
  background-color: #f9f9f9;
  border-radius: 10px; overflow: hidden; margin-bottom: 12px;
}
.detail-image { width: 100%; display: block; }
.detail-info { margin-bottom: 12px; }
.detail-artist { font-size: 16px; font-weight: 600; }
.detail-score { font-size: 13px; color: #888; margin-top: 2px; }
.detail-actions { display: flex; gap: 8px; justify-content: center; }
.detail-share-btn {
  padding: 10px 22px; background: #ff6b6b; color: #fff; border: none;
  border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.detail-close-btn {
  padding: 10px 22px; background: #eee; color: #333; border: none;
  border-radius: 10px; font-size: 14px; font-weight: 500; cursor: pointer;
}
