/* 見た目の方針（仕様書 8章）：r/place のような、実用的で平らな現代の画面。
   白い札・細い実線・小さめの角丸・影なし。紺と金、紫のグラデ、すりガラス、光る演出は使わない */
:root {
  color-scheme: light;
  --map: #d7d6d1;        /* 地図の地（霧） */
  --grid: #b9b8b2;
  --panel: #ffffff;
  --line: #1f1f1f;       /* 札の枠 */
  --soft: #e6e5e1;       /* 区切り線・押せないボタン */
  --ink: #1a1a1a;
  --sub: #66645e;
  --accent: #e4572e;     /* 押すボタンの色 */
  --warn: #b3261e;
  --font: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  --emoji: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}
html, body { height: 100%; margin: 0; }
[hidden] { display: none !important; }
body { background: var(--map); color: var(--ink); font-family: var(--font); font-size: 14px; overflow: hidden; -webkit-user-select: none; user-select: none; }
button, input { font: inherit; color: inherit; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.fl { font-family: var(--emoji); font-size: 15px; line-height: 1; }

.box { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.box > .head { padding: 7px 10px 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: var(--sub); }
.box > .body { padding: 6px 10px 10px; display: grid; gap: 5px; }
.btn { background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 3px 10px; cursor: pointer; }
.btn:hover { background: #f1f0ec; }
.btn[aria-pressed="true"] { background: var(--ink); color: #fff; }
.btn.go { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn:disabled { background: var(--soft); border-color: var(--soft); color: var(--sub); cursor: default; }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.head .btn { padding: 1px 8px; font-size: 12px; font-weight: 400; color: var(--ink); }

#hud { position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); left: calc(10px + env(safe-area-inset-left, 0px)); width: max-content; min-width: 250px; max-width: min(420px, calc(100vw - 20px)); }   /* 数が長くなったら札が横に伸びる */
/* 自分が開いたマスの数（種類ごと） */
#mine { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 12px; font-variant-numeric: tabular-nums; }
#mine span { display: inline-flex; align-items: center; gap: 3px; }
#mine > .sub { flex-basis: 100%; margin-bottom: -4px; }   /* 見出しは1行目、数は2行目 */
#mine b { font-weight: 700; }
#mine b.m { color: #1b5e20; } #mine b.s { color: #d98a00; }
#mine i { font-style: normal; }
#mine .sh { width: 10px; height: 12px; }
.cellic { display: inline-block; width: 10px; height: 10px; background: #fff; border: 1px solid #1a1a1a; border-radius: 1px; margin-right: 4px; vertical-align: -1px; }   /* 普通のマス＝白い四角 */
#mine .cellic { margin-right: 0; }
#statLine { flex-wrap: nowrap; white-space: nowrap; overflow: hidden; gap: 10px; }   /* どんな数でも1行。入らない時は文字を小さくする */
.line b.m { color: #1b5e20; } .line b.s { color: #d98a00; }
#gp { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.line { display: flex; gap: 12px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.sub { color: var(--sub); font-size: 12px; }
#gate.locked { color: var(--warn); }
.acts { display: flex; gap: 6px; margin-top: 2px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; }
/* 押せるのはチェックの四角だけ。四角の周りを少し広めに押せるようにする（文字は押しても反応しない） */
.check .hit { display: grid; place-items: center; padding: 4px 6px; margin: -4px -6px; cursor: pointer; }
.check + .check { margin-top: 4px; }   /* 上下の押せる範囲が重ならないよう少し離す */
.check input { margin: 0; accent-color: var(--accent); cursor: pointer; }

#chat { position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); right: calc(10px + env(safe-area-inset-right, 0px)); width: 300px; display: flex; flex-direction: column; }
#chatLog { overflow-y: auto; margin: 4px 10px 8px; display: grid; align-content: start; gap: 3px; max-height: 64px; font-size: 12px; }
.msg { display: flex; align-items: center; gap: 5px; white-space: nowrap; min-width: 0; }   /* 1行に収める */
.msg img { image-rendering: pixelated; flex: none; }
.msg .pos { font-variant-numeric: tabular-nums; flex: none; }   /* 座標は省かない */
.msg.tight { gap: 3px; } .msg.tight time { font-size: 10px; } .msg.tight .reacts { gap: 3px; } .msg.tight .pos { font-size: 10px; } .msg.tight .reacts > span { font-size: 10px; }   /* 地図の端の長い座標＋大量リアクションの時だけ文字を小さくして1行に収める */
.msg time { flex: none; margin-left: auto; color: var(--sub); font-size: 11px; }
/* ピン留め：チャット欄の上に固定。履歴の中のピン留め済みは左に線 */
#chatHelp { padding: 1px 10px 0; font-size: 11px; white-space: nowrap; }
#chatPins { margin: 6px 10px 0; padding: 4px 6px; display: grid; gap: 3px; font-size: 12px; background: #f4f3ef; border-radius: 3px; }
#chatPins:empty { display: none; }
#chatPins .msg::before, #chatLog .msg.pinned::before { content: ''; width: 9px; height: 12px; flex: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 12'%3E%3Cpath d='M2 0h5v1H6v4l2 2v1H5v4H4V8H1V7l2-2V1H2z' fill='%23d9480f'/%3E%3C/svg%3E") no-repeat center / contain; }
#chatLog .msg { cursor: context-menu; }
/* グッド：数の表示と、届いた時の演出（行がふわっと光り、親指が浮き上がって消える） */
.msg .good { display: inline-flex; align-items: center; gap: 2px; font-size: 11px; color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.msg .good::before, .goodFx, #goodPop .thumb { content: ''; width: 12px; height: 12px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' shape-rendering='crispEdges'%3E%3Cpath d='M4 1h2v1h-2zM3 2h1v1h-1zM5 2h1v1h-1zM3 3h1v1h-1zM5 3h1v1h-1zM2 4h1v1h-1zM5 4h1v1h-1zM0 5h3v1h-3zM5 5h6v1h-6zM0 6h1v1h-1zM2 6h1v1h-1zM10 6h1v1h-1zM0 7h1v1h-1zM2 7h1v1h-1zM8 7h3v1h-3zM0 8h1v1h-1zM2 8h1v1h-1zM10 8h1v1h-1zM0 9h1v1h-1zM2 9h1v1h-1zM8 9h3v1h-3zM0 10h1v1h-1zM2 10h1v1h-1zM9 10h1v1h-1zM0 11h10v1h-10z' fill='%23212121'/%3E%3Cpath d='M4 2h1v1h-1zM4 3h1v1h-1zM3 4h2v1h-2zM3 5h2v1h-2zM1 6h1v1h-1zM3 6h7v1h-7zM1 7h1v1h-1zM3 7h5v1h-5zM1 8h1v1h-1zM3 8h7v1h-7zM1 9h1v1h-1zM3 9h5v1h-5zM1 10h1v1h-1zM3 10h6v1h-6z' fill='%23e4572e'/%3E%3C/svg%3E") no-repeat center / contain; image-rendering: pixelated; }
.msg .good.mine, .msg .done.mine { text-decoration: underline; text-underline-offset: 2px; }
/* 完了（チェック）：Shift＋右クリック */
.msg .done { display: inline-flex; align-items: center; gap: 2px; font-size: 11px; color: #2e7d32; font-weight: 700; font-variant-numeric: tabular-nums; }
.msg .done::before { content: ''; width: 12px; height: 12px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' shape-rendering='crispEdges'%3E%3Cpath d='M10 1h2v1h-2zM9 2h1v1h-1zM11 2h1v1h-1zM8 3h1v1h-1zM11 3h1v1h-1zM1 4h2v1h-2zM7 4h1v1h-1zM10 4h1v1h-1zM0 5h1v1h-1zM3 5h1v1h-1zM6 5h1v1h-1zM9 5h1v1h-1zM0 6h1v1h-1zM4 6h2v1h-2zM8 6h1v1h-1zM1 7h1v1h-1zM7 7h1v1h-1zM2 8h1v1h-1zM6 8h1v1h-1zM3 9h1v1h-1zM5 9h1v1h-1zM4 10h1v1h-1z' fill='%23212121'/%3E%3Cpath d='M10 2h1v1h-1zM9 3h2v1h-2zM8 4h2v1h-2zM1 5h2v1h-2zM7 5h2v1h-2zM1 6h3v1h-3zM6 6h2v1h-2zM2 7h5v1h-5zM3 8h3v1h-3zM4 9h1v1h-1z' fill='%232e7d32'/%3E%3C/svg%3E") no-repeat center / contain; image-rendering: pixelated; }
.msg .reacts { display: inline-flex; gap: 5px; flex: none; }
.msg .reacts:empty { display: none; }
.msg.got { animation: gotGood .9s ease-out; }
@keyframes gotGood { 0% { background: #fde3d9; } 100% { background: transparent; } }
.goodFx { position: fixed; width: 18px; height: 18px; pointer-events: none; z-index: 7; animation: goodFly 1s ease-out forwards; }
@keyframes goodFly { 0% { transform: translate(0, 0) scale(.6); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; } }
/* グッドが届いた時の大きめの札：画面の上のほう中央にポンと出て、しばらく届かなければ消える。クリックは邪魔しない */
#goodPop { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 7; pointer-events: none;
  display: flex; align-items: center; gap: 12px; padding: 10px 18px 10px 14px; background: #fff; border: 1px solid var(--ink); border-radius: 4px; transition: opacity .4s; }
#goodPop.hide { opacity: 0; }
#goodPop .thumb { width: 48px; height: 48px; }
#goodPop .thumb.bump { animation: thumbBump .35s ease-out; }
@keyframes thumbBump { 0% { transform: scale(1); } 40% { transform: scale(1.25) rotate(-8deg); } 100% { transform: scale(1); } }
#goodPop.pop { animation: popIn .3s ease-out; }
@keyframes popIn { 0% { transform: translateX(-50%) scale(.7); } 70% { transform: translateX(-50%) scale(1.06); } 100% { transform: translateX(-50%) scale(1); } }
#goodPop b { display: block; font-size: 24px; line-height: 1.1; }
#goodPop b span { color: var(--accent); font-variant-numeric: tabular-nums; }
#goodPop .who { display: flex; gap: 3px; margin-top: 3px; min-height: 16px; }
/* 中央が押された時の札：画面のまん中に大きく。押した人の国旗つき */
#endPop { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 9; pointer-events: none; text-align: center;
  padding: 18px 28px; background: #fff; border: 1px solid var(--ink); border-radius: 4px; animation: popIn2 .4s ease-out; }
#endPop b { display: block; font-size: 34px; color: var(--accent); }
#endPop .who { margin-top: 6px; }
#endPop .fl { font-size: 30px; }
@keyframes popIn2 { 0% { transform: translate(-50%, -50%) scale(.7); } 100% { transform: translate(-50%, -50%) scale(1); } }
/* ★が押された時の札：グッドの札の少し下に、全員の画面に出す（押した人の国旗つき） */
#starPop { position: fixed; left: 50%; top: calc(150px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 7; pointer-events: none;
  display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 10px; background: #fff; border: 1px solid var(--ink); border-radius: 4px; transition: opacity .4s; }
#starPop.hide { opacity: 0; }
#starPop.pop { animation: popIn .3s ease-out; }
#starPop .st { font-size: 28px; line-height: 1; color: #d98a00; }
#starPop b { font-size: 18px; white-space: nowrap; }
#starPop .who { display: flex; gap: 3px; align-items: center; }
@keyframes goodUp { 0% { transform: translateY(0) scale(.6); opacity: 0; } 25% { transform: translateY(-6px) scale(1.15); opacity: 1; } 100% { transform: translateY(-26px) scale(1); opacity: 0; } }
/* チャットの下のつまみ：上下にドラッグして履歴の高さを変える */
#chatGrip { height: 10px; cursor: ns-resize; touch-action: none; border-top: 1px solid var(--soft); position: relative; }
#chatGrip::after { content: ''; position: absolute; left: 50%; top: 3px; width: 28px; height: 3px; margin-left: -14px; border-top: 1px solid #b9b8b2; border-bottom: 1px solid #b9b8b2; }
#chatGrip:hover::after { border-color: var(--ink); }
#chatForm { padding: 8px 10px 10px; border-top: 1px solid var(--soft); display: grid; gap: 6px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
input[type="text"], #flagSearch { background: #fff; border: 1px solid var(--line); border-radius: 3px; padding: 3px 6px; -webkit-user-select: text; user-select: text; }
.coord { display: flex; align-items: center; gap: 3px; }
.coord input { width: 56px; font-variant-numeric: tabular-nums; }
.coord .sign { width: 26px; padding: 3px 0; text-align: center; font-weight: 700; }
.emos { display: flex; gap: 4px; flex-wrap: wrap; }
.emos .btn { width: 32px; height: 32px; padding: 0; display: grid; place-items: center; }
.emos .btn[aria-pressed="true"] { background: #fde3da; border-color: var(--accent); }
.emos img { width: 22px; height: 22px; image-rendering: pixelated; }
#cursorEmos .btn { position: relative; overflow: hidden; }
#cursorEmos .key { position: absolute; top: 1px; right: 2px; z-index: 1; }
#cursorEmos .cd { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgb(110 108 102 / 0.72); pointer-events: none; }
#cursorEmos.cooling img { filter: grayscale(1); opacity: 0.6; }
#chatToggle { display: none; }

#bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 20px); }
#bar .body { padding: 8px 10px; display: grid; gap: 6px; }
#bar .barrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#bar .barrow .label { width: 86px; margin: 0; white-space: nowrap; }
#bar .barrow .label .hint { font-weight: 400; font-size: 11px; }
#colorBar { display: flex; gap: 3px; flex-wrap: wrap; }
#colorBar button { width: 22px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 3px; cursor: pointer; }
#colorBar button { position: relative; }
#colorBar .key { position: absolute; top: 2px; left: 0; right: 0; text-align: center; }
/* 色とカーソルのキー表示：白い太字に黒いふち（どの色の上でも読める） */
#colorBar .key, #cursorEmos .key { font-size: 10px; line-height: 1; font-weight: 700; color: #fff;
  text-shadow: -1px 0 #1a1a1a, 1px 0 #1a1a1a, 0 -1px #1a1a1a, 0 1px #1a1a1a; }
#colorBar button[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 1px; }


#tip .info, #tip .gate { font-size: 14px; }
#hudTip { z-index: 8; }
#hudTip .info { font-size: 14px; color: #1b5e20; font-weight: 700; }
#hudTip .info.s { color: #d98a00; }
#tip .info { color: #1b5e20; font-weight: 700; }
#tip .info.done { color: #757575; }
#tip .how { color: var(--sub); font-size: 11px; }
#tip .gate { color: #1f4f9a; font-weight: 700; }
#tip .gate.locked { color: #b3261e; }
#tip, #hudTip { position: fixed; pointer-events: none; padding: 6px 8px; font-size: 12px; line-height: 1.55; max-width: 230px; z-index: 5; background: rgb(255 255 255 / 0.82); border: 1px solid rgb(31 31 31 / 0.7); border-radius: 3px; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(108px + env(safe-area-inset-bottom, 0px)); padding: 6px 12px; z-index: 6; background: var(--ink); color: #fff; border-radius: 3px; max-width: calc(100vw - 20px); }

#setup { position: fixed; inset: 0; z-index: 10; background: rgb(30 30 28 / 0.55); display: grid; place-items: center; overflow-y: auto;
  padding-block: calc(16px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
#setup .box { width: min(540px, 100%); }
#setup .head { font-size: 16px; color: var(--ink); padding: 14px 16px 0; }
#setup .body { gap: 14px; padding: 8px 16px 16px; }
#setup p { margin: 0; line-height: 1.6; color: var(--sub); }
#setup p b { color: var(--ink); }
#setup p.warn { color: #9c1f17; }
.label { margin-bottom: 5px; font-weight: 700; font-size: 13px; }
#flagSearch { width: 200px; max-width: 100%; margin-bottom: 6px; }
.flags { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 4px; max-height: 176px; overflow-y: auto; padding: 2px; border: 1px solid var(--soft); border-radius: 3px; }
.flags .btn { display: flex; align-items: center; gap: 6px; text-align: left; font-size: 12px; padding: 3px 6px; border-color: transparent; min-width: 0; }
.flags .btn span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.flags .btn[aria-pressed="true"] { background: #fde3da; color: var(--ink); border-color: var(--accent); }
.colors { display: flex; gap: 6px; flex-wrap: wrap; }
.colors button { width: 28px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 3px; cursor: pointer; }
.colors button[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }
.dirs { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 32px); gap: 4px; }
.dirs .mid { display: grid; place-items: center; font-size: 11px; color: var(--sub); }

@media (max-width: 760px) {
  #goodPop { top: 34%; }
  #starPop { top: calc(34% + 86px); }   /* スマホでは左上の札と重ならないよう少し下に */
  #chat { display: none; width: min(300px, calc(100vw - 20px)); top: auto; bottom: calc(132px + env(safe-area-inset-bottom, 0px)); }
  #chat.open-mobile { display: flex; }
  #chatToggle { display: inline-block; }
  #bar { left: calc(140px + env(safe-area-inset-left, 0px)); right: calc(10px + env(safe-area-inset-right, 0px)); transform: none; }
  #bar .label { display: none; }
  #bar .emos .btn { width: 28px; height: 28px; }
  #bar .emos img { width: 20px; height: 20px; }
  #toast { bottom: calc(140px + env(safe-area-inset-bottom, 0px)); }
}
#net { position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 11; padding: 4px 10px; background: var(--ink); color: #fff; border-radius: 3px; font-size: 12px; }

/* テスト用の世界のパネル（持ち主だけに出る） */
#testPanel { position: fixed; left: calc(10px + env(safe-area-inset-left, 0px)); bottom: calc(10px + env(safe-area-inset-bottom, 0px)); width: 250px; z-index: 6; border-color: var(--accent); }
#testPanel .body { display: grid; gap: 6px; }
#testPanel label { display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 6px; font-size: 13px; }
#testPanel input { min-width: 0; border: 1px solid var(--line); border-radius: 3px; padding: 2px 6px; font-variant-numeric: tabular-nums; }
#testPanel .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* 満員の画面（地図の上にまんなかの札を1枚） */
#full { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 12; padding: 18px 28px; display: grid; gap: 4px; text-align: center; }
#full b { font-size: 26px; }
#full span { font-variant-numeric: tabular-nums; }
