/* 点検モードだけ。ふだん（?review=1 でないとき）は要素が無いので画面は変わらない。 */
body.review-on .screen { padding-top: var(--review-bar-h, calc(var(--safe-t) + 62px)); }

.review-bar {
  position: absolute; z-index: 16; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 6px) max(10px, env(safe-area-inset-right, 0px)) 6px max(10px, env(safe-area-inset-left, 0px));
  background: #fff1ea; border-bottom: 2px solid #9d3414;
}
.review-badge {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-height: 44px; margin: 0; padding: 0 14px; border-radius: 999px;
  background: #9d3414; color: #fff; font-weight: 900; font-size: 15px; letter-spacing: .04em;
}
.review-open { flex: 1; background: #fff; }

.review-hit, .review-chip {
  font: inherit; font-weight: 800; font-size: 16px; color: var(--ink);
  min-height: 44px; padding: 8px 10px; border-radius: 12px; border: 1px solid #d6ddd6;
  background: #fff; box-shadow: 0 3px 0 #c8d3c8; cursor: pointer; touch-action: manipulation;
}
.review-hit:active, .review-chip:active { transform: translateY(2px); box-shadow: 0 1px 0 #c8d3c8; }
.review-hit:disabled { opacity: .45; }
.review-hit:focus-visible, .review-chip:focus-visible, .review-memo:focus-visible, .review-tools select:focus-visible {
  outline: 3px solid var(--amber); outline-offset: 2px;
}
.review-hit-good.is-on { background: #d7efe4; color: #145246; box-shadow: inset 0 0 0 3px #145246; }
.review-hit-fair.is-on { background: #fff0d6; color: #6a3e10; box-shadow: inset 0 0 0 3px #6a3e10; }
.review-hit-bad.is-on { background: #f8e2d2; color: #6a3412; box-shadow: inset 0 0 0 3px #6a3412; }

.review-rate { margin-top: 8px; }
.review-rate-id {
  margin: 0 0 6px; font-size: 12px; font-weight: 800; color: #6a5340;
  word-break: break-all; user-select: text; -webkit-user-select: text;
}
.review-rate-btns { display: flex; gap: 8px; }
.review-rate-btns .review-hit { flex: 1; white-space: nowrap; padding-left: 4px; padding-right: 4px; }
.review-memo {
  display: block; width: 100%; box-sizing: border-box; margin-top: 8px;
  min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid #d6ddd6;
  background: #fff; color: var(--ink); font: inherit; font-size: 16px; font-weight: 700;
  touch-action: manipulation; user-select: text; -webkit-user-select: text;
}
.review-memo::placeholder { color: #637570; font-weight: 700; }
.parcel:has(.review-rate) { padding-bottom: 22px; }
/* 評価の分だけ伝票が伸びる。地図の最低の高さを下げて、答えのボタンを画面の中に残す */
@media (orientation: portrait) and (max-width: 759px) {
  body.review-on .map-station .map-box { min-height: 72px; }
}
/* 広い画面：答えのボタンは地図の下にある。点検の帯の分だけ地図を低くして、ボタンを画面の中に残す
   （追加問題の長い4択は2行になるので、760×720でも収まるよう .58 から .54 にした：chiri-bundle-a2-foundation-1030） */
@media (min-width: 760px) {
  body.review-on .sort-board .map-station .map-box { height: min(calc((100vh - var(--review-bar-h, 62px)) * .54), 540px); }
}

#review-dialog {
  width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
  margin: 0; padding: 0; border: 0; background: var(--paper); color: var(--ink);
}
#review-dialog[open] { display: flex; flex-direction: column; overflow: hidden; }
#review-dialog::backdrop { background: #183a3288; }
#review-dialog { user-select: text; -webkit-user-select: text; }
.review-head, .review-tools, .review-footer, .review-hit, .review-chip { user-select: none; -webkit-user-select: none; }

.review-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; flex: none;
  padding: calc(var(--safe-t) + 8px) 12px 8px; background: #fff; border-bottom: 1px solid var(--line);
}
.review-titles { min-width: 0; }
.review-head h2 { margin: 0; font-size: 22px; line-height: 1.2; }
.review-progress { margin: 4px 0 0; font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }
.review-note { margin: 2px 0 0; font-size: 12px; line-height: 1.4; color: var(--sub); font-weight: 700; }
.review-close { flex: none; align-self: center; }

.review-tools {
  flex: none; padding: 8px 12px 10px; background: #fff; border-bottom: 1px solid var(--line);
}
.review-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 800; color: var(--sub); }
.review-tools select {
  width: 100%; min-height: 48px; padding: 0 12px; border-radius: 12px; border: 1px solid #d6ddd6;
  background: #fff; color: var(--ink); font: inherit; font-size: 16px; font-weight: 800; touch-action: manipulation;
}
.review-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.review-chip { flex: 1 1 calc(50% - 8px); }
.review-chip.is-on { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 3px 0 var(--brand-dark); }
.review-filter-count { margin: 8px 0 0; font-size: 13px; font-weight: 800; color: var(--sub); }
.review-off {
  width: 100%; margin-top: 4px; background: transparent; box-shadow: none; border-color: transparent;
  color: #8b5528; font-size: 14px;
}
.review-off.is-armed { background: #f8e2d2; border-color: #d2a07a; box-shadow: none; }

.review-status { flex: none; min-height: 0; margin: 0; padding: 0 12px; font-size: 14px; font-weight: 800; color: var(--brand); }
.review-status:not(:empty) { padding-top: 8px; padding-bottom: 4px; }

.review-list {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  list-style: none; margin: 0; padding: 10px 12px 16px;
}
.review-empty { padding: 28px 8px; text-align: center; color: var(--sub); font-weight: 800; }
.review-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 0 0 10px;
}
.review-card:has(.review-mark[data-rating="good"]) { border-color: #8ac5b4; }
.review-card:has(.review-mark[data-rating="fair"]) { border-color: #e0b15a; }
.review-card:has(.review-mark[data-rating="bad"]) { border-color: #d2a07a; }
.review-card-head { display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 8px; row-gap: 4px; align-items: start; }
.review-mark {
  grid-column: 1; grid-row: 1 / span 3; width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: #e7ece3; color: var(--sub); font-size: 18px; font-weight: 900;
}
.review-mark[data-rating="good"] { background: #2d887b; color: #fff; }
.review-mark[data-rating="fair"] { background: #c9802b; color: #3c2a08; }
.review-mark[data-rating="bad"] { background: #8b5528; color: #fff; }
.review-meta { grid-column: 2; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: baseline; }
.review-region { font-size: 14px; font-weight: 900; }
.review-id { font-size: 12px; font-weight: 700; color: var(--sub); word-break: break-all; }
.review-text, .review-answer { grid-column: 2; margin: 0; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.review-answer { color: var(--brand); font-weight: 800; }

.review-export {
  flex: none; display: block; box-sizing: border-box; width: calc(100% - 24px); height: 96px; margin: 0 12px 8px;
  padding: 8px; border-radius: 12px; border: 1px solid #d6ddd6; background: #fff; color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.4; resize: none;
  user-select: text; -webkit-user-select: text;
}
.review-export[hidden] { display: none; }
.review-footer {
  flex: none; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
  padding: 8px 12px calc(var(--safe-b) + 8px); background: #fff;
  border-top: 1px solid var(--line); box-shadow: 0 -4px 16px #183a3214;
}
.review-footer .review-hit { font-size: 15px; line-height: 1.2; padding: 8px 4px; min-height: 48px; }

@media (max-width: 340px) {
  .review-rate-btns .review-hit { font-size: 14px; }
  .review-badge { padding: 0 10px; font-size: 14px; }
}
@media (min-width: 760px) {
  #review-dialog {
    width: min(720px, calc(100vw - 48px)); height: min(920px, calc(100dvh - 48px));
    max-height: calc(100dvh - 48px); margin: auto; border-radius: 18px; border: 1px solid var(--line);
  }
}

/* 低い画面（横向きなど）：問題リストまで届くよう、ダイアログ全体をスクロールにする */
@media (max-height: 560px) {
  #review-dialog[open] { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #review-dialog[open] .review-list { flex: none; overflow: visible; min-height: auto; }
}
/* 短い画面のゲーム中：評価欄を小さくし、答えのボタンを初期表示に残す（メモは問題リストで書ける）。
   スマホ縦は 741〜820px でも長い問題文で押し出されるので、ここまで小さくする */
@media (max-height: 700px), (orientation: portrait) and (max-width: 759px) and (max-height: 820px) {
  .review-rate { margin-top: 4px; }
  .review-rate-id, .parcel .review-memo { display: none; }
  .review-rate-btns .review-hit { min-height: 36px; padding-top: 4px; padding-bottom: 4px; font-size: 14px; }
  .parcel:has(.review-rate) { padding-bottom: 8px; }
}
/* 低い画面：書き出しのボタンは下に固定。ゲーム中の評価欄は隠し、評価は問題リストで行う */
@media (max-height: 560px) {
  #review-dialog[open] .review-footer { position: sticky; bottom: 0; z-index: 2; }
  .parcel .review-rate { display: none; }
  /* 0 にすると伝票の下の時間の帯が問題文に重なるので、文字にかからない 8px を残す */
  .parcel:has(.review-rate) { padding-bottom: 8px; }
}
/* とても低い画面（iPhone SE 初代の縦・スマホの横）：点検の帯を細くして、答えのボタンの場所を空ける */
@media (max-height: 500px), (orientation: portrait) and (max-width: 759px) and (max-height: 600px) {
  .review-bar { padding-top: calc(var(--safe-t) + 2px); padding-bottom: 2px; }
  .review-badge, .review-open { min-height: 34px; font-size: 14px; }
  .review-open { padding-top: 4px; padding-bottom: 4px; }
}
/* とても低い縦画面：ゲーム中の評価欄を隠し（評価は問題リストで行う）、地図の最低の高さを下げて、
   長い問題文でも答えのボタンを画面の中に残す */
@media (orientation: portrait) and (max-width: 759px) and (max-height: 600px) {
  .parcel .review-rate { display: none; }
  body.review-on .map-station .map-box { min-height: 64px; }
}
@media (orientation: portrait) and (max-width: 759px) and (max-height: 500px) {
  body.review-on .map-station .map-box { min-height: 36px; }
}
/* 低い横画面：上の数字の枠を細くし、点検モードの間だけ地図の最低の高さを下げて、帯の分だけ答えのボタンを上げる */
@media (orientation: landscape) and (max-height: 500px) {
  body.review-on .map-station .map-box { min-height: 48px; }
  body.review-on .screen.game { gap: 4px; }
  body.review-on .hud-item { padding-top: 0; padding-bottom: 0; }
  body.review-on .hud-item b { font-size: 16px; }
}
