:root {
  --bg: #f6f1e4;
  --panel: #fffdf8;
  --ink: #3a3226;
  --sub: #8a7f6a;
  --accent: #e07a5f;
  --line: rgba(60, 50, 30, 0.12);
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
}

#wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
}

header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}

header h1 {
  font-size: 20px;
  font-weight: 900;
  color: var(--accent);
  margin-right: auto;
  white-space: nowrap;
}
header h1 small { display: block; font-size: 11px; font-weight: 500; color: var(--sub); }

#clockDisplay, #weatherDisplay { font-weight: 700; font-size: 14px; white-space: nowrap; }
#eventBanner {
  background: #ffe9c7; border: 1px solid #e0b400; color: #7a5a00;
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap;
}

.controls { display: flex; gap: 6px; align-items: center; }
.speed-group { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.speed-btn, #pauseBtn, #resetBtn {
  border: none; background: var(--panel); color: var(--ink); font-weight: 700; font-size: 13px;
  padding: 7px 12px; cursor: pointer;
}
.speed-btn.active { background: var(--accent); color: #fff; }
#pauseBtn, #resetBtn { border: 1px solid var(--line); border-radius: 999px; }
#pauseBtn:hover, #resetBtn:hover, .speed-btn:hover { filter: brightness(0.96); }

#roster {
  display: flex; flex-wrap: wrap; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px;
}
.roster-avatar {
  width: 42px; height: 42px; border-radius: 50%; border: 2.5px solid #ccc;
  background: #fff; font-size: 20px; cursor: pointer; transition: transform .1s;
}
.roster-avatar:hover { transform: scale(1.08); }
.roster-avatar.selected { box-shadow: 0 0 0 3px rgba(224,122,95,0.35); }

main {
  display: flex; gap: 12px; flex: 1; min-height: 0;
}

#mapCard {
  flex: 1 1 60%; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; display: flex; flex-direction: column; gap: 8px; position: relative; min-width: 0;
}
#canvas { width: 100%; height: auto; aspect-ratio: 960 / 660; border-radius: 12px; cursor: pointer; background: #eef3e4; }

#sidePanel { flex: 0 0 340px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }

#detailPanel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: none; flex-direction: column; gap: 8px;
}
#detailPanel.open { display: flex; }
.detail-head { display: flex; align-items: center; gap: 10px; }
#detailAvatar {
  width: 48px; height: 48px; border-radius: 50%; border: 3px solid #ccc; background: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0;
}
.detail-titles { flex: 1; min-width: 0; }
#detailName { font-weight: 900; font-size: 17px; }
#detailRole { font-size: 12px; color: var(--sub); }
#detailClose {
  border: none; background: transparent; font-size: 18px; cursor: pointer; color: var(--sub); padding: 4px 8px;
}
#detailTraits { font-size: 12px; background: #f1ece0; display: inline-block; padding: 3px 10px; border-radius: 999px; width: fit-content; }
#detailActivity { font-size: 13px; font-weight: 700; }
#detailThought { font-size: 13px; color: var(--sub); font-style: italic; }

.need-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.need-row span:first-child { width: 60px; flex-shrink: 0; color: var(--sub); }
.need-bar { flex: 1; height: 8px; border-radius: 999px; background: #eee5d3; overflow: hidden; }
.need-bar > div { height: 100%; border-radius: 999px; transition: width .3s; }
#needEnergy { background: #4caf7d; }
#needSocial { background: #4f8ff0; }
#needFun { background: #f0a94f; }

#logCard {
  flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
#logCard h2 { font-size: 13px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--sub); }
#logList { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; }

.log-entry { font-size: 13px; display: flex; flex-direction: column; gap: 3px; transition: opacity .15s; }
.log-entry.dimmed { opacity: 0.25; }
.log-time { font-size: 10px; color: var(--sub); }
.log-system { background: #f1ece0; border-radius: 10px; padding: 6px 10px; }
.log-system .log-time { display: block; margin-bottom: 2px; }
.log-bubble {
  border-left: 3px solid #ccc; padding: 4px 0 4px 8px; display: flex; flex-direction: column; gap: 1px;
}
.log-name { font-weight: 800; font-size: 12px; }
.log-text { line-height: 1.4; }

footer { text-align: center; font-size: 11px; color: var(--sub); padding: 4px 0 10px; }
footer a { color: var(--accent); }

@media (max-width: 860px) {
  main { flex-direction: column; }
  #sidePanel { flex: none; }
  #logList { max-height: 42vh; }
  header h1 { font-size: 17px; }
}
