:root {
  --ink: #2a1838;
  --grape: #6a3d9e;
  --grape-deep: #4a2674;
  --butter: #f3c14a;
  --sky: #7fd3e8;
  --meadow: #4faf78;
  --peach: #f4a698;
  --paper: #fff6ea;
  --paper-2: #f3e4c9;
  --wood: #b8895c;
  --line: rgba(42, 24, 56, 0.14);
  --shadow: 0 18px 40px rgba(74, 38, 116, 0.16);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Nunito, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(127, 211, 232, 0.45), transparent 28%),
    radial-gradient(circle at 88% 8%, rgba(244, 166, 152, 0.4), transparent 24%),
    radial-gradient(circle at 70% 90%, rgba(79, 175, 120, 0.25), transparent 30%),
    linear-gradient(180deg, #efe2ff 0%, var(--paper) 42%, #f7ebc8 100%);
}

h1, h2, h3, .brand strong {
  font-family: Fraunces, serif;
  font-weight: 700;
  margin: 0;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button {
  border: 0;
  border-radius: 999px;
  background: var(--grape);
  color: white;
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  font-weight: 800;
}
button:hover { background: var(--grape-deep); }
button.ghost {
  background: transparent;
  color: var(--grape-deep);
  border: 2px solid var(--line);
}
button.ghost:hover { background: rgba(106, 61, 158, 0.08); }
button.danger { color: #9b2743; }
button.active {
  background: var(--butter);
  color: var(--ink);
}

.screen { min-height: 100%; }
[hidden] { display: none !important; }
html[data-view="login"] #forgot-form,
html[data-view="login"] #reset-form,
html[data-view="login"] #app-screen { display: none !important; }
html[data-view="forgot"] #login-form,
html[data-view="forgot"] #reset-form,
html[data-view="forgot"] #app-screen { display: none !important; }
html[data-view="forgot"] #forgot-form { display: block !important; }
html[data-view="reset"] #login-form,
html[data-view="reset"] #forgot-form,
html[data-view="reset"] #app-screen { display: none !important; }
html[data-view="reset"] #reset-form { display: block !important; }
html[data-view="app"] #login-screen { display: none !important; }
html[data-view="app"] #app-screen { display: block !important; }
html[data-view="app"] #new-map-view { display: none !important; }
html[data-view="editor"] #login-screen { display: none !important; }
html[data-view="editor"] #app-screen { display: block !important; }
html[data-view="editor"] #dashboard,
html[data-view="editor"] #new-map-view { display: none !important; }
html[data-view="editor"] #editor { display: grid !important; }
html[data-view="new"] #login-screen,
html[data-view="profile"] #login-screen { display: none !important; }
html[data-view="new"] #app-screen,
html[data-view="profile"] #app-screen { display: block !important; }
html[data-view="new"] #dashboard,
html[data-view="new"] #editor { display: none !important; }
html[data-view="new"] #new-map-view { display: block !important; }
html[data-view="profile"] #profile-panel,
#profile-panel:not([hidden]) {
  display: grid !important;
  z-index: 80;
}

.login-card {
  width: min(460px, calc(100% - 2rem));
  margin: 8vh auto;
  background: rgba(255, 246, 234, 0.92);
  border: 3px solid #2a1838;
  border-radius: 28px;
  padding: 2.2rem 2rem 2rem;
  box-shadow: var(--shadow), 8px 8px 0 #2a1838;
}
.login-logo {
  display: block;
  width: min(320px, 100%);
  height: auto;
  margin: 0 auto 0.8rem;
  border-radius: 18px;
}
.login-mark { font-size: 3.2rem; line-height: 1; }
.eyebrow {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--grape);
  margin: 0.6rem 0 0.2rem;
}
.lede { color: #5a4468; margin: 0.4rem 0 1.4rem; }
.field { margin-bottom: 0.8rem; }
label { display: grid; gap: 0.28rem; font-weight: 800; font-size: 0.86rem; margin-bottom: 0.8rem; }
.field > label { margin-bottom: 0.28rem; }
input, select, textarea {
  border: 2px solid #2a1838;
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  background: white;
}
.error { color: #9b2743; font-weight: 800; min-height: 1.2em; }
.login-card form > button { width: 100%; margin-top: 1.2rem; }
.password-field {
  position: relative;
  display: block;
}
.password-field > input:not(.pw-toggle) {
  width: 100%;
  padding-right: 2.8rem;
}
.password-field > input.pw-input,
input.pw-input {
  -webkit-text-security: disc;
}
.password-field:has(.pw-toggle:checked) > input.pw-input {
  -webkit-text-security: none;
}
.password-field > input:not(.pw-toggle)::-ms-reveal,
.password-field > input:not(.pw-toggle)::-ms-clear {
  display: none;
}
.pw-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.eye {
  position: absolute;
  right: 0.3rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2.4rem;
  height: 2.4rem;
  margin: 0;
  padding: 0;
  background: #efe6ff;
  color: var(--grape-deep);
  border: 2px solid #2a1838;
  border-radius: 10px;
  display: grid;
  place-items: center;
  z-index: 2;
  cursor: pointer;
  font-weight: 800;
}
.eye:hover { background: rgba(106, 61, 158, 0.12); }
.eye svg { width: 1.2rem; height: 1.2rem; display: block; }
.eye .eye-off { display: none; }
.eye.is-on .eye-on,
.password-field:has(.pw-toggle:checked) .eye .eye-on { display: none; }
.eye.is-on .eye-off,
.password-field:has(.pw-toggle:checked) .eye .eye-off { display: block; }
.auth-links { text-align: center; margin: 0.9rem 0 0; }
button.link,
a.link {
  width: auto;
  margin: 0;
  padding: 0;
  background: none;
  color: var(--grape);
  font-size: 0.92rem;
  font-weight: 800;
  text-decoration: underline;
  border-radius: 0;
  display: inline;
  cursor: pointer;
}
button.link:hover,
a.link:hover { background: none; color: var(--grape-deep); }
.ok { color: #2f7d52; font-weight: 800; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1rem;
  background: rgba(255, 246, 234, 0.9);
  border-bottom: 3px solid #2a1838;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-start {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.brand { display: flex; gap: 0.7rem; align-items: center; }
.brand-mark {
  width: 2.6rem;
  height: 2.6rem;
  object-fit: cover;
  border-radius: 10px;
  flex: 0 0 auto;
}
.brand small { display: block; color: #6b547c; font-weight: 700; }
.top-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.inline-form { margin: 0; }
.app-menu {
  position: relative;
  z-index: 60;
}
.app-menu > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 2.6rem;
  padding: 0 0.85rem 0 0.7rem;
  border: 2px solid #2a1838;
  border-radius: 12px;
  background: white;
  font-weight: 800;
  color: var(--ink);
}
.app-menu > summary::-webkit-details-marker,
.app-menu > summary::marker { display: none; content: ''; }
.app-menu[open] > summary { background: #efe6ff; }
.menu-bars {
  width: 1.05rem;
  height: 2px;
  background: #2a1838;
  box-shadow: 0 -5px 0 #2a1838, 0 5px 0 #2a1838;
}
.menu-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 0.4rem);
  min-width: 280px;
  max-width: min(360px, 92vw);
  background: var(--paper);
  border: 3px solid #2a1838;
  border-radius: 16px;
  box-shadow: var(--shadow), 4px 4px 0 #2a1838;
  padding: 0.4rem;
  display: none;
  gap: 0.1rem;
}
.app-menu[open] .menu-panel { display: grid; }
.menu-heading {
  font-size: 0.72rem;
  font-weight: 800;
  color: #6b547c;
  padding: 0.35rem 0.85rem 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.menu-map-list {
  display: grid;
  gap: 0.12rem;
  max-height: 240px;
  overflow: auto;
  padding: 0 0.2rem 0.25rem;
}
.menu-empty {
  margin: 0;
  padding: 0.4rem 0.65rem;
  color: #6b547c;
  font-size: 0.85rem;
  font-weight: 700;
}
.menu-map-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem;
  align-items: center;
}
.menu-panel a,
.menu-panel button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font-weight: 800;
  text-decoration: none;
}
.menu-map-open {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu-map-del {
  width: auto;
  padding: 0.45rem 0.6rem;
  color: #9b2743;
  font-size: 0.78rem;
}
.menu-panel a:hover,
.menu-panel button:hover {
  background: rgba(106, 61, 158, 0.1);
  color: var(--grape-deep);
}
.menu-map-del:hover {
  background: rgba(155, 39, 67, 0.12);
  color: #9b2743;
}
.menu-panel form { margin: 0; }
a.ghost, a.new-map-btn, button.new-map-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.new-map-launch { margin: 0; }
button.new-map-btn,
a.new-map-btn {
  border-radius: 999px;
  background: var(--grape);
  color: white;
  padding: 0.7rem 1.15rem;
  font-weight: 800;
}
button.new-map-btn:hover,
a.new-map-btn:hover { background: var(--grape-deep); color: white; }

.dashboard { padding: 1.4rem; max-width: 1200px; margin: 0 auto; }
.dash-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1.2rem;
}
.dash-head p { margin: 0.35rem 0 0; color: #5a4468; }
.map-groups { display: grid; gap: 1.4rem; }
.group h3 { margin-bottom: 0.7rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.9rem; }
.card {
  background: var(--paper);
  border: 3px solid #2a1838;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 4px 4px 0 #2a1838;
}
.card.is-main { border-color: var(--butter); }
.badge-main {
  display: inline-block;
  margin: 0.4rem 0 0;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  background: var(--butter);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
}
.modal-card .check,
.inspector .check {
  margin: 0 0 0.8rem;
  font-weight: 800;
}
.meta { color: #6b547c; font-size: 0.85rem; margin: 0.35rem 0 0.8rem; }
.card-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.card-actions button { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

.editor {
  display: grid;
  grid-template-columns: 320px 1fr 280px;
  height: calc(100vh - 68px);
}
.palette, .inspector {
  background: rgba(255, 246, 234, 0.94);
  border-right: 3px solid #2a1838;
  overflow: auto;
  padding: 0.8rem;
}
.palette {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.tile-browser {
  flex: 1 1 auto;
  min-height: 220px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 0.12rem;
  margin: 0.35rem 0 0.65rem;
  padding: 0.2rem 0.15rem 0.4rem 0;
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid var(--line);
  border-radius: 14px;
}
.tile-folder, .tile-file {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 0.28rem 0.4rem;
  font-size: 0.82rem;
  font-weight: 800;
}
.tile-folder:hover, .tile-file:hover { background: rgba(106, 61, 158, 0.08); }
.tile-folder.active, .tile-file.active {
  background: var(--butter);
  border-color: #2a1838;
}
.tile-folder .twist {
  width: 0.9rem;
  flex: 0 0 auto;
  font-size: 0.72rem;
}
.tile-file img {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  image-rendering: pixelated;
  background: #e9dcc4;
  border-radius: 6px;
}
.tile-file span, .tile-folder span.name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-empty {
  margin: 0.8rem 0.6rem;
  color: #6b547c;
  font-size: 0.85rem;
  font-weight: 700;
}
.place-tile {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  gap: 0.7rem;
  align-items: center;
  width: 100%;
  margin: 0 0 0.55rem;
  border-radius: 16px;
  background: var(--grape);
  text-align: left;
  padding: 0.55rem;
  box-shadow: var(--shadow);
}
.place-tile:hover { background: var(--grape-deep); }
.place-tile.is-ready { box-shadow: 0 0 0 3px rgba(243, 193, 74, 0.55); }
.place-tile:disabled,
.place-tile:not(.is-ready) {
  opacity: 0.58;
}
.place-thumb img,
.tile-file img {
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}
.place-thumb {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border-radius: 10px;
  background:
    repeating-conic-gradient(#e9dcc4 0 25%, #d7c49a 0 50%) 0 0 / 16px 16px;
  overflow: hidden;
  border: 2px solid rgba(255, 246, 234, 0.35);
}
.place-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.place-copy {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}
.place-copy strong {
  font-size: 0.92rem;
  line-height: 1.2;
  word-break: break-word;
}
.place-copy small {
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.88;
}
.place-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}
.place-actions .ghost {
  padding: 0.4rem 0.5rem;
  font-size: 0.78rem;
}
.inspector { border-right: 0; border-left: 3px solid #2a1838; }
.panel-title {
  font-family: "Press Start 2P", monospace;
  font-size: 0.62rem;
  margin: 0.4rem 0 0.7rem;
  color: var(--grape-deep);
}
.search-row input { width: 100%; }
.folder-tree {
  display: grid;
  gap: 0.12rem;
  margin: 0.4rem 0 0.65rem;
  max-height: 34vh;
  overflow: auto;
  padding-right: 0.15rem;
}
.folder-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  text-align: left;
  background: white;
  color: var(--ink);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 0.32rem 0.45rem;
  font-size: 0.82rem;
  font-weight: 800;
}
.folder-row:hover { background: rgba(106, 61, 158, 0.08); }
.folder-row.active {
  background: var(--butter);
  border-color: #2a1838;
}
.folder-row .twist {
  width: 0.85rem;
  flex: 0 0 auto;
  font-size: 0.7rem;
}
.folder-row .count {
  margin-left: auto;
  color: #6b547c;
  font-size: 0.72rem;
  font-weight: 700;
}
.stamp-list, .tile-grid { margin: 0.4rem 0; }
.stamp-list { display: grid; gap: 0.35rem; }
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.4rem;
}
.stamp, .tile-icon {
  border: 2px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 0.35rem;
  cursor: pointer;
  color: var(--ink);
}
.stamp { display: flex; gap: 0.45rem; align-items: center; text-align: left; font-size: 0.8rem; }
.tile-icon {
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  padding: 0.35rem 0.2rem 0.4rem;
}
.stamp:hover, .tile-icon:hover { border-color: var(--grape); }
.stamp.active, .tile-icon.active { border-color: var(--butter); box-shadow: 0 0 0 3px rgba(243, 193, 74, 0.45); }
.stamp img { width: 48px; height: 48px; image-rendering: pixelated; background: #e9dcc4; }
.tile-icon img {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  background: #e9dcc4;
}
.tile-icon span {
  font-size: 0.62rem;
  line-height: 1.15;
  text-align: center;
  word-break: break-word;
}
.upload-form {
  display: grid;
  gap: 0.45rem;
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 2px solid var(--line);
}
.upload-form input[type='file'] {
  display: block;
  width: 100%;
  padding: 0.4rem;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 24, 56, 0.45);
  display: none;
  place-items: center;
  z-index: 80;
  padding: 1rem;
}
.modal-card {
  width: min(460px, 92vw);
  background: var(--paper);
  border: 3px solid #2a1838;
  border-radius: 22px;
  padding: 1.2rem;
  box-shadow: var(--shadow);
}
.new-map-screen { padding-bottom: 2rem; }
.new-map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 420px);
  gap: 1.2rem;
  align-items: start;
  max-width: 1180px;
  margin: 0 auto;
}
.size-preview-card {
  background: rgba(255, 246, 234, 0.94);
  border: 3px solid #2a1838;
  border-radius: 22px;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.size-preview-label {
  font-family: "Press Start 2P", monospace;
  font-size: 0.68rem;
  color: var(--grape-deep);
  margin: 0 0 0.75rem;
}
#size-preview-wrap {
  height: min(58vh, 520px);
  background:
    repeating-conic-gradient(#241634 0 25%, #1b1026 0 50%) 0 0 / 28px 28px;
  border-radius: 14px;
  overflow: hidden;
}
#size-preview { display: block; width: 100%; height: 100%; }
.new-map-page {
  width: min(520px, 100%);
  margin: 0;
}
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem; }
.modal-card .ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.stage { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; background: #1b1026; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding: 0.45rem;
  background: #3b2458;
  color: #fff6ea;
}
.toolbar button {
  background: transparent;
  border: 2px solid rgba(255, 246, 234, 0.25);
  color: #fff6ea;
  padding: 0.35rem 0.7rem;
}
.toolbar button.active { background: var(--butter); color: var(--ink); border-color: var(--butter); }
.tool-group { display: flex; flex-wrap: wrap; gap: 0.25rem; }
#floor-tabs button.floor-under { border-color: #7a5a2a; }
#floor-tabs button.floor-ground { border-color: #4faf78; }
#floor-tabs button.floor-over { border-color: #7fd3e8; }
.check { font-size: 0.8rem; font-weight: 800; display: flex; gap: 0.3rem; align-items: center; }
#canvas-wrap {
  position: relative;
  overflow: hidden;
  cursor: crosshair;
  background:
    linear-gradient(#0000, #0000),
    repeating-conic-gradient(#241634 0 25%, #1b1026 0 50%) 0 0 / 28px 28px;
}
#map-canvas { display: block; image-rendering: pixelated; }
.compass {
  position: absolute;
  right: 0.7rem;
  top: 0.7rem;
  width: 72px;
  height: 72px;
  border: 2px solid rgba(243, 193, 74, 0.85);
  border-radius: 50%;
  background: rgba(27, 16, 38, 0.72);
  color: #fff6ea;
  font-family: "Press Start 2P", monospace;
  font-size: 0.48rem;
  pointer-events: none;
}
.compass-n, .compass-s, .compass-e, .compass-w {
  position: absolute;
}
.compass-n { top: 0.35rem; left: 50%; transform: translateX(-50%); color: #f3c14a; }
.compass-s { bottom: 0.35rem; left: 50%; transform: translateX(-50%); }
.compass-w { left: 0.4rem; top: 50%; transform: translateY(-50%); }
.compass-e { right: 0.4rem; top: 50%; transform: translateY(-50%); }
.status {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.7rem;
  background: #2a1838;
  color: #f3c14a;
  font-family: "Press Start 2P", monospace;
  font-size: 0.55rem;
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.chip-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.chip-row label { font-size: 0.8rem; display: flex; align-items: center; gap: 0.3rem; }
.cell-info { background: white; border: 2px solid var(--line); border-radius: 12px; padding: 0.6rem; font-size: 0.85rem; margin-bottom: 0.8rem; }
.row-btns { display: flex; gap: 0.4rem; }
.hint { color: #6b547c; font-size: 0.85rem; }

dialog {
  border: 3px solid #2a1838;
  border-radius: 22px;
  padding: 1.2rem;
  background: var(--paper);
  box-shadow: var(--shadow);
  width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(42, 24, 56, 0.45); }
.keys { list-style: none; padding: 0; display: grid; gap: 0.35rem; }
kbd {
  font-family: "Press Start 2P", monospace;
  font-size: 0.52rem;
  background: #2a1838;
  color: var(--butter);
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
}

@media (max-width: 980px) {
  .editor { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; height: auto; }
  .palette, .inspector { border: 0; max-height: 280px; }
  #canvas-wrap { min-height: 55vh; }
  .new-map-layout { grid-template-columns: 1fr; }
  .new-map-page { width: 100%; }
  #size-preview-wrap { height: 42vh; }
}
