:root {
  --bg: #eef6f7;
  --ink: #1f2d3a;
  --sub: #5b6b78;
  --panel: #ffffff;
  --line: #cfdde3;
  --sea: #1b6f8a;
  --sea2: #d7eef3;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Hiragino Sans", "Noto Sans JP", sans-serif;
}
header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: var(--sea); color: #fff; flex-wrap: wrap;
}
header h1 { margin: 0; font-size: 1.25rem; }
.hdr-r { display: flex; gap: 8px; align-items: center; font-size: .9rem; }
button {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover { background: #f2f7f9; }
button.primary { background: var(--sea); color: #fff; border-color: var(--sea); }
button.primary:hover { background: #155a70; }
button:disabled { opacity: .45; cursor: default; }
header button { padding: 4px 10px; }

main {
  display: flex; gap: 16px; padding: 16px; align-items: flex-start; justify-content: center;
}
#board {
  width: min(680px, calc(100vw - 32px));
  aspect-ratio: 1;
  display: grid;
  grid-template: repeat(9, 1fr) / repeat(9, 1fr);
  gap: 3px;
  background: #9fd3df;
  padding: 3px;
  border-radius: 10px;
  flex-shrink: 0;
}
.cell {
  position: relative; background: #fff; border-radius: 4px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: clamp(7px, 1.35vw, 11.5px); line-height: 1.15; text-align: center;
  cursor: pointer; border: 3px solid transparent; min-width: 0;
}
.cell .band { position: absolute; top: 0; left: 0; right: 0; height: 22%; }
.cell .nm { margin-top: 14%; font-weight: 600; padding: 0 1px; word-break: break-all; }
.cell .val { color: var(--sub); }
.cell .ic { font-size: 1.7em; }
.cell.special { background: #f6fbfc; }
.cell.port { background: #ffe9a8; }
.cell.closed::after {
  content: "休"; position: absolute; right: 2px; bottom: 1px; color: #fff; background: #555;
  border-radius: 3px; padding: 0 2px;
}
.tokens { position: absolute; bottom: 2px; left: 2px; display: flex; gap: 1px; }
.tok { width: .95em; height: .95em; border-radius: 50%; border: 1.5px solid #fff; box-shadow: 0 0 0 1px #0004; }
.tok.cur { animation: bob .6s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-3px); } }

#center {
  grid-row: 2 / 9; grid-column: 2 / 9;
  background: linear-gradient(160deg, #e3f4f8, #c4e5ee);
  border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 12px; text-align: center;
}
#dice {
  width: 3.4em; height: 3.4em; font-size: clamp(18px, 4vw, 30px); background: #fff; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; box-shadow: 0 4px 10px #0002;
}
#dice.roll { animation: shake .3s linear infinite; }
@keyframes shake { 50% { transform: rotate(12deg); } }
#msg { font-size: clamp(12px, 2vw, 16px); font-weight: 600; min-height: 2.4em; max-width: 90%; }
#center .turn { font-size: clamp(11px, 1.8vw, 14px); color: var(--sub); }

aside { width: 340px; display: flex; flex-direction: column; gap: 12px; }
aside section { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
aside h2 { margin: 0 0 6px; font-size: .95rem; color: var(--sea); }
.pcard { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; padding: 6px 4px; border-radius: 6px; align-items: center; }
.pcard + .pcard { border-top: 1px solid var(--line); }
.pcard.active { background: var(--sea2); }
.pcard.out { opacity: .4; }
.pcard .dot { width: 14px; height: 14px; border-radius: 50%; grid-row: span 2; }
.pcard .nm { font-weight: 700; }
.pcard .nw { font-weight: 700; text-align: right; }
.pcard .sub { grid-column: 2 / 4; font-size: .8rem; color: var(--sub); display: flex; justify-content: space-between; }
.lights span { opacity: .25; }
.lights span.on { opacity: 1; }
#actions:empty { display: none; }
#actions { display: flex; flex-direction: column; gap: 8px; }
#actions button { padding: 10px; font-size: 1rem; }
#market { width: 100%; border-collapse: collapse; font-size: .85rem; }
#market td, #market th { padding: 3px 4px; text-align: right; }
#market td:first-child, #market th:first-child { text-align: left; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; border: 1px solid #0002; }
.up { color: #15803d; } .down { color: #c2410c; }
#log { margin: 0; padding-left: 1.2em; max-height: 220px; overflow-y: auto; font-size: .8rem; color: var(--sub); }
#log li { margin-bottom: 2px; }

#modal { position: fixed; inset: 0; background: #0006; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
#modal.hidden { display: none; }
#modal .box { background: #fff; border-radius: 10px; padding: 18px; width: min(460px, 100%); max-height: 90vh; overflow-y: auto; }
#modal h2 { margin: 0 0 10px; font-size: 1.15rem; color: var(--sea); }
#mBody { font-size: .92rem; line-height: 1.6; }
#mBody table { width: 100%; border-collapse: collapse; }
#mBody td, #mBody th { padding: 4px; border-bottom: 1px solid var(--line); text-align: right; }
#mBody td:first-child, #mBody th:first-child { text-align: left; }
#mBody .q { white-space: nowrap; }
#mBody .q button { padding: 0 8px; }
#mBody .q span { display: inline-block; width: 2.4em; text-align: center; }
#mBody select, #mBody input[type=text] { font: inherit; padding: 4px; }
#mBody input[type=range] { width: 100%; }
#mBody .err { color: #c2410c; }
#mBody .setup-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
#mBody .setup-row input { flex: 1; min-width: 0; }
#mBtns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.rules h3 { font-size: .95rem; margin: 12px 0 2px; }
.rules ul { margin: 0; padding-left: 1.2em; }

@media (max-width: 1060px) {
  main { flex-direction: column; align-items: center; }
  aside { width: min(680px, calc(100vw - 32px)); }
}
