:root {
  color-scheme: dark;
  --surface: #18191b;
  --paper: #000;
  --ink: #f1f1f1;
  --muted: #c3c6cb;
  --border: #62666e;
  --line: #656970;
  --accent: #88c8ff;
  --active: #273d51;
  --origin: #173750;
  --preview: #85ccff;
  --warning: #ff9a86;
  font: 15px/1.5 "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--ink);
  background: var(--surface);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .65rem 1.5rem;
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
h1 { margin: 0; font-size: 1.25rem; }
.file-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
button, select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .4rem;
  padding: .4rem .65rem;
}
button { cursor: pointer; }
button:hover, select:hover { background: var(--active); border-color: var(--accent); }
button:active { box-shadow: inset 0 0 0 1px var(--accent); }
button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .55; cursor: wait; }
.primary { color: #102437; background: var(--accent); border-color: var(--accent); }
.primary:hover { background: #b5ddff; }
main { display: grid; grid-template-columns: 13rem minmax(0, 1fr); flex: 1; min-height: 0; }
#game-screen { display: block; overflow: auto; padding: clamp(1rem, 6vh, 4rem) 1rem; }
.game-panel {
  width: min(100%, 34rem);
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 1.75rem);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
#game-screen-title, #active-game { font-size: 1.15rem; color: var(--ink); overflow-wrap: anywhere; }
#active-game { padding: .5rem .85rem 0; }
#game-status { margin: .75rem 0; }
#game-status:empty, #game-error:empty { display: none; }
#game-status.error, #game-error { color: var(--warning); }
#game-error { margin: .35rem 0 0; }
.game-panel form { margin-top: 1rem; }
.game-panel label { display: block; margin-bottom: .3rem; font-weight: 700; }
.game-fields { display: flex; flex-wrap: wrap; gap: .4rem; }
.game-fields > :is(input, select) { flex: 1 1 12rem; min-width: 0; }
aside { overflow: auto; padding: .85rem; border-right: 1px solid var(--border); }
.settings { display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-weight: 700; }
#tools { display: grid; gap: .8rem; margin-top: .85rem; }
.tool-group { display: grid; align-content: start; gap: .25rem; }
h2 { margin: 0; font-size: .8rem; color: var(--muted); }
.tool {
  display: grid;
  grid-template-columns: 1.45rem 1fr;
  align-items: center;
  gap: .3rem;
  padding: .28rem .45rem;
  text-align: left;
  font-size: .88rem;
}
.tool span:first-child { text-align: center; font-family: "Segoe UI Emoji", sans-serif; }
.tool[aria-pressed="true"] { background: var(--active); border-color: var(--accent); font-weight: 700; }
#hint { margin: .85rem 0 0; color: var(--muted); font-size: .82rem; }
#tooltip {
  position: fixed;
  z-index: 1;
  max-width: min(19rem, calc(100vw - 16px));
  padding: .4rem .65rem;
  border: 1px solid #aaa;
  border-radius: .35rem;
  background: #fff;
  color: #18191b;
  font-size: .82rem;
  pointer-events: none;
}
.workspace { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.map-categories {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem 1.25rem;
  padding: .5rem .85rem;
  border-bottom: 1px solid var(--border);
}
.category {
  display: grid;
  grid-template-columns: auto minmax(0, 12rem) auto auto;
  align-items: center;
  gap: .35rem;
  max-width: 100%;
  font-size: .85rem;
}
.category label { font-weight: 700; }
.category select { width: 100%; min-width: 0; }
.category button { white-space: nowrap; }
#category-dialog {
  width: min(24rem, calc(100% - 2rem));
  padding: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}
#category-dialog::backdrop { background: #000a; }
#category-form { display: grid; gap: .5rem; }
#category-title { font-size: 1.1rem; color: var(--ink); }
#category-name, #game-name {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: .4rem;
  padding: .45rem .65rem;
}
#category-name:focus-visible, #game-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#game-name { width: auto; }
#category-error { margin: 0; color: var(--warning); }
#category-error:empty { display: none; }
#category-form .file-actions { justify-content: end; margin-top: .35rem; }
.map { flex: 1; position: relative; min-height: 0; background: var(--paper); }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
canvas.pan { cursor: grab; }
canvas.dragging { cursor: grabbing; }
footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem 1rem;
  padding: .45rem .85rem;
  border-top: 1px solid var(--border);
  font-size: .85rem;
}
#position { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#status { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#status.error { color: var(--warning); }
#home { margin-left: auto; }
@media (max-width: 660px), (max-height: 490px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  aside { max-height: 34dvh; border-right: 0; border-bottom: 1px solid var(--border); }
  .settings { justify-content: start; }
  #tools { display: flex; flex-wrap: wrap; }
  .tool-group { display: flex; flex-wrap: wrap; align-items: center; }
}
.edit-dialog {
  width: min(30rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  border: 1px solid var(--border);
  border-radius: .5rem;
  background: var(--surface);
  color: var(--ink);
}
.edit-dialog::backdrop { background: #000a; }
.edit-dialog form { display: grid; gap: .45rem; }
.edit-dialog h2 { font-size: 1.15rem; color: var(--ink); }
.edit-dialog :is(input, textarea) { font: inherit; padding: .35rem; }
.edit-dialog textarea { resize: vertical; }
.edit-dialog .file-actions { justify-content: end; }
.part-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: .35rem;
  width: 100%;
  max-height: 14rem;
  overflow: auto;
  padding: 3px;
}
.part-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: .2rem;
  min-width: 0;
  padding: .3rem;
  font-size: .78rem;
  overflow-wrap: anywhere;
}
.part-card[aria-pressed="true"] { background: var(--active); border-color: var(--accent); }
.part-card canvas, #part-preview { position: static; width: auto; height: auto; background: var(--paper); cursor: inherit; }
#part-image-fields { display: grid; gap: .35rem; justify-items: start; }
#part-image { max-width: 100%; }
.account-page { display: block; overflow: auto; padding: 2rem 1rem; }
.account-form { display: grid; gap: .5rem; margin-bottom: 1rem; }
.account-form input {
  width: 100%;
  padding: .5rem;
  font: inherit;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: .35rem;
}
.account-actions { align-items: center; margin-top: 1rem; }
#admin-menu { display: grid; gap: .6rem; margin-bottom: 1rem; }
#admin-menu a {
  display: block;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: .35rem;
  font-weight: 700;
}
#admin-menu a:hover { background: var(--surface); }
#admin-menu a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
#shape-canvas {
  position: static;
  width: min(100%, 320px);
  height: auto;
  aspect-ratio: 1;
  background: var(--paper);
  border: 1px solid var(--border);
}
.account-form .shape-checkbox input { width: auto; }
#shape-list { width: 100%; min-width: 0; }
#shape-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
