:root {
  --bg: #1b1626; --panel: #2a2236; --panel2: #352b45; --line: #4c3f60;
  --text: #f1e9da; --muted: #b7a9c4; --gold: #f2c35b; --fire: #ff6a3d;
  --good: #8fd18b; --warn: #f2c35b; --bad: #ff7a7a; --magic: #b58cff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif; overflow: hidden;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; }
button { font: inherit; color: inherit; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; }
button:hover { border-color: var(--gold); }
button:disabled { opacity: .45; cursor: default; }
button.on { background: #5a3f86; border-color: var(--magic); }
button.hint { animation: hint 1s ease-in-out infinite; border-color: var(--gold); }
@keyframes hint { 0%, 100% { box-shadow: 0 0 0 0 rgba(242, 195, 91, .0); } 50% { box-shadow: 0 0 0 4px rgba(242, 195, 91, .75); } }
button.primary { background: #a8461f; border-color: var(--fire); }
.hidden { display: none !important; }

#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
/* 上の資源バー（参考画像のように、暗い帯に絵記号と数字） */
#top { display: flex; align-items: center; gap: 22px; padding: 4px 14px; min-height: 46px; flex-wrap: nowrap;
  background: linear-gradient(#2a2130, #17121d); border-bottom: 2px solid #5b4632; box-shadow: 0 2px 8px rgba(0,0,0,.5);
  font-size: 17px; position: relative; z-index: 2; }
.res { white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.res b { color: #fff4dc; font-size: 1.1em; letter-spacing: .02em; }
.res small { color: var(--muted); font-size: .7em; }
.res .ic { width: 28px; height: 28px; object-fit: contain; filter: drop-shadow(0 1px 1px rgba(0,0,0,.6)); }
.cal { font-weight: bold; color: var(--gold); margin-right: 4px; } .cal small { color: var(--gold); }
.res.raid { margin-left: auto; padding: 3px 12px 3px 6px; border-radius: 999px; background: rgba(80,30,30,.55);
  border: 2px solid #8a5a3a; color: #ffd0b0; font-weight: bold; }
.res.raid.soon { color: #ff8a6a; border-color: #ff6a3d; animation: raidpulse 1s ease-in-out infinite; }
@keyframes raidpulse { 50% { box-shadow: 0 0 10px rgba(255,90,60,.8); } }
.speed { display: flex; gap: 4px; }
.speed button { padding: 3px 9px; min-width: 36px; }

#mid { flex: 1; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
/* 右の施設パネル（地図に重ねる） */
#panel { position: absolute; right: 10px; top: 10px; max-height: calc(100% - 20px); width: 250px; padding: 10px;
  background: rgba(24,19,30,.9); border: 2px solid #5b4632; border-radius: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.55);
  overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 8px; }
#panel h3 { margin: 0 0 4px; font-size: 15px; color: #fff4dc; }
#coach { background: #3b2a55; border: 1px solid var(--magic); border-radius: 8px; padding: 8px; }
#coach:empty { display: none; }
#info:empty { display: none; }
#info .row { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.07); }
#info .actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
#info .actions button.primary { border-radius: 999px; background: linear-gradient(#f0a040, #c86a1c); border-color: #ffd08a; color: #3a1c00; font-weight: bold; }
#voice .v { padding: 3px 0 3px 8px; border-left: 3px solid var(--muted); margin: 3px 0; }
#voice .v.good { border-color: var(--good); } #voice .v.warn { border-color: var(--warn); } #voice .v.bad { border-color: var(--bad); }

/* 下の建設パレット（大きな角丸のボタン） */
#palette { display: flex; gap: 10px; padding: 8px 12px; background: linear-gradient(#211a28, #120e17);
  border-top: 2px solid #5b4632; position: relative; z-index: 2; }
#palette button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; line-height: 1.15;
  padding: 6px 4px; border-radius: 14px; background: linear-gradient(#4a4150, #2e2834); border: 2px solid #5e5464;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 2px 4px rgba(0,0,0,.5); }
#palette button span { display: flex; flex-direction: column; align-items: center; }
#palette button b { font-size: 15px; letter-spacing: .05em; }
#palette small { color: var(--muted); font-size: 11px; }
#palette .pi { width: 34px; height: 34px; object-fit: contain; filter: drop-shadow(0 1px 1px rgba(0,0,0,.6)); }
#palette button.magic { background: linear-gradient(#5a3a86, #34204f); border-color: #9a6ad8; }
#palette button.magic b { color: #e8d6ff; }
#palette button.on { border-color: var(--gold); background: linear-gradient(#6a5236, #3e3020); }
#palette button.magic.on { border-color: #d4b0ff; box-shadow: 0 0 12px rgba(181,140,255,.8); }

/* 描く画面 */
#draw { position: fixed; inset: 0; background: rgba(12, 8, 20, .97); display: flex; align-items: stretch; z-index: 20; }
#dcanvas { flex: none; touch-action: none; display: block; margin: auto 0; border-radius: 12px;
  background: radial-gradient(circle, #2b2140 0%, #18121f 75%); }
.draw-side { flex: 1; padding: 12px; font-size: 13px; overflow-y: auto; min-width: 0; }
.draw-side h2 { margin: 0 0 8px; font-size: 16px; color: var(--magic); }
#d-step { font-size: 15px; margin-bottom: 8px; color: var(--gold); }
#d-sizes { display: flex; flex-direction: column; gap: 6px; }
#d-sizes button { text-align: left; font-size: 12px; }
.elem { margin: 8px 0; color: var(--muted); }
#d-msg { color: var(--bad); min-height: 2em; }
#d-result .rank { font-size: 42px; font-weight: bold; text-align: center; }
#d-result .rank.S { color: #ffe27a; text-shadow: 0 0 12px #ffcf40; } #d-result .rank.A { color: #ffb36b; }
#d-result .rank.B { color: #e6d3c0; } #d-result .rank.C { color: #a7a0b0; }
#d-result table { width: 100%; border-collapse: collapse; font-size: 12px; }
#d-result td { padding: 2px 4px; border-bottom: 1px solid var(--line); }
#d-result td:last-child { text-align: right; }
#d-buttons { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }

#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 30; }
#modal .box { background: var(--panel); border: 1px solid var(--gold); border-radius: 12px; padding: 14px 18px;
  max-width: min(560px, 92vw); max-height: 88vh; overflow-y: auto; font-size: 14px; }
#modal h2 { margin: 0 0 8px; color: var(--gold); font-size: 18px; }
#modal table { border-collapse: collapse; width: 100%; margin: 6px 0; }
#modal td { padding: 3px 6px; border-bottom: 1px solid var(--line); }
#modal .btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
#modal textarea { width: 100%; height: 90px; background: #120e1a; color: var(--text); border: 1px solid var(--line); font-size: 11px; }
.big { font-size: 28px; font-weight: bold; }

#rotate { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 99; align-items: center; justify-content: center; text-align: center; font-size: 20px; }
#rotate small { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }
@media (orientation: portrait) and (max-width: 900px) { #rotate { display: flex; } }

/* スマホ横（高さが低い） */
@media (max-height: 500px) {
  #top { font-size: 13px; gap: 12px; min-height: 34px; padding: 2px 8px; }
  .res .ic { width: 20px; height: 20px; }
  #panel { width: 200px; font-size: 11.5px; top: 6px; max-height: calc(100% - 12px); right: 6px; padding: 7px; }
  #palette { padding: 4px 8px; gap: 6px; }
  #palette button { padding: 2px; flex-direction: row; gap: 6px; border-radius: 10px; }
  #palette .pi { width: 24px; height: 24px; }
  #palette button b { font-size: 13px; }
  .draw-side { padding: 8px; font-size: 12px; }
  .draw-side h2 { font-size: 14px; margin-bottom: 4px; }
  #d-result .rank { font-size: 28px; line-height: 1; }
  #d-result td { padding: 0 4px; font-size: 11px; }
  #d-buttons { margin-top: 6px; gap: 4px; }
  #d-buttons button { padding: 4px 8px; }
}

/* 経済の最小セット（11/21） */
.res .em { font-size: 20px; line-height: 1; }
.res.warn b, .res.warn small { color: #ff9a7a; }
#palette .pe { font-size: 26px; line-height: 34px; height: 34px; }
@media (max-width: 1000px) {
  #top { gap: 9px; }
  .res .lbl { display: none; }
  .res .em { font-size: 16px; }
  .speed button { padding: 3px 6px; min-width: 30px; }
}
