/* AcrobatLine — 美術館のデザイン
   壁 = 暗い色＋上からのスポットライト、パネル = クリーム色の銘板、金の縁取り、見出しは明朝体 */
:root {
  --wall: #2b2224;
  --wall-text: #efe5d2;
  --wall-muted: #b9a98f;
  --bg: #e9e0cd;          /* 入力欄など */
  --panel: #f4eddf;       /* 銘板・カード */
  --text: #2e2520;        /* 銘板の上の文字（盤面の線もこの色） */
  --muted: #7d6f5f;
  --line: #d6c8ab;
  --gold: #c9a24f;
  --gold-light: #ecd391;
  --accent: #8a2f38;      /* 主なボタン（えんじ） */
  --accent2: #3f6b5c;     /* クリア・強調（深い緑） */
  --error: #b3362f;
  --filled: #e3cf9c;      /* 塗ったマス */
  --star: #e0ae3c;
  --serif: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", "Times New Roman", serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--wall-text);
  font-family: system-ui, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--wall);
}
/* 背景は画面に固定した層に描く（background-attachment: fixed はスマホで効かないことがあるため）
   壁: 上からのスポットライトと、細い縦じまの壁紙 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 90% 45% at 50% 0%, rgba(255, 226, 170, .16), transparent 70%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .025) 0 2px, transparent 2px 28px),
    var(--wall);
}
/* タイトルまわりの画面は、図書館の絵を背景に */
body[data-screen="s-loading"]::before, body[data-screen="s-title"]::before, body[data-screen="s-entry"]::before,
body[data-screen="s-register"]::before, body[data-screen="s-login"]::before, body[data-screen="s-issued"]::before {
  background:
    linear-gradient(rgba(25, 15, 12, .25), rgba(25, 15, 12, .78)),
    url("img/library.jpg") center / cover no-repeat,
    var(--wall);
}

#app {
  max-width: 420px;
  margin: 0 auto;
  padding: 48px 16px;
  text-align: center;
}
.logo {
  font-family: var(--serif);
  font-size: 44px;
  font-weight: 600;
  letter-spacing: .04em;
  margin: 0 0 36px;
  color: var(--wall-text);
  text-shadow: 0 2px 12px rgba(0, 0, 0, .6);
}
.logo span { color: var(--gold-light); }

.screen { display: none; flex-direction: column; gap: 12px; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* 銘板（カード） */
.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--gold);
  border-radius: 4px;
  padding: 24px;
  box-shadow: inset 0 0 0 4px var(--panel), inset 0 0 0 5px rgba(201, 162, 79, .5), 0 10px 26px rgba(0, 0, 0, .45);
}
.card p { margin: 0; }
.lead { font-family: var(--serif); font-size: 19px; margin: 0 0 12px; text-shadow: 0 1px 8px rgba(0, 0, 0, .7); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
.hint.wall { color: var(--wall-muted); margin: 0; }
.error { color: var(--error); font-size: 14px; min-height: 1em; }
.error:empty { display: none; }

label { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 14px; }
input {
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbf7ee;
  color: var(--text);
}
input:focus { outline: 2px solid var(--gold); border-color: transparent; }

button {
  font: inherit;
  font-size: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--gold); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--gold); color: #fbf3e2; font-weight: bold; }
button.primary:hover { filter: brightness(1.1); }
button.link { background: none; border: none; color: var(--wall-muted); text-decoration: underline; padding: 6px; font-size: 14px; }
.card button.link { color: var(--muted); }
button.small { padding: 6px 12px; font-size: 14px; }
button.big { font-family: var(--serif); font-size: 21px; padding: 16px; letter-spacing: .2em; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); }
.title-sub { display: flex; flex-direction: column; margin-top: 8px; }

.pid {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 30px;
  font-weight: bold;
  letter-spacing: .12em;
  color: var(--accent2);
  user-select: all;
}

