:root {
  --ink: #19231f;
  --ink-soft: #5e6963;
  --paper: #f5f3ed;
  --panel: #fbfaf6;
  --line: #dcded6;
  --forest: #1d4c3b;
  --forest-deep: #14372b;
  --moss: #879d72;
  --gold: #d6a54d;
  --shadow: 0 14px 40px rgb(25 35 31 / 0.14);
  --topbar-height: 68px;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell { height: 100dvh; width: 100%; overflow: hidden; background: var(--paper); }

.topbar {
  position: relative;
  z-index: 30;
  height: var(--topbar-height);
  padding: 0 22px;
  display: grid;
  grid-template-columns: 330px 1fr auto;
  align-items: center;
  gap: 24px;
  color: #f6f4ed;
  background: var(--forest-deep);
  border-bottom: 1px solid rgb(255 255 255 / 0.08);
}

.brand { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 800; letter-spacing: .16em; }
.brand-mark {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid rgb(255 255 255 / .36); border-radius: 50%;
  color: #e7c67f; font-family: Georgia, serif; font-size: 19px; letter-spacing: 0;
}

.profile-heading { min-width: 0; display: flex; align-items: baseline; gap: 11px; }
.profile-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia, serif; font-size: 20px; font-weight: 500; }
.profile-kicker { flex: none; color: #aebcb5; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.save-indicator { display: flex; align-items: center; gap: 7px; color: #b9c6c0; font-size: 11px; }
.save-indicator i { width: 6px; height: 6px; border-radius: 50%; background: #8fbf90; box-shadow: 0 0 0 4px rgb(143 191 144 / .1); }
.save-indicator.saving i { background: #e5ba6b; animation: pulse 1s infinite; }
.save-indicator.error i { background: #e4846f; }

.mobile-panel-toggle { display: none; }
.workspace { height: calc(100dvh - var(--topbar-height)); display: flex; }

.sidebar {
  position: relative; z-index: 20; width: 352px; flex: 0 0 352px;
  background: var(--panel); border-right: 1px solid #d7d9d1;
  box-shadow: 8px 0 28px rgb(28 41 35 / .08);
  transition: transform .25s ease;
}
.sidebar-scroll { height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #c7cac1 transparent; }
.profile-section { padding: 20px 20px 18px; border-bottom: 1px solid var(--line); background: #f2f1eb; }
.section-label { margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; color: #506159; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .11em; }
.saved-date { color: #939b95; font-weight: 500; letter-spacing: .02em; text-transform: none; }
.profile-picker-row { display: grid; grid-template-columns: 1fr 40px; gap: 8px; }
.profile-picker-row select {
  width: 100%; min-width: 0; padding: 10px 34px 10px 12px; appearance: none;
  color: var(--ink); background: #fff; border: 1px solid #ccd1c9; border-radius: 4px;
  background-image: linear-gradient(45deg, transparent 50%, #52615a 50%), linear-gradient(135deg, #52615a 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px; background-size: 5px 5px; background-repeat: no-repeat;
  font-weight: 700; outline: none;
}
.profile-picker-row select:focus, .key-form input:focus, .modal input:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgb(29 76 59 / .1); }
.square-button { border: 0; border-radius: 4px; background: var(--forest); color: white; font-size: 21px; cursor: pointer; }
.square-button:hover { background: var(--forest-deep); }

.layers-section { padding: 22px 18px 20px; }
.section-title-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.section-title-row.compact { align-items: center; margin-bottom: 10px; }
.eyebrow { display: block; color: #7c877f; font-size: 9px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.section-title-row h2, .modal h2 { margin: 4px 0 0; font-family: Georgia, serif; font-size: 22px; font-weight: 500; letter-spacing: -.02em; }
.count-pill { min-width: 24px; padding: 4px 7px; text-align: center; border-radius: 20px; color: #526159; background: #e6e8e1; font-size: 10px; font-weight: 800; }

.empty-layers { margin: 8px 0 16px; padding: 24px 22px; text-align: center; border: 1px dashed #bdc4ba; border-radius: 7px; background: #f8f7f2; }
.empty-icon { width: 40px; height: 40px; margin: 0 auto 12px; display: grid; place-items: center; border: 1px solid #b9c1b6; border-radius: 50%; color: var(--forest); font-size: 23px; transform: rotate(-8deg); }
.empty-layers strong { display: block; font-family: Georgia, serif; font-size: 17px; font-weight: 500; }
.empty-layers p { margin: 7px auto 0; max-width: 220px; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }

.layer-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.layer-card { padding: 11px; border: 1px solid #d8dbd3; border-radius: 6px; background: #fff; transition: border-color .2s, box-shadow .2s; }
.layer-card:hover { border-color: #bdc5ba; }
.layer-card.is-editing { border-color: var(--gold); box-shadow: 0 0 0 2px rgb(214 165 77 / .16); }
.layer-row { display: flex; align-items: center; gap: 9px; min-width: 0; }
.visibility-toggle { flex: none; width: 19px; cursor: pointer; color: var(--forest); text-align: center; }
.visibility-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.visibility-toggle span { font-size: 17px; }
.layer-thumb { position: relative; width: 47px; height: 47px; flex: none; border-radius: 3px; background: #d9d4c5 center/cover no-repeat; overflow: hidden; box-shadow: inset 0 0 0 1px rgb(25 35 31 / .09); filter: sepia(.2); }
.layer-thumb::after { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, transparent 45%, rgb(255 255 255 / .24)); }
.layer-thumb span { position: absolute; left: 4px; bottom: 3px; z-index: 1; padding: 2px 3px; color: white; background: rgb(20 55 43 / .8); font-size: 8px; font-weight: 800; }
.layer-copy { flex: 1; min-width: 0; }
.layer-copy strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia, serif; font-size: 14px; font-weight: 600; }
.layer-copy span { display: block; margin-top: 4px; color: #7f8983; font-size: 10px; }
.more-button { width: 26px; height: 26px; flex: none; border: 0; border-radius: 4px; color: #8c9690; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; }
.more-button:hover { color: #8c4035; background: #f7ebe8; }
.opacity-row { margin-top: 10px; display: grid; grid-template-columns: 45px 1fr 34px; align-items: center; gap: 7px; color: #707b75; font-size: 9px; }
.opacity-row input { width: 100%; height: 3px; accent-color: var(--forest); cursor: pointer; }
.opacity-row output { color: #526059; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.align-button { width: 100%; margin-top: 9px; padding: 7px 8px; border: 1px solid #d6d9d1; border-radius: 4px; color: #526159; background: #f7f7f3; font-size: 10px; font-weight: 700; cursor: pointer; }
.align-button span { margin-right: 6px; font-size: 13px; }
.align-button:hover, .align-button.active { color: #76551d; border-color: #d6ad64; background: #fff9ed; }

.upload-button { width: 100%; padding: 11px 14px; border: 1px solid var(--forest); border-radius: 4px; color: white; background: var(--forest); font-size: 12px; font-weight: 800; cursor: pointer; }
.upload-button span { margin-right: 8px; font-size: 17px; line-height: 0; vertical-align: -1px; }
.upload-button:hover { background: var(--forest-deep); }
.upload-button:disabled { opacity: .65; cursor: wait; }
.upload-hint { margin: 8px 0 0; color: #909892; text-align: center; font-size: 9px; }

.key-section { margin-top: 2px; padding: 20px 18px 26px; border-top: 1px solid var(--line); background: #f2f1eb; }
.key-section h2 { margin: 3px 0 0; font-family: Georgia, serif; font-size: 18px; font-weight: 500; }
.key-section > p { margin: 0 0 12px; color: var(--ink-soft); font-size: 10px; line-height: 1.5; }
.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: #c6c8c2; box-shadow: 0 0 0 4px rgb(198 200 194 / .22); }
.connection-dot.connected { background: #76a66f; box-shadow: 0 0 0 4px rgb(118 166 111 / .16); }
.key-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.key-form input { min-width: 0; padding: 9px 10px; border: 1px solid #ccd1c9; border-radius: 4px; outline: none; font-size: 10px; }
.key-form button { padding: 8px 10px; border: 0; border-radius: 4px; color: white; background: #51675d; font-size: 10px; font-weight: 700; cursor: pointer; }
.database-section { padding: 20px 18px 26px; border-top: 1px solid var(--line); background: #ecebe4; }
.database-section h2 { margin: 3px 0 0; font-family: Georgia, serif; font-size: 18px; font-weight: 500; }
.database-section > p { margin: 0 0 12px; color: var(--ink-soft); font-size: 10px; line-height: 1.5; }
.database-mark { width: 25px; height: 25px; display: grid; place-items: center; border: 1px solid #c6ccc3; border-radius: 50%; color: var(--forest); background: #f7f7f2; font-size: 15px; }
.database-update { width: 100%; padding: 10px 12px; border: 1px solid #aeb8ae; border-radius: 4px; color: var(--forest-deep); background: #fafaf6; font-size: 10px; font-weight: 800; cursor: pointer; }
.database-update span { display: inline-block; margin-right: 6px; font-size: 13px; }
.database-update:hover { border-color: var(--forest); background: white; }
.database-update:disabled { opacity: .62; cursor: wait; }

.map-workspace { position: relative; flex: 1; min-width: 0; height: 100%; overflow: hidden; background: #d8dfd4; }
.map-surface { position: absolute; inset: 0; }
.map-placeholder { position: absolute; inset: 0; overflow: hidden; display: grid; place-items: center; background-color: #dce2d7; background-image: linear-gradient(rgb(38 70 55 / .08) 1px, transparent 1px), linear-gradient(90deg, rgb(38 70 55 / .08) 1px, transparent 1px), radial-gradient(circle at 70% 25%, #eef0e5 0 11%, transparent 11.4%), linear-gradient(135deg, #cbd7c7 0 24%, #e7e8dc 24% 51%, #c9d5c8 51% 64%, #dde3d6 64%); background-size: 42px 42px, 42px 42px, auto, auto; }
.map-placeholder::after { content: ""; position: absolute; inset: 0; opacity: .35; background: repeating-linear-gradient(28deg, transparent 0 88px, rgb(87 102 91 / .28) 89px 91px, transparent 92px 150px); }
.contour { position: absolute; width: 48%; aspect-ratio: 1.6; border: 2px solid rgb(36 77 58 / .17); border-radius: 48% 52% 41% 59%; transform: rotate(-18deg); }
.contour::before, .contour::after { content: ""; position: absolute; border: inherit; border-radius: inherit; inset: 20px; }
.contour::after { inset: 42px; }
.contour-one { left: -12%; top: 9%; }
.contour-two { right: -8%; bottom: 8%; transform: rotate(22deg) scale(.8); }
.placeholder-card { position: relative; z-index: 2; width: min(390px, calc(100% - 40px)); padding: 28px 32px 30px; text-align: center; color: #f4f2e9; background: rgb(20 55 43 / .94); box-shadow: var(--shadow); border: 1px solid rgb(255 255 255 / .12); }
.placeholder-card .eyebrow { color: #d5b66f; }
.placeholder-card h2 { margin: 8px 0 9px; font-family: Georgia, serif; font-size: 31px; font-weight: 400; }
.placeholder-card p { margin: 0 auto; max-width: 300px; color: #c3cec8; font-size: 12px; line-height: 1.6; }

.map-search { position: absolute; z-index: 5; top: 18px; left: 50%; width: min(430px, calc(100% - 120px)); height: 44px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 0 13px; border: 1px solid rgb(25 35 31 / .12); border-radius: 4px; background: rgb(255 255 255 / .96); box-shadow: 0 5px 20px rgb(25 35 31 / .16); }
.map-search > span { color: var(--forest); font-size: 22px; }
.map-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 12px; }
.map-search kbd { color: #929993; font-family: inherit; font-size: 9px; }
.locate-button { position: absolute; z-index: 5; right: 18px; bottom: 118px; width: 42px; height: 42px; border: 1px solid rgb(25 35 31 / .15); border-radius: 4px; color: var(--forest); background: white; box-shadow: 0 3px 14px rgb(25 35 31 / .17); font-size: 21px; cursor: pointer; }
.locate-button:hover { background: #f5f6f2; }
.locate-button.is-loading { animation: pulse 1s infinite; }
.edit-banner { position: absolute; z-index: 5; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: calc(100% - 44px); padding: 10px 14px; color: #57431e; background: #fff8e8; border: 1px solid #ddb967; box-shadow: 0 3px 15px rgb(49 38 18 / .14); font-size: 11px; white-space: nowrap; }
.edit-banner span { margin-right: 8px; font-weight: 800; }
.empty-map-note { position: absolute; z-index: 4; left: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 4px; padding: 12px 15px; color: #f5f3ec; background: rgb(20 55 43 / .9); box-shadow: var(--shadow); font-size: 10px; }
.empty-map-note strong { font-family: Georgia, serif; font-size: 14px; font-weight: 500; }
.map-error { position: absolute; z-index: 8; top: 18px; left: 50%; transform: translateX(-50%); width: min(480px, calc(100% - 40px)); padding: 12px 16px; color: #762f27; background: #fff0ed; border: 1px solid #e1a79d; box-shadow: var(--shadow); font-size: 12px; text-align: center; }

.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgb(12 28 22 / .56); backdrop-filter: blur(3px); }
.modal { width: min(430px, 100%); padding: 28px; background: var(--panel); box-shadow: 0 24px 70px rgb(8 25 18 / .35); }
.modal > p { margin: 9px 0 20px; color: var(--ink-soft); font-size: 12px; line-height: 1.55; }
.modal label { display: flex; flex-direction: column; gap: 7px; color: #53625b; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.modal input { padding: 11px 12px; border: 1px solid #cdd1ca; border-radius: 3px; outline: 0; color: var(--ink); font-size: 13px; font-weight: 400; letter-spacing: 0; text-transform: none; }
.modal-actions { margin-top: 22px; display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button { padding: 10px 15px; border: 1px solid var(--forest); border-radius: 3px; color: white; background: var(--forest); font-size: 11px; font-weight: 800; cursor: pointer; }
.modal-actions button.secondary { color: #56635d; border-color: #cdd1ca; background: white; }
.modal-actions button:disabled { opacity: .45; cursor: default; }
.toast { position: fixed; z-index: 120; right: 20px; bottom: 20px; max-width: min(360px, calc(100% - 40px)); padding: 12px 16px; color: white; background: #193f31; border-left: 3px solid #d8b463; box-shadow: var(--shadow); font-size: 11px; }

.app-loading { width: 100%; height: 100dvh; display: flex; align-items: center; justify-content: center; gap: 12px; color: #d7e0db; background: var(--forest-deep); font-family: Georgia, serif; }
.loading-mark { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid #70877c; border-radius: 50%; color: #e2bd6e; font-size: 23px; animation: pulse 1.3s infinite; }
.loading-error { width: min(420px, calc(100% - 40px)); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px; text-align: center; border: 1px solid #526d61; background: #183f31; }
.loading-error strong { color: #f5f3ed; font-family: Georgia, serif; font-size: 22px; font-weight: 500; }
.loading-error span { color: #bdcbc4; font-family: Arial, sans-serif; font-size: 12px; line-height: 1.5; }
.loading-error button { margin-top: 6px; padding: 9px 14px; border: 1px solid #d8b463; border-radius: 3px; color: #17392d; background: #e1c178; font-size: 11px; font-weight: 800; cursor: pointer; }

@keyframes pulse { 50% { opacity: .45; } }

@media (max-width: 760px) {
  :root { --topbar-height: 58px; }
  .topbar { grid-template-columns: 1fr auto; padding: 0 13px; gap: 10px; }
  .brand { font-size: 11px; letter-spacing: .12em; }
  .brand-mark { width: 29px; height: 29px; font-size: 17px; }
  .profile-heading, .save-indicator { display: none; }
  .mobile-panel-toggle { display: flex; align-items: center; gap: 6px; padding: 8px 10px; color: #f7f6f1; border: 1px solid rgb(255 255 255 / .2); border-radius: 4px; background: rgb(255 255 255 / .06); font-size: 10px; font-weight: 800; }
  .mobile-panel-toggle span { font-size: 14px; }
  .mobile-panel-toggle b { min-width: 17px; padding: 2px 4px; border-radius: 10px; color: var(--forest-deep); background: #d7bc79; font-size: 8px; }
  .workspace { position: relative; }
  .sidebar { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: min(62dvh, 520px); flex: none; border: 0; border-top: 1px solid #cfd4ca; box-shadow: 0 -10px 35px rgb(20 40 31 / .17); transform: translateY(0); }
  .sidebar::before { content: ""; position: absolute; z-index: 2; top: 7px; left: 50%; width: 34px; height: 4px; transform: translateX(-50%); border-radius: 5px; background: #c6cac2; }
  .sidebar.closed { transform: translateY(calc(100% + 20px)); }
  .sidebar-scroll { padding-top: 9px; }
  .profile-section { padding-top: 18px; }
  .map-search { top: 12px; left: 12px; width: calc(100% - 74px); transform: none; }
  .map-search kbd { display: none; }
  .locate-button { right: 12px; bottom: 20px; }
  .empty-map-note { left: 12px; right: 64px; bottom: 20px; }
  .edit-banner { bottom: 18px; width: calc(100% - 104px); white-space: normal; text-align: center; line-height: 1.4; }
  .placeholder-card { margin-top: -46px; padding: 24px 22px; }
  .placeholder-card h2 { font-size: 26px; }
  .toast { right: 12px; bottom: 12px; }
}

@media (max-width: 420px) {
  .layers-section { padding-left: 14px; padding-right: 14px; }
  .profile-section, .key-section, .database-section { padding-left: 14px; padding-right: 14px; }
  .map-search { height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
