/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Disable accidental text selection during drags. Drag handlers attach to
   `document`, so without this the browser highlights any text the cursor
   sweeps over (nav, labels, modal copy). Re-enable on real text inputs. */
#app, .modal-overlay {
  user-select: none;
  -webkit-user-select: none;
}
input, textarea, [contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
}

:root {
  --sand-light:  #f0d57a;
  --sand-mid:    #d4a843;
  --sand-dark:   #a07828;
  --nav-h:       58px;
  --panel-h:     140px;
  --tool-bar-w:  68px;
  --font:        'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: #1a1208;
  color: #f5e8c0;
  overflow: hidden;
}

#app { position: relative; }

/* ── Nav — fixed overlay ──────────────────────────────────────────────────── */
nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: rgba(12, 8, 2, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  z-index: 200;
}

.nav-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--sand-light);
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 4px;
  list-style: none;
}

.nav-link {
  display: inline-block;
  padding: 7px 18px;
  border-radius: 22px;
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.7);
  transition: background 0.18s, color 0.18s;
  cursor: pointer;
}
.nav-link:hover  { background: rgba(255,255,255,0.1); color: #fff; }
.nav-link.active { background: var(--sand-mid); color: #1a0e00; font-weight: 700; }

.nav-link.login-btn {
  border: 1.5px solid var(--sand-mid);
  color: var(--sand-light);
  font-weight: 600;
}
.nav-link.login-btn:hover { background: rgba(212,168,67,0.15); color: var(--sand-light); }
.nav-link.login-btn.active { background: var(--sand-mid); color: #1a0e00; border-color: var(--sand-mid); }

/* Language switcher — sits between title and links, anchored right */
.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  margin-right: 16px;
  padding: 3px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}
.lang-btn {
  min-width: 34px;
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.lang-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.lang-btn.active {
  background: var(--sand-mid);
  color: #1a0e00;
}
.lang-btn:focus-visible {
  outline: 2px solid var(--sand-light);
  outline-offset: 1px;
}

/* hidden attribute must beat display:flex */
[hidden] { display: none !important; }

/* ── Pages — true full-viewport ───────────────────────────────────────────── */
.page {
  position: fixed;
  inset: 0;
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ── Home page ────────────────────────────────────────────────────────────── */
#page-home {
  background:
    radial-gradient(ellipse 80% 60% at 50% 65%, #3d2800 0%, #1a0e00 65%),
    linear-gradient(180deg, #0e0800 0%, #1a1000 100%);
}

.home-content {
  text-align: center;
  max-width: 560px;
  padding: 2rem 1.5rem;
  margin-top: var(--nav-h); /* shift content below nav */
}
.home-content h1 {
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--sand-light);
  text-shadow: 0 2px 20px rgba(0,0,0,0.7);
  margin-bottom: 1.1rem;
  line-height: 1.1;
}
.home-content p {
  font-size: 1.05rem;
  color: rgba(255, 255, 255, 0.55);
  line-height: 1.75;
  margin-bottom: 2rem;
}

.home-cta {
  display: inline-block;
  padding: 13px 36px;
  background: var(--sand-mid);
  color: #1a0e00;
  border-radius: 28px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  border: none;
  transition: background 0.2s, transform 0.12s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(212, 168, 67, 0.35);
}
.home-cta:hover  { background: var(--sand-light); box-shadow: 0 6px 28px rgba(240,213,122,0.45); }
.home-cta:active { transform: scale(0.96); }

/* ── Sand Tray page ───────────────────────────────────────────────────────── */
#page-sandtray {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  background: #0e0a04;
}

/* ── Sand Tray Intro ──────────────────────────────────────────────────────── */
#st-intro {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 70% 55% at 50% 60%, #3a2400 0%, #0e0a04 65%);
}

.st-intro-content {
  text-align: center;
  max-width: 520px;
  padding: 2rem 1.5rem;
  margin-top: var(--nav-h);
}
.st-intro-icon {
  font-size: 4.5rem;
  margin-bottom: 1.2rem;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,0.6));
}
.st-intro-content h2 {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--sand-light);
  text-shadow: 0 2px 18px rgba(0,0,0,0.7);
  margin-bottom: 1rem;
  line-height: 1.15;
}
.st-intro-content p {
  font-size: 1rem;
  color: rgba(255,255,255,0.55);
  line-height: 1.75;
  margin-bottom: 2rem;
}

/* ── Sand Tray Session ────────────────────────────────────────────────────── */
#st-session {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding-top: var(--nav-h);
}

/* Tray area — fills remaining height, centers the tray */
#tray-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0e0a04;
  padding: 16px;   /* clearance so box-shadow frame is never clipped */
}

#tray-container {
  /* width + height set by JS to maintain 28.5:19.5 ratio */
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 0 0 6px #5c3a10,
    0 0 0 8px #3d2408,
    0 0 32px 10px rgba(0,0,0,0.7);
  border-radius: 3px;
}