.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.topbar > :first-child { justify-self: start; }
.topbar > :last-child { justify-self: end; }
.screen-title, #p-title { font-family: var(--serif); font-size: 20px; color: var(--gold-light); letter-spacing: .1em; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 5, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.overlay .card { width: 100%; max-width: 360px; }

/* ステージ選択 */
.stage-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stage-item {
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  padding: 10px;
}
.stage-item .num {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--line);
  font-weight: bold;
  font-size: 13px;
  flex: none;
}
.stage-item.cleared .num { background: var(--gold); color: #3a2a12; }
.stage-item.locked { opacity: .55; }
.stage-item.locked .num { background: none; font-size: 18px; }
.stage-summary { margin: 0; text-align: right; color: var(--star); font-weight: bold; }
.stage-item .info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stage-item .info b { font-family: var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.stage-item .info small { color: var(--muted); font-size: 13px; }
.stage-item .stars-mini { color: var(--line); font-size: 13px; letter-spacing: .05em; position: absolute; right: 8px; bottom: 6px; }
.stage-item .stars-mini b { color: var(--star); font-weight: normal; }
.stage-rest { grid-column: 1 / -1; margin: 4px 0 0; color: var(--wall-muted); font-size: 13px; text-align: center; }

/* プレイ画面 */
#app:has(#s-play.active) { max-width: 760px; }
.scorebar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.scorebar div, .live {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px;
  display: flex; flex-direction: column;
  /* 採点中の得点の枠は、星の基準点の欄と同じ高さ（盤面がずれないように） */
  height: 56px; justify-content: center;
}
.scorebar small { color: var(--star); font-size: 13px; letter-spacing: .1em; }
.scorebar span { font-size: 20px; font-weight: bold; font-variant-numeric: tabular-nums; }
.live { align-items: center; padding: 4px; }
.live span { font-size: 14px; font-weight: bold; min-height: 1.4em; }
.live b { font-size: 34px; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--accent); }

.play-area { display: flex; gap: 12px; align-items: flex-start; justify-content: center; }
/* 盤面は額縁の中のキャンバスのように */
#board {
  touch-action: none; display: block; max-width: 100%;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  outline: 6px solid #3e2a19; box-shadow: 0 0 0 8px var(--gold), 0 12px 24px rgba(0, 0, 0, .5);
  background: #f7f1e3;
  margin: 8px;
}
.shape-list { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.shape-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
  text-align: left;
}
.shape-row canvas { flex: none; }
.shape-row .sname { flex: 1; display: flex; flex-direction: column; }
.shape-row .sname small { color: var(--muted); }
.play-buttons { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; }

/* 結果 */
.breakdown { width: 100%; border-collapse: collapse; font-size: 15px; }
.breakdown td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.breakdown td:nth-child(1) { text-align: left; }
.breakdown td:nth-child(2) { text-align: right; color: var(--muted); }
.breakdown td:nth-child(3) { text-align: right; font-weight: bold; width: 5em; font-variant-numeric: tabular-nums; }
.breakdown tr { animation: pop-in .25s ease-out; }
.result-score { font-size: 18px; }
.result-score span { font-size: 40px; font-weight: bold; font-variant-numeric: tabular-nums; }
.stars { font-size: 44px; letter-spacing: .1em; line-height: 1; }
.stars span { color: var(--line); display: inline-block; }
.stars span.on { color: var(--star); animation: star-pop .35s ease-out; }
.result-title { font-family: var(--serif); font-size: 26px; font-weight: bold; }
.result-title.clear { color: var(--accent2); }
.result-title.fail { color: var(--muted); }
.result-buttons { display: flex; flex-direction: column; gap: 12px; }
#r-detail { white-space: pre-line; }
.pending { visibility: hidden; }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes star-pop { 0% { transform: scale(.3); } 70% { transform: scale(1.25); } }

/* 王冠（最大点を取ったとき、星の前） */
.crown { font-style: normal; }
.stars .crown { font-size: 40px; margin-right: 2px; display: inline-block; vertical-align: 2px; }
.stars .crown:not(.on) { visibility: hidden; }
.stars .crown.on { animation: star-pop .45s ease-out; }
.stage-item .stars-mini .crown { font-size: 12px; margin-right: 1px; }

