* { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  color-scheme: dark;
  --bg: #1c1815;
  --panel: #2a2420;
  --line: #43382f;
  --text: #eadfc8;
  --muted: #a89a82;
  --accent: #c9a25a;
  --danger: #b5533f;
}

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
h1 {
  margin: 0;
  font-size: 18px;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  letter-spacing: .08em;
}
.tag {
  font-size: 11px;
  font-family: sans-serif;
  letter-spacing: 0;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 1px 8px;
  margin-left: 6px;
  vertical-align: middle;
}
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

textarea { width: 100%; resize: vertical; line-height: 1.5; }
.row > textarea { margin-top: 4px; }
button, select, textarea, input[type="text"], input[type="number"] {
  font: inherit;
  color: var(--text);
  background: #382f29;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; border-color: var(--line); }
button.active { background: var(--accent); border-color: var(--accent); color: #221a10; font-weight: bold; }
button.primary { background: var(--accent); border-color: var(--accent); color: #221a10; font-weight: bold; }
button.danger { background: var(--danger); border-color: var(--danger); width: 100%; margin-top: 4px; }
input[type="text"], input[type="number"], select { width: 100%; min-width: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px 1fr 230px;
}
aside {
  background: var(--panel);
  overflow-y: auto;
  padding: 4px 12px 16px;
}
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }

section { padding: 10px 0; border-bottom: 1px solid var(--line); }
section:last-child { border-bottom: none; }
h2 { margin: 0 0 8px; font-size: 12px; color: var(--accent); letter-spacing: .1em; }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.tools button:first-child, .tools button.full { grid-column: 1 / -1; }

.kinds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kinds button {
  padding: 4px 0 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  gap: 1px;
  background: #e9dcba;
  color: #2b1d12;
}
.kinds button.active { background: var(--accent); }
.kinds canvas { width: 28px; height: 28px; }

.inline.auto input { width: 58px; flex: none; }
.inline.auto button { flex: 1; }
#nations { margin: 8px 0 6px; display: flex; flex-direction: column; gap: 4px; }
.nation { display: flex; gap: 4px; align-items: center; padding: 3px; border: 1px solid transparent; border-radius: 6px; cursor: pointer; }
.nation.active { border-color: var(--accent); background: rgba(201, 162, 90, .15); }
.nation input[type="color"] { flex: none; width: 28px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; }
.nation input[type="text"] { padding: 4px 6px; font-size: 12px; }
.nation button { flex: none; padding: 2px 8px; }
button.wide { width: 100%; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0 10px; }
.check + .note { margin-top: 8px; }

.row { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.row > input, .row > select, .row > .inline { margin-top: 4px; }
.inline { display: flex; gap: 6px; }
.inline button { padding: 6px 8px; }
.check { display: flex; align-items: center; gap: 6px; }
.note { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 0; }
.help { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.8; }

#stage {
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
#map {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  box-shadow: 0 6px 30px rgba(0, 0, 0, .6);
  touch-action: none;
  cursor: crosshair;
}
#map.tool-select { cursor: default; }
#map.panning { cursor: grabbing; }

button.gap { margin-top: 10px; }
button.rot { margin-bottom: 10px; }
.nation button { font-size: 11px; padding: 4px 6px; }
#focus-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(42, 36, 32, .94);
  border: 1px solid var(--accent);
  border-radius: 8px;
}
#focus-bar span { font-weight: bold; margin-right: 6px; }
#focus-bar button { padding: 3px 10px; }
#focus-bar button.push { margin-left: auto; }
.focused #hint { top: 64px; }
#hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 6px 14px;
  background: rgba(42, 36, 32, .92);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 13px;
  pointer-events: none;
}
.zoom {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  background: rgba(42, 36, 32, .92);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.zoom button { padding: 3px 10px; }
#zoom-label { min-width: 44px; text-align: center; font-size: 12px; color: var(--muted); }

/* 見出しを押して畳める欄 */
aside h2 { cursor: pointer; user-select: none; display: flex; justify-content: space-between; }
aside h2::after { content: "▾"; opacity: .6; }
section.collapsed h2 { margin-bottom: 0; }
section.collapsed h2::after { content: "▸"; }
section.collapsed > :not(h2) { display: none; }

.row.gap, .note.gap { margin-top: 10px; }
.note.len { margin: -4px 0 10px; color: var(--text); }
.inline.auto { margin-top: 2px; }

.biomes { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.biomes button { display: flex; align-items: center; gap: 5px; padding: 5px 6px; font-size: 12px; }
.biomes button.full { grid-column: 1 / -1; justify-content: center; }
.biomes i { flex: none; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .4); }
.biomes button.full i { display: none; }

/* 広告枠。番号を入れた場所だけ ads.js が表示する */
.ad-slot { display: block; margin-top: 12px; text-align: center; overflow: hidden; }
.ad-bottom { display: none; }

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  align-items: center;
  padding: 5px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
footer span { margin-right: auto; }
footer a { color: var(--accent); }

dialog {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  padding: 16px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 10px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-actions { display: flex; gap: 8px; margin-bottom: 12px; }

#maps-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.map-card { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.map-card.current { border-color: var(--accent); }
.map-card img { flex: none; width: 96px; height: 64px; object-fit: cover; border-radius: 4px; background: #1c1815; }
.map-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.map-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-info span { font-size: 12px; color: var(--muted); }
.map-btns { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.map-btns button { padding: 4px 10px; }
button.danger-text { color: #e08a78; }

#notes-list h3 { margin: 14px 0 6px; font-size: 14px; color: var(--accent); }
.note-item { display: block; width: 100%; text-align: left; margin-bottom: 4px; padding: 7px 10px; }
.note-item span { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); white-space: pre-wrap; }

/* スマホ・狭い画面: 地図を上に固定し、その下で操作欄をスクロールする */
@media (max-width: 900px) {
  html, body { height: auto; }
  header { padding: 6px 8px; gap: 6px; }
  h1 { font-size: 15px; }
  .actions { flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; }
  .actions button { flex: none; }
  main { display: flex; flex-direction: column; }
  #stage { order: -1; position: sticky; top: 0; z-index: 5; height: 56vh; height: 56svh; background: var(--bg); border-bottom: 1px solid var(--line); }
  #right { order: 0; }
  #right .ad-slot { display: none; }
  .ad-bottom { display: block; order: 2; margin: 12px; }
  #left { order: 1; }
  #left, #right { border: none; border-top: 1px solid var(--line); overflow: visible; }
  button, select, input[type="text"], input[type="number"] { padding: 9px 10px; }
  .nation button, .zoom button, #focus-bar button, .map-btns button { padding: 7px 10px; }
  .kinds { grid-template-columns: repeat(6, 1fr); }
  #focus-bar span { width: 100%; }
  #hint { font-size: 12px; width: calc(100% - 24px); text-align: center; }
  .focused #hint { top: 104px; }
  .map-card { flex-wrap: wrap; }
  .map-btns { width: 100%; }
  footer span { width: 100%; }
}

/* PNGを書き出したあとの案内 */
#export-note {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  max-width: calc(100% - 24px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  padding: 8px 12px;
  background: rgba(42, 36, 32, .96);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 13px;
}
#export-note a { color: var(--accent); }
#export-note button { padding: 0 8px; }
@media (max-width: 900px) {
  #export-note { left: 12px; bottom: 60px; }
}