#tray-container[data-tool="none"]    { cursor: default; }
#tray-container[data-tool="shovel"]  { cursor: crosshair; }
#tray-container[data-tool="flatten"] { cursor: cell; }
#tray-container[data-tool="hill"]    { cursor: copy; }

/* Canvas layers */
.water-canvas,
.sand-canvas {
  position: absolute;
  inset: 0;
  display: block;
}
.water-canvas { z-index: 1; }
.sand-canvas  { z-index: 2; }

/* Placed figures */
.tray-figure {
  position: absolute;
  z-index: 10;
  transform: translate(-50%, -50%);
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.tray-figure.dragging {
  cursor: grabbing;
  z-index: 20;
}

/* Figure emoji */
.tf-emoji {
  display: block;
  font-size: 2.6rem;
  line-height: 1;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,0.55));
  transition: filter 0.15s;
}
.tray-figure.dragging .tf-emoji {
  filter: drop-shadow(0 8px 18px rgba(0,0,0,0.65));
}

/* Selection ring */
.tray-figure.selected .tf-emoji {
  outline: 2px dashed rgba(212, 168, 67, 0.85);
  outline-offset: 3px;
  border-radius: 6px;
}

/* Transform handles — hidden until selected */
.tf-handle {
  display: none;
  position: absolute;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  z-index: 3;
}
.tray-figure.selected .tf-handle { display: flex; }

/* Rotate handle — arc above figure */
.tf-rotate {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(30, 20, 5, 0.88);
  border: 2px solid var(--sand-mid);
  color: var(--sand-light);
  font-size: 0.95rem;
  align-items: center;
  justify-content: center;
  top: -34px;
  left: 50%;
  transform: translateX(-50%);
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  transition: background 0.15s;
}
.tf-rotate:hover { background: var(--sand-dark); }

/* Resize handle — corner grip */
.tf-resize {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: rgba(30, 20, 5, 0.88);
  border: 2px solid var(--sand-mid);
  bottom: -12px;
  right: -12px;
  cursor: se-resize;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  /* diagonal arrow via CSS */
  background-image: linear-gradient(
    135deg,
    transparent 40%,
    var(--sand-mid) 40%,
    var(--sand-mid) 55%,
    transparent 55%
  );
  transition: border-color 0.15s;
}
.tf-resize:hover { border-color: var(--sand-light); }

/* ── Bottom bar — two rows ────────────────────────────────────────────────── */
#bottom-bar {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: rgba(14, 9, 2, 0.96);
  border-top: 1px solid rgba(255,255,255,0.07);
}

/* Row 1: tool buttons | category tabs | finish */
#bar-row1 {
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 64px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

#tool-buttons {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,0.07);
  height: 100%;
}

/* Category tabs — centered, fills remaining space in row 1 */
#figure-tabs {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
}
#figure-tabs::-webkit-scrollbar { display: none; }

#finish-area {
  display: flex;
  align-items: center;
  padding: 0 12px;
  flex-shrink: 0;
  border-left: 1px solid rgba(255,255,255,0.07);
  height: 100%;
}

/* Row 2: full-width figure scroll */
#figure-list {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Tool buttons ─────────────────────────────────────────────────────────── */
.tool-btn {
  width: 46px;
  height: 46px;
  border-radius: 11px;
  border: 2px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.07);
  color: #fff;
  font-size: 1.45rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  touch-action: manipulation;
  flex-shrink: 0;
}
.tool-btn:hover  { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.28); }
.tool-btn.active { background: var(--sand-mid); border-color: var(--sand-light); color: #1a0e00; }
.tool-btn:active { transform: scale(0.91); }

.finish-btn {
  width: auto;
  padding: 0 20px;
  background: #1e5c2e;
  border-color: #3d9e58;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #b8f5c8;
  text-transform: uppercase;
  border-radius: 11px;
}
.finish-btn:hover { background: #2a7a40; }

.save-btn {
  width: auto;
  padding: 0 18px;
  margin-right: 8px;
  background: rgba(212, 168, 67, 0.15);
  border-color: var(--sand-mid);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--sand-light);
  text-transform: uppercase;
  border-radius: 11px;
}
.save-btn:hover { background: rgba(212, 168, 67, 0.28); }

.fp-tab {
  padding: 4px 15px;
  border-radius: 15px;
  border: 1px solid rgba(255,255,255,0.13);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.65);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.fp-tab:hover  { background: rgba(255,255,255,0.12); color: #fff; }
.fp-tab.active { background: var(--sand-mid); border-color: var(--sand-light); color: #1a0e00; }

.fp-list {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 14px;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.13) transparent;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.fp-list::-webkit-scrollbar       { height: 3px; }
.fp-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.13); border-radius: 2px; }


.fp-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 62px;
  padding: 6px 4px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.09);
  background: rgba(255,255,255,0.04);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: background 0.15s, transform 0.12s;
  flex-shrink: 0;
}
.fp-item:hover  { background: rgba(255,255,255,0.11); transform: translateY(-3px); }
.fp-item:active { transform: scale(0.94); }