/* ---- 美術館 ---- */
#app:has(#s-gallery.active), #app:has(#s-room.active) { max-width: 900px; }
.room-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 28px 24px; padding-top: 8px; }
.room-item {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: radial-gradient(ellipse 70% 60% at 50% 0%, rgba(255, 226, 170, .14), transparent 75%);
  border: none; padding: 16px 8px 8px; color: var(--wall-text);
}
.room-item:hover .frame { transform: translateY(-2px); }
.room-item.locked { opacity: .6; }

/* 額縁: ふつうは木、その範囲で王冠を全部取ると金 */
.frame {
  width: 100%;
  padding: 14px;
  border-radius: 2px;
  background: linear-gradient(145deg, #6b4a2e, #3e2a19 55%, #5a3e26);
  box-shadow: inset 0 0 0 2px #24170d, inset 0 0 0 4px #7b5a3a, inset 0 0 0 6px #2f2013, 0 14px 30px rgba(0, 0, 0, .6);
  transition: transform .2s;
}
.frame.small { padding: 9px; }
.frame.gold {
  background: linear-gradient(135deg, #7a561a 0%, #f2d589 22%, #b5862e 45%, #f7e2a0 62%, #a37624 82%, #e9c96f 100%);
  box-shadow: inset 0 0 0 2px #5a3f12, inset 0 0 0 5px #f0d68f, inset 0 0 0 7px #8f6a24,
    0 0 28px rgba(240, 200, 110, .5), 0 14px 30px rgba(0, 0, 0, .6);
}
.mat { background: #efe7d6; padding: 12px; box-shadow: inset 0 0 8px rgba(0, 0, 0, .35); }
.frame.small .mat { padding: 6px; }
.picture { position: relative; aspect-ratio: 1344 / 768; overflow: hidden; background: #2a2020; }
.picture.blank { background: #fdfcf8; } /* 白紙の絵 */
.picture img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; }
.picture.closed {
  background: repeating-linear-gradient(45deg, #3a2f2c 0 10px, #332926 10px 20px);
}
.picture.closed::after { content: "未公開"; position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--serif); color: var(--wall-muted); letter-spacing: .3em; }
/* まだ開いていないマスの覆い（麻布のような生地） */
.cover-grid { position: absolute; inset: 0; display: grid; grid-template-rows: repeat(5, 1fr); }
.cover {
  min-height: 0; margin: 0; padding: 0; border-radius: 0;
  border: 1px solid rgba(110, 88, 50, .35);
  background:
    repeating-linear-gradient(0deg, rgba(120, 100, 60, .08) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(90deg, rgba(120, 100, 60, .08) 0 2px, transparent 2px 4px),
    #d8ccb2;
}
.cover.open { background: transparent; border-color: transparent; pointer-events: none; }
.cover.opening { animation: cover-open .45s ease-out; }
@keyframes cover-open { from { background-color: #fff3cf; box-shadow: inset 0 0 0 3px var(--gold-light); } }
button.cover { cursor: default; }
.picture.can-open button.cover:not(.open) { cursor: pointer; }
.picture.can-open button.cover:not(.open):hover { background-color: #ece0c3; box-shadow: inset 0 0 0 2px var(--gold); }

/* 作品名の銘板（真ちゅう） */
.plaque {
  display: flex; flex-direction: column; gap: 2px; align-items: center;
  background: linear-gradient(#ead59a, #c7a14d);
  color: #33240f;
  border-radius: 2px;
  padding: 6px 16px;
  font-size: 13px;
  box-shadow: inset 0 0 0 1px #8f6a24, 0 4px 10px rgba(0, 0, 0, .45);
}
.plaque b { font-family: var(--serif); font-size: 15px; letter-spacing: .1em; }
.plaque small { font-size: 12px; opacity: .85; }
.plaque .big-num { font-size: 20px; font-family: var(--serif); }
.room-view { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 12px 0; }
.room-view .frame { max-width: 680px; }
.room-view .plaque { padding: 10px 28px; font-size: 14px; gap: 4px; }

/* ---- スマホ・タッチ操作 ---- */
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button.small, button.link { min-height: 40px; }
/* 結果やメニューが画面より高いときはスクロールできるように */
.overlay { overflow-y: auto; align-items: safe center; }

@media (max-width: 600px) {
  #app { padding: 20px 12px; }
  .logo { font-size: 32px; margin: 0 0 20px; }
  /* プレイ中はロゴを出さず、盤面とボタンを1画面に収める */
  #app:has(#s-play.active) { padding-top: 10px; padding-bottom: 10px; }
  #app:has(#s-play.active) .logo, #app:has(#s-room.active) .logo, #app:has(#s-gallery.active) .logo { display: none; }
  .screen { gap: 8px; }
  .scorebar div, .live { height: 48px; padding: 3px; }
  .scorebar span { font-size: 17px; }
  .live { flex-direction: row; gap: 12px; }
  .live b { font-size: 26px; }
  .play-area { flex-direction: column; align-items: center; }
  /* 盤面は画面の横幅いっぱい（まわりの余白を 4px まで詰め、額縁も細く） */
  .play-area { margin: 0 -8px; }
  #board { margin: 7px; outline-width: 3px; box-shadow: 0 0 0 6px var(--gold), 0 6px 14px rgba(0, 0, 0, .5); }
  /* 図形の一覧は1段に4つ（見本の上に名前） */
  .shape-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; width: 100%; min-width: 0; }
  .shape-row { flex-direction: column; gap: 2px; padding: 4px 2px; text-align: center; font-size: 11px; }
  .shape-row .sname { align-items: center; }
  #p-hint { font-size: 12px; margin: 0; }
  .play-buttons button { padding: 12px 6px; }
  .room-list { grid-template-columns: 1fr; gap: 20px; }
  .frame { padding: 9px; }
  .mat { padding: 6px; }
}

/* 遊び方・案内 */
.help { text-align: left; max-width: 420px !important; }
.help-title { font-family: var(--serif); font-size: 22px; text-align: center; letter-spacing: .15em; color: var(--accent); }
.help-main { font-size: 15px; line-height: 1.8; }
.help-sub { font-size: 13px; line-height: 1.6; color: var(--muted); }
.help-shapes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.help-shape { display: flex; align-items: center; gap: 6px; background: #fbf7ee; border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; font-size: 12px; line-height: 1.3; }
.help-shape canvas { flex: none; }
.help-shape small { display: block; color: var(--muted); font-size: 11px; }
.notice-text { white-space: pre-line; line-height: 1.7; }

/* 結果画面の「次のステージへ」: 次がまだ遊べないときはグレーで、押しても反応しない */
button.off, button.off:hover { background: #d9d2c4; border-color: #c9c0ae; color: #8f8676; filter: none; cursor: default; box-shadow: none; }

/* 図形の見本は押せる（条件を表示） */
button.shape-row, button.help-shape { font: inherit; cursor: pointer; width: 100%; position: relative; }
button.shape-row:hover, button.help-shape:hover { border-color: var(--gold); }
button.shape-row::after, button.help-shape::after {
  content: "?"; position: absolute; top: 2px; right: 4px;
  font-size: 10px; font-weight: bold; color: var(--muted); line-height: 1;
}
.help-shape { text-align: left; color: var(--text); }
/* 図形の条件の窓 */
.si-examples { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.si-examples canvas { background: #fbf7ee; border: 1px solid var(--line); border-radius: 4px; }
.si-rule { line-height: 1.8; text-align: left; }

/* ステージ70以降（このPCから開いたときだけ見える）の印 */
.stage-item.local-only::before {
  content: "このPCのみ"; position: absolute; top: 3px; right: 6px;
  font-size: 9px; color: var(--accent); letter-spacing: .05em;
}
