@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap');

:root {
  --paper: #f5f1e8;
  --paper-deep: #ebe4d6;
  --ink: #17223b;
  --muted: #6f746f;
  --blue: #3158d3;
  --blue-dark: #2445b2;
  --coral: #ee725b;
  --green: #3f8f76;
  --gold: #d49b37;
  --white: #fffefa;
  --line: #d8d1c3;
  --shadow: 0 18px 50px rgba(41, 50, 73, 0.12);
  --shadow-soft: 0 8px 24px rgba(41, 50, 73, 0.08);
  font-family: "Kanit", "Noto Sans Thai", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body, #app { min-height: 100%; margin: 0; }

body {
  min-width: 320px;
  background:
    radial-gradient(circle at 9% 8%, rgba(238, 114, 91, 0.09), transparent 26rem),
    radial-gradient(circle at 92% 4%, rgba(49, 88, 211, 0.09), transparent 25rem),
    var(--paper);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(49, 88, 211, 0.26);
  outline-offset: 2px;
}

.icon { width: 20px; height: 20px; display: block; }
.icon-sm { width: 17px; height: 17px; display: block; }

.home-shell { max-width: 1440px; margin: 0 auto; padding: 0 42px 70px; }
.home-nav {
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(23, 34, 59, 0.1);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: white;
  display: grid;
  place-items: center;
  background: var(--blue);
  transform: rotate(-4deg);
  box-shadow: 5px 5px 0 rgba(238, 114, 91, 0.55);
}
.brand-mark svg { width: 25px; height: 25px; }
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.brand-tagline { color: var(--muted); font-size: 12px; margin-top: -3px; }

.nav-note { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 14px; }
.nav-note-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(63, 143, 118, 0.13); }
.shell-exit { color: var(--blue); font-size: 13px; text-decoration: none; white-space: nowrap; }
.shell-exit:hover { text-decoration: underline; }

.hero {
  padding: 75px 0 54px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(390px, 0.74fr);
  align-items: center;
  gap: 72px;
}
.hero-copy { max-width: 710px; }
.eyebrow { display: flex; align-items: center; gap: 10px; color: var(--blue); font-weight: 600; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; }
.eyebrow::before { content: ""; width: 30px; height: 2px; background: var(--coral); }
.hero h1 {
  font-size: clamp(48px, 5.6vw, 82px);
  line-height: 1.14;
  letter-spacing: -0.045em;
  margin: 17px 0 21px;
  max-width: 850px;
}
.hero h1 em { color: var(--blue); font-style: normal; position: relative; white-space: nowrap; display: inline-block; }
.hero h1 em::after { content: ""; position: absolute; left: 2%; right: 0; bottom: 0; height: 9px; background: var(--coral); opacity: 0.3; transform: rotate(-1deg); z-index: -1; }
.hero-copy > p { color: var(--muted); font-size: 19px; line-height: 1.7; max-width: 600px; margin: 0; }
.hero-actions { display: flex; gap: 12px; margin-top: 30px; flex-wrap: wrap; }

