/* ── Reset ─────────────────────────────────────────────────── */
body, html, div, canvas {
  margin: 0;
  padding: 0;
  border: 0;
}

/* ── Canvas ─────────────────────────────────────────────────── */
#gridCanvas {
  display: block;
  touch-action: none; /* prevent browser scroll/zoom from intercepting touch */
}

/* ── Login page ────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #f0f0f0;
  font-family: system-ui, sans-serif;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 48px 40px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.login-card h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  color: #111;
}

.login-subtitle {
  color: #666;
  margin: 0 0 32px;
  font-size: 0.95rem;
}

.auth-error {
  background: #fff0f0;
  border: 1px solid #f88;
  border-radius: 6px;
  color: #c00;
  font-size: 0.85rem;
  padding: 10px 14px;
  margin-bottom: 20px;
  text-align: left;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  color: #333;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 10px 20px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}

.btn-google:hover {
  background: #f5f5f5;
  border-color: #bbb;
}

.auth-unavailable {
  color: #888;
  font-size: 0.9rem;
}

/* ── User chip (toolbar) ────────────────────────────────────── */
#user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
}

.user-name {
  color: #999;
}

.logout-btn {
  background: transparent;
  border: 1px solid #555;
  border-radius: 4px;
  color: #aaa;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 10px;
  height: 40px;
}

.logout-btn:hover {
  background: #3c3c3c;
  color: #ddd;
}

.login-btn {
  background: transparent;
  border: 1px solid #555;
  border-radius: 4px;
  color: #aaa;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 10px;
  text-decoration: none;
  line-height: 40px;
  display: inline-block;
  height: 40px;
}

.login-btn:hover {
  background: #3c3c3c;
  color: #ddd;
}

/* ── Toggle panel button ───────────────────────────────────── */
#toggle-panel-btn {
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  right: 10px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  padding: 0;
  background: #282828;
  color: #ccc;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

#toggle-panel-btn:hover {
  background: #383838;
  color: #fff;
}

/* ── Bottom panel ──────────────────────────────────────────── */
.bottom-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  background: #282828;
  padding: 10px 12px;
  /* extend into iPhone home-bar area */
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  gap: 8px;
  box-sizing: border-box;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 1000;
  font-family: system-ui, sans-serif;
}

.bottom-panel.visible {
  transform: translateY(0);
}

.bottom-panel-row {
  display: flex;
  align-items: center;
  width: 100%;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Panel buttons ─────────────────────────────────────────── */
.bottom-panel-row button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: #3c3c3c;
  color: #ddd;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.bottom-panel-row button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.bottom-panel-row button:not(:disabled):hover {
  background: #505050;
  color: #fff;
}

/* save / delete buttons are text, not square icons */
.bottom-panel-row button[onclick="savePattern()"],
.bottom-panel-row button[onclick="deleteCurrentPattern()"] {
  width: auto;
  padding: 0 14px;
  font-size: 0.85rem;
}

/* ── Panel inputs ──────────────────────────────────────────── */
.bottom-panel-row input[type="text"] {
  height: 40px;
  min-width: 80px;
  width: 130px;
  box-sizing: border-box;
  border-radius: 4px;
  border: 1px solid #505050;
  background: #1e1e1e;
  color: #e0e0e0;
  padding: 0 8px;
  font-size: 0.9rem;
  font-family: system-ui, sans-serif;
}

.bottom-panel-row input[type="text"]::placeholder {
  color: #666;
}

.bottom-panel-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #888;
}

.public-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  color: #aaa;
  cursor: pointer;
}

/* ── Save status badge ─────────────────────────────────────── */
#save-status-badge {
  font-size: 0.75rem;
  border-radius: 10px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

#save-status-badge.save-status-public {
  background: #1b3a1e;
  color: #6dbf80;
  border: 1px solid #3a7d50;
}

#save-status-badge.save-status-private {
  background: #333;
  color: #888;
  border: 1px solid #505050;
}

/* ── Status / debug output ─────────────────────────────────── */
#grid-size-display {
  font-family: monospace;
  font-size: 0.8rem;
  color: #888;
}

.selectable {
  user-select: text;
  -webkit-user-select: text;
  min-width: 0;
  max-width: 280px;
  overflow-x: auto;
  white-space: nowrap;
  color: #999;
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  font-style: italic;
}

.non-selectable {
  user-select: none;
  -webkit-user-select: none;
}

.knit-mode-label {
  font-size: 0.85rem;
  color: #aaa;
  cursor: pointer;
}

/* ── Brush size row ────────────────────────────────────────── */
.brush-label {
  font-size: 0.85rem;
  color: #aaa;
}

.brush-size-display {
  font-family: monospace;
  font-size: 0.9rem;
  min-width: 1.5em;
  text-align: center;
  color: #fff;
}

/* ── Color swatches (fancy mode) ───────────────────────────── */
.bottom-panel-row .color-swatch {
  border: 3px solid transparent;
  box-sizing: border-box;
}

.bottom-panel-row .color-swatch.active {
  border-color: #fff;
}

.bottom-panel-row .color-swatch.bg-swatch {
  border: 3px dashed #888;
  position: relative;
}

/* ── Miniature list popup ──────────────────────────────────── */
.miniature-list-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.miniature-list-popup {
  background: #fff;
  border-radius: 8px;
  width: min(80%, 640px);
  height: min(70%, 90svh);
  max-height: 90svh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}

@media (max-width: 480px) {
  .miniature-list-popup {
    width: 96%;
    height: 85svh;
    border-radius: 4px;
  }
}

.miniature-list-header {
  display: flex;
  padding: 12px 16px;
  border-bottom: 1px solid #ddd;
  align-items: center;
  gap: 8px;
}

.miniature-list-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #555;
  margin-right: 8px;
  white-space: nowrap;
}

.miniature-search-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
}

.miniature-close-btn {
  background: #e44;
  color: #fff;
  border: none;
  border-radius: 4px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

.miniature-close-btn:hover {
  background: #c33;
}

.miniature-pattern-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.miniature-pattern-item {
  display: flex;
  align-items: center;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 6px;
  cursor: pointer;
  background: #fafafa;
  gap: 12px;
}

.miniature-pattern-item:hover {
  background: #e8f3ff;
  border-color: #08c;
}

.miniature-canvas {
  width: 64px;
  height: 64px;
  border: 1px solid #ccc;
  flex-shrink: 0;
  image-rendering: pixelated;
}

.miniature-pattern-info {
  flex: 1;
  min-width: 0;
}

.miniature-pattern-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #222;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.miniature-pattern-owner {
  font-size: 0.75rem;
  color: #888;
  margin-top: 2px;
}

.miniature-public-badge {
  font-size: 0.7rem;
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
  border-radius: 10px;
  padding: 1px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

.miniature-empty {
  text-align: center;
  color: #aaa;
  font-size: 0.9rem;
  padding: 32px 0;
}