.fp-emoji { font-size: 1.85rem; line-height: 1; }
.fp-label {
  font-size: 0.61rem;
  color: rgba(255,255,255,0.6);
  white-space: nowrap;
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* ── Finish modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-box {
  background: linear-gradient(160deg, #2a1c06 0%, #1a1005 100%);
  border: 1px solid rgba(212, 168, 67, 0.3);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  max-width: 360px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.7);
}

.modal-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
}

.modal-box h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--sand-light);
  margin-bottom: 0.6rem;
}

.modal-box p {
  color: rgba(255,255,255,0.55);
  font-size: 0.95rem;
  line-height: 1.65;
  margin-bottom: 1.8rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-btn {
  padding: 10px 24px;
  border-radius: 22px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.75);
  transition: background 0.18s, color 0.18s, border-color 0.18s, transform 0.1s;
}
.modal-btn:hover  { background: rgba(255,255,255,0.13); color: #fff; }
.modal-btn:active { transform: scale(0.95); }
.modal-btn.primary {
  background: var(--sand-mid);
  border-color: var(--sand-light);
  color: #1a0e00;
}
.modal-btn.primary:hover { background: var(--sand-light); }

/* ── Stage 1 color picker ────────────────────────────────────────────────── */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 1.4rem 0 0.6rem;
}
.palette-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, transform 0.1s;
}
.palette-card:hover  { background: rgba(255, 255, 255, 0.10); border-color: var(--sand-mid); }
.palette-card:active { transform: scale(0.96); }
.palette-swatch {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 4px 12px rgba(0, 0, 0, 0.4);
}
.palette-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  letter-spacing: 0.02em;
}

/* ── Saved-sessions list (load modal) ────────────────────────────────────── */
.modal-wide { max-width: 460px; }

.load-list {
  list-style: none;
  margin: 0.6rem 0 1.2rem;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
}
.load-empty {
  display: block;
  text-align: center;
  padding: 1.4rem 0.4rem;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.95rem;
  list-style: none;
}
.load-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.04);
}
.load-item:hover { background: rgba(255, 255, 255, 0.08); }
.load-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.load-meta {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.load-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent;
  border: none;
  padding: 0;
  width: 100%;
  cursor: text;
}
.load-name:focus {
  outline: 1px solid var(--sand-mid);
  outline-offset: 2px;
  border-radius: 3px;
}
.load-date {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 2px;
}
.load-actions { display: flex; gap: 4px; flex-shrink: 0; }
.load-action {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.75);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.load-action:hover         { background: rgba(255, 255, 255, 0.10); }
.load-action.load-action-open   { background: var(--sand-mid); color: #1a0e00; border-color: var(--sand-light); }
.load-action.load-action-open:hover { background: var(--sand-light); }
.load-action.load-action-delete:hover {
  background: rgba(180, 60, 50, 0.25);
  border-color: rgba(220, 90, 80, 0.6);
  color: #fff;
}

/* ── Intro screen extras ─────────────────────────────────────────────────── */
.st-intro-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.home-cta-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  border: 1.5px solid rgba(255, 255, 255, 0.18);
}
.home-cta-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

.st-intro-recover {
  margin-top: 1.2rem;
  padding: 10px 14px;
  border: 1px solid rgba(212, 168, 67, 0.35);
  background: rgba(212, 168, 67, 0.08);
  border-radius: 10px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.75);
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.link-btn {
  background: none;
  border: none;
  color: var(--sand-light);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0 2px;
}
.link-btn:hover { color: #fff; }
.link-btn-muted { color: rgba(255, 255, 255, 0.55); font-weight: 500; }
.link-btn-muted:hover { color: rgba(255, 255, 255, 0.85); }

/* Toast (transient feedback for save) */
.toast {
  position: fixed;
  bottom: 168px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 14, 4, 0.92);
  color: var(--sand-light);
  border: 1px solid rgba(212, 168, 67, 0.4);
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* ── Contact & Login placeholder pages ───────────────────────────────────── */
#page-contact {
  background: radial-gradient(ellipse 70% 50% at 50% 55%, #0c1a2e 0%, #060c14 65%);
}
#page-login {
  background: radial-gradient(ellipse 70% 50% at 50% 55%, #14200e 0%, #080e04 65%);
}

.placeholder-content {
  text-align: center;
  max-width: 400px;
  padding: 2rem 1.5rem;
  margin-top: var(--nav-h);
}
.placeholder-icon {
  font-size: 4rem;
  margin-bottom: 1.2rem;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
}
.placeholder-content h2 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--sand-light);
  margin-bottom: 0.75rem;
}
.placeholder-content p {
  color: rgba(255,255,255,0.45);
  font-size: 1rem;
  line-height: 1.6;
}