.primary-btn, .secondary-btn, .tool-btn, .icon-btn, .danger-btn {
  border: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-weight: 600;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.primary-btn { min-height: 47px; padding: 0 21px; background: var(--blue); color: white; box-shadow: 0 8px 18px rgba(49, 88, 211, 0.22); }
.primary-btn:hover { background: var(--blue-dark); transform: translateY(-2px); box-shadow: 0 11px 24px rgba(49, 88, 211, 0.27); }
.primary-btn:disabled { color: #8a8f9b; background: #e8e9ed; box-shadow: none; cursor: not-allowed; transform: none; }
.secondary-btn { min-height: 47px; padding: 0 18px; background: rgba(255,255,255,0.55); color: var(--blue); border: 1px solid rgba(49,88,211,0.27); }
.secondary-btn:hover { background: white; transform: translateY(-2px); }
.danger-btn { min-height: 42px; padding: 0 14px; color: #b53c35; background: #fff3f0; border: 1px solid #f0c4bb; }

.hero-visual { height: 390px; position: relative; }
.sketch-card {
  position: absolute;
  inset: 15px 12px 18px 16px;
  border-radius: 30px;
  background-color: var(--white);
  background-image: radial-gradient(#d7d3c9 1px, transparent 1px);
  background-size: 18px 18px;
  border: 1px solid rgba(23,34,59,0.1);
  box-shadow: var(--shadow);
  transform: rotate(1.5deg);
  overflow: hidden;
}
.sketch-svg { width: 100%; height: 100%; }
.floating-label { position: absolute; background: var(--ink); color: white; border-radius: 10px; padding: 8px 13px; font-size: 13px; box-shadow: var(--shadow-soft); }
.floating-label.one { top: 0; right: 4px; transform: rotate(4deg); }
.floating-label.two { bottom: 0; left: 0; color: var(--ink); background: #f7d77d; transform: rotate(-3deg); }

.section-heading { display: flex; justify-content: space-between; align-items: end; margin: 22px 0 20px; gap: 20px; }
.section-heading h2 { font-size: 30px; margin: 0; letter-spacing: -0.02em; }
.section-heading p { margin: 5px 0 0; color: var(--muted); }
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.template-card {
  appearance: none;
  text-align: left;
  border: 1px solid rgba(23,34,59,0.11);
  border-radius: 22px;
  padding: 22px;
  background: rgba(255,254,250,0.72);
  color: var(--ink);
  min-height: 238px;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  position: relative;
  overflow: hidden;
}
.template-card::after { content: ""; width: 110px; height: 110px; border-radius: 50%; position: absolute; right: -45px; top: -45px; background: var(--accent-soft); }
.template-card:hover { transform: translateY(-6px) rotate(-0.35deg); box-shadow: var(--shadow); border-color: var(--accent); }
.template-preview { height: 100px; border-radius: 15px; background: var(--paper); margin-bottom: 17px; position: relative; overflow: hidden; }
.template-preview svg { width: 100%; height: 100%; }
.template-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.template-title strong { font-size: 20px; }
.template-title span { color: var(--accent); background: var(--accent-soft); border-radius: 50%; width: 33px; height: 33px; display: grid; place-items: center; }
.template-card p { color: var(--muted); line-height: 1.55; font-size: 14px; margin: 7px 0 0; }

.recent-section { margin-top: 50px; }
.recent-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.recent-card { border: 1px solid var(--line); background: rgba(255,254,250,0.7); border-radius: 16px; padding: 16px; min-width: 0; transition: background 150ms ease, transform 150ms ease; }
.recent-card:hover { background: var(--white); transform: translateY(-2px); }
.recent-open { background: none; border: 0; padding: 0; text-align: left; color: inherit; width: 100%; }
.recent-type { color: var(--blue); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.recent-card h3 { font-size: 16px; margin: 6px 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-meta { font-size: 12px; color: var(--muted); }
.recent-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.mini-delete { border: 0; color: #a95950; background: transparent; padding: 5px; border-radius: 7px; }
.mini-delete:hover { background: #fff0ec; }
.empty-state { border: 1px dashed #c7beaf; border-radius: 18px; padding: 28px; text-align: center; color: var(--muted); background: rgba(255,255,255,0.3); }

/* Editor */
.editor-shell { height: 100vh; min-height: 620px; display: grid; grid-template-rows: 67px 1fr; overflow: hidden; background: #ece9e1; }
.editor-shell-embedded { height: 720px; min-height: 560px; border: 1px solid var(--line); border-radius: 16px; }
.editor-shell-readonly .map-node { cursor: default; }
.editor-shell-readonly .editor-body { grid-template-columns: minmax(0, 1fr); }
.editor-shell-readonly .sidebar,
.editor-shell-readonly .mobile-inspector-toggle,
.editor-shell-readonly #undo,
.editor-shell-readonly #redo { display: none !important; }
.editor-header { background: rgba(255,254,250,0.93); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 18px; padding: 0 18px; z-index: 10; }
.header-left, .header-actions, .zoom-controls { display: flex; align-items: center; gap: 8px; }
.header-left, .header-actions { min-width: 0; }
.editor-brand { font-weight: 700; margin-left: 4px; }
.map-title-input { border: 0; border-bottom: 1px solid transparent; color: var(--ink); background: transparent; font-size: 18px; font-weight: 600; padding: 7px 5px 5px; min-width: 0; max-width: 490px; width: 100%; }
.map-title-input:hover { border-color: var(--line); }
.save-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-status.saved { color: #2d6f5c; }
.icon-btn { flex: 0 0 42px; width: 42px; min-width: 42px; height: 42px; min-height: 42px; padding: 0; background: transparent; color: var(--blue); border: 1px solid transparent; }
.icon-btn:hover { background: rgba(49,88,211,0.08); border-color: rgba(49,88,211,0.12); }
.tool-btn { min-height: 39px; padding: 0 13px; background: white; color: var(--blue); border: 1px solid rgba(49,88,211,0.23); }
.tool-btn:hover { background: #f3f6ff; }
.tool-btn:disabled, .icon-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.share-menu-wrap { position: relative; }
.share-menu { position: absolute; top: calc(100% + 8px); right: 0; width: 235px; padding: 7px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,254,250,0.98); box-shadow: var(--shadow); z-index: 30; }
.share-option { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; border-radius: 10px; padding: 10px; color: var(--blue); background: transparent; text-align: left; }
.share-option:hover { background: rgba(49,88,211,0.08); }
.share-option > span { display: grid; gap: 1px; }
.share-option strong { font-size: 14px; }
.share-option small { color: var(--muted); font-size: 11px; font-weight: 400; }

.editor-body { min-height: 0; display: grid; grid-template-columns: 302px 1fr; }
.sidebar { position: relative; top: auto; width: auto; height: auto; min-height: 0; display: flex; flex-direction: column; gap: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: auto; background: rgba(255,254,250,0.95); color: var(--ink); border-right: 1px solid var(--line); box-shadow: none; padding: 20px 17px 25px; z-index: 3; }
.side-label { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 9px; }
.type-pill { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; background: rgba(49,88,211,0.09); color: var(--blue); padding: 6px 10px; font-size: 12px; font-weight: 600; margin-bottom: 22px; }
.inspector-card { border: 1px solid var(--line); border-radius: 15px; padding: 14px; background: white; }
.inspector-empty { color: var(--muted); font-size: 14px; line-height: 1.6; padding: 10px 2px; }
.decoration-card { display: grid; gap: 11px; }
.decoration-selected { display: flex; align-items: center; gap: 8px; min-width: 0; padding-bottom: 4px; color: var(--ink); font-size: 14px; font-weight: 600; }
.decoration-selected > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.decoration-selected-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; box-shadow: 0 0 0 4px rgba(23,34,59,0.07); }
.decoration-label { margin-top: 6px; }
.swatch-grid { display: flex; flex-wrap: wrap; gap: 9px; }
.color-swatch { flex: 0 0 29px; width: 29px; min-width: 29px; height: 29px; min-height: 29px; padding: 0; border: 3px solid transparent; border-radius: 50%; background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(23,34,59,0.12); }
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.active { border-color: var(--ink); box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--ink); }
.color-swatch:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }
.theme-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.theme-option { min-width: 0; display: grid; justify-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 3px; color: var(--muted); background: #fffefa; font-size: 11px; }
.theme-option:hover, .theme-option.active { color: var(--blue); border-color: var(--blue); background: #f5f7ff; }
.theme-preview { width: 100%; height: 30px; border-radius: 6px; background-color: var(--theme-canvas); background-image: radial-gradient(var(--theme-grid) 1px, transparent 1px); background-size: 8px 8px; }
.decoration-help { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.text-field { width: 100%; border: 1px solid #d2cbbc; border-radius: 10px; min-height: 42px; padding: 9px 11px; color: var(--ink); background: #fffefa; }
textarea.text-field { overflow-y: hidden; resize: none; }
textarea.text-field { min-height: 78px; line-height: 1.45; }
.inspector-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 11px; }
.inspector-actions .primary-btn { min-height: 41px; padding: 0 12px; }
.outline-heading { display: flex; justify-content: space-between; align-items: center; margin-top: 25px; margin-bottom: 9px; }
.outline-heading .side-label { margin: 0; }
.node-count { font-size: 11px; color: var(--muted); }
.outline-list { display: flex; flex-direction: column; gap: 3px; }
.outline-row { width: 100%; min-width: 0; border: 0; border-radius: 9px; padding: 8px 9px; color: var(--ink); background: transparent; display: flex; align-items: center; gap: 7px; text-align: left; font-size: 13px; }
.outline-row:hover { background: rgba(49,88,211,0.06); }
.outline-row.active { background: rgba(49,88,211,0.1); color: var(--blue); font-weight: 600; }
.outline-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--node-color, var(--blue)); }
.outline-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.canvas-area { min-width: 0; min-height: 0; position: relative; overflow: hidden; background-color: var(--canvas-color, #eeece6); background-image: radial-gradient(var(--grid-color, #cbc7bd) 1px, transparent 1px); background-size: 22px 22px; }
.canvas-wrap { width: 100%; height: 100%; overflow: hidden; cursor: grab; touch-action: none; }
.canvas-wrap.dragging { cursor: grabbing; }
#map-canvas { width: 100%; height: 100%; display: block; user-select: none; }
.canvas-toolbar { position: absolute; left: 18px; top: 17px; display: flex; align-items: center; gap: 8px; z-index: 2; }
.canvas-chip { height: 36px; min-height: 36px; padding: 0 11px; border-radius: 10px; background: rgba(255,254,250,0.92); border: 1px solid var(--line); box-shadow: var(--shadow-soft); display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.canvas-chip b { color: var(--ink); }
.zoom-controls { position: absolute; right: 18px; bottom: 18px; padding: 5px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,254,250,0.94); box-shadow: var(--shadow-soft); z-index: 2; }
.zoom-value { width: 48px; text-align: center; font-size: 12px; color: var(--muted); }
.canvas-hint { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); color: var(--muted); background: rgba(255,254,250,0.78); border-radius: 999px; padding: 7px 12px; font-size: 11px; pointer-events: none; white-space: nowrap; }

.map-connector { fill: none; stroke-linecap: round; }
.map-node { cursor: pointer; filter: drop-shadow(0 5px 7px rgba(23,34,59,0.12)); }
.map-node .node-bg { stroke-width: 2; transition: stroke-width 120ms ease, filter 120ms ease; }
.map-node:hover .node-bg { stroke-width: 3; }
.map-node.selected .node-bg { stroke: var(--coral) !important; stroke-width: 4; filter: drop-shadow(0 0 5px rgba(238,114,91,0.35)); }
.map-node.editing .node-bg { stroke: var(--blue) !important; stroke-width: 4; }
.node-text { font-family: "Kanit", "Noto Sans Thai", Tahoma, sans-serif; font-weight: 500; pointer-events: none; }
.node-subtext { font-family: "Kanit", "Noto Sans Thai", Tahoma, sans-serif; font-weight: 300; pointer-events: none; opacity: 0.73; }
.node-controls { pointer-events: none; }
.node-control { pointer-events: all; cursor: pointer; }
.node-control circle { fill: #fffefa; stroke: var(--blue); stroke-width: 1.25; filter: drop-shadow(0 2px 3px rgba(23,34,59,0.12)); transition: transform 120ms ease, fill 120ms ease, stroke 120ms ease; transform-box: fill-box; transform-origin: center; }
.node-control text { fill: var(--blue); font-family: Kanit, sans-serif; font-size: 16px; font-weight: 600; pointer-events: none; }
.node-control-trash { pointer-events: none; }
.node-control-trash path { fill: none; stroke: var(--blue); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.node-control:hover circle, .node-control:focus circle { fill: #eff6ff; stroke: var(--blue-dark); transform: scale(1.06); }
.node-control.disabled { cursor: not-allowed; opacity: 0.32; }
.node-control.disabled circle { fill: #f8fafc; stroke: #94a3b8; }
.node-editor-foreign { overflow: visible; }
.inline-node-editor { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 3px; padding: 2px; font-family: Kanit, "Noto Sans Thai", Tahoma, sans-serif; }
.inline-node-field { display: block; width: 100%; min-height: 18px; border: 1px solid rgba(49,88,211,0.25); border-radius: 5px; padding: 2px 5px; color: var(--ink); background: rgba(255,254,250,0.94); font-family: inherit; font-size: 12px; font-weight: 500; line-height: 1.2; resize: none; overflow: hidden; }
.inline-node-note { min-height: 15px; font-size: 10px; font-weight: 300; }
.map-node.root .inline-node-field { color: white; border-color: rgba(255,255,255,0.5); background: rgba(255,255,255,0.16); }
.map-node.root .inline-node-field::placeholder { color: rgba(255,255,255,0.75); }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 9px; pointer-events: none; }
.toast { color: white; background: var(--ink); padding: 11px 15px; border-radius: 11px; box-shadow: var(--shadow); font-size: 14px; animation: toast-in 220ms ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.mobile-inspector-toggle { display: none; }

@media (max-width: 1000px) {
  .home-shell { padding-inline: 26px; }
  .hero { gap: 30px; grid-template-columns: 1.05fr 0.95fr; }
  .template-grid { grid-template-columns: repeat(2, 1fr); }
  .template-card:last-child { grid-column: span 2; }
  .recent-grid { grid-template-columns: repeat(2, 1fr); }
  .editor-body { grid-template-columns: 270px 1fr; }
  .header-text { display: none; }
}

@media (max-width: 760px) {
  .home-shell { padding: 0 17px 50px; }
  .home-nav { height: 74px; }
  .nav-note { display: none; }
  .brand-tagline { display: none; }
  .hero { display: block; padding: 48px 0 35px; }
  .hero h1 { font-size: clamp(43px, 14vw, 64px); line-height: 1.16; }
  .hero-copy > p { font-size: 16px; }
  .hero-visual { height: 285px; margin-top: 38px; }
  .template-grid { grid-template-columns: 1fr; }
  .template-card:last-child { grid-column: auto; }
  .recent-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: start; }

  .editor-shell { grid-template-rows: 60px 1fr; min-height: 520px; }
  .editor-header { grid-template-columns: auto 1fr auto; padding: 0 8px; gap: 7px; }
  .editor-brand, .save-status, .hide-mobile { display: none; }
  .map-title-input { font-size: 16px; }
  .editor-body { display: block; position: relative; }
  .canvas-area { width: 100%; height: 100%; }
  .sidebar { display: flex !important; flex-direction: column; position: absolute; left: 0; right: 0; bottom: 0; top: auto; z-index: 20; max-height: 72%; border-right: 0; border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; box-shadow: 0 -15px 50px rgba(23,34,59,0.14); transform: translateY(105%); transition: transform 220ms ease; padding-top: 18px; }
  .sidebar.open { transform: translateY(0); }
  .mobile-inspector-toggle { display: inline-flex; }
  .canvas-toolbar { top: 12px; left: 12px; }
  .canvas-hint { bottom: 72px; }
  .zoom-controls { right: 12px; bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
