/* =========================================================
   BadJudge スタイル
   - 横画面（ランドスケープ）前提
   - サイズは全て変数で管理し、画面サイズに応じて下部の
     メディアクエリで変数だけを上書きする
   ========================================================= */

:root {
  /* 色 */
  --bg: #e9e9f7;
  --panel: #f7f6ff;
  --stroke: #cfcfe0;
  --title: #6e8bff;
  --shadow: 0 6px 18px rgba(0, 0, 0, .18);
  --shadow-soft: 0 4px 12px rgba(0, 0, 0, .16);
  --left: #ffe2e2;
  --right: #fff6d8;
  --highlight: #ffe9d6;
  --pbtn: #8fa7ff;

  /* 余白 */
  --page-pad: 12px;
  --gap: 14px;
  --row-gap: 16px;

  /* ヘッダー */
  --nav-size: 52px;
  --nav-font: 28px;
  --title-h: 62px;
  --title-font: 22px;

  /* スコア行 */
  --team-w: 300px;
  --team-h: 72px;
  --team-score-w: 58px;
  --team-score-font: 34px;
  --center-font: 44px;

  /* テーブル */
  --pbtn-size: 64px;
  --pbtn-font: 22px;
  --cell-h: 44px;
  --cell-w: 54px;
  --cell-font: 28px;
  --name-font: 15px;
  --col1: 44px;   /* 1列目（サーブ順）の幅 */
  --col2: 220px;  /* 2列目（名前）の幅 */

  /* 下部 */
  --reset-h: 56px;
}

* {
  box-sizing: border-box;
}

html {
  /* iPhone横向き・Androidの文字拡大で崩れないように */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: #444;
}

.page {
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--page-pad);
  /* iPhone横向きのノッチ部分を避ける */
  padding-left: max(var(--page-pad), env(safe-area-inset-left));
  padding-right: max(var(--page-pad), env(safe-area-inset-right));
  padding-bottom: max(var(--page-pad), env(safe-area-inset-bottom));
}

/* ===== Header ===== */
.topRow {
  display: flex;
  align-items: center;
  gap: var(--gap);
  margin-bottom: var(--row-gap);
}

.navButton {
  flex: 0 0 auto;
  width: var(--nav-size);
  height: var(--nav-size);
  padding: 0;
  border: none;
  background: transparent;
  font-size: var(--nav-font);
  line-height: 1;
  cursor: pointer;
  color: #4a4a4a;
  display: grid;
  place-items: center;
}

.titleBar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  height: var(--title-h);
  padding: 0 18px;
  border-radius: 12px;
  background: var(--title);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .22);
  color: #fff;
  overflow: hidden;
}

.headerText {
  min-width: 0;
  font-size: var(--title-font);
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Score row ===== */
.scoreRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: var(--row-gap);
}

.teamBox {
  flex: 0 1 var(--team-w);
  min-width: 0;
  height: var(--team-h);
  border-radius: 10px;
  display: flex;
  overflow: hidden;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .14);
}

.teamBoxLeft {
  background: var(--left);
}

.teamBoxRight {
  background: var(--right);
}

.teamNames {
  flex: 1;
  min-width: 0;
  padding: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}

.nameInput {
  width: 100%;
  min-width: 0;
  min-height: 0;
  border: none;
  outline: none;
  background: rgba(255, 255, 255, .55);
  border-radius: 6px;
  padding: 0 8px;
  /* 16px未満だとiPhoneでタップ時に自動ズームされる */
  font-size: 16px;
  line-height: 1;
}

.nameInput:disabled {
  background: rgba(200, 200, 200, 0.4);
  color: #666;
  cursor: not-allowed;
}

.teamScoreBox {
  flex: 0 0 var(--team-score-w);
  display: grid;
  place-items: center;
  font-size: var(--team-score-font);
  font-weight: 700;
  color: #5a5a5a;
  border-left: 2px solid rgba(0, 0, 0, .15);
  background: rgba(255, 255, 255, .25);
}

.teamBoxRight .teamScoreBox {
  border-left: none;
  border-right: 2px solid rgba(0, 0, 0, .15);
}

.centerScore {
  flex: 1 0 auto;
  text-align: center;
  font-size: var(--center-font);
  line-height: 1;
  color: #6a6a6a;
  font-weight: 500;
  white-space: nowrap;
}

.centerDivider {
  margin: 0 .25em;
}

/* ===== Table area ===== */
.tableAreaRow {
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.sideButton {
  flex: 0 0 auto;
  width: var(--pbtn-size);
  height: var(--pbtn-size);
  padding: 0;
  border-radius: 12px;
  border: none;
  background: var(--pbtn);
  color: #fff;
  font-size: var(--pbtn-font);
  font-weight: 700;
  box-shadow: 0 6px 14px rgba(0, 0, 0, .2);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.tableWrapper {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
  border-radius: 10px;
  box-shadow: var(--shadow-soft);
}

table.table {
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
}

td.cell {
  border: 1px solid var(--stroke);
  height: var(--cell-h);
  width: var(--cell-w);
  min-width: var(--cell-w);
  max-width: var(--cell-w);
  padding: 0;
  text-align: center;
  vertical-align: middle;
  color: #6a6a6a;
  font-size: var(--cell-font);
  font-weight: 700;
  line-height: 1;
}

/* 1列目・2列目は横スクロールしても固定 */
td.indexCell,
td.nameCell {
  position: sticky;
  z-index: 10;
  background: #fff;
}

td.indexCell {
  left: 0;
  width: var(--col1);
  min-width: var(--col1);
  max-width: var(--col1);
}

td.nameCell {
  left: var(--col1);
  width: var(--col2);
  min-width: var(--col2);
  max-width: var(--col2);
  padding: 0 10px;
  text-align: left;
  font-size: var(--name-font);
  font-weight: 400;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

td.nameHighlight {
  background: var(--highlight);
}

td.scoreHighlight,
.scoreHighlight {
  background: var(--highlight);
  color: #000;
}

/* JSで付与されるクラス（サーブ列を薄赤） */
.redColumnCell {
  background: #ffd3d3;
}

/* サーブ順1の強調 */
.orange {
  background: #ffd6a6 !important;
}

/* サーブボタン */
.serveBtn {
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  background: transparent;
  font-size: var(--cell-font);
  font-weight: 700;
  color: #6a6a6a;
  cursor: pointer;
}

.serveBtn:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

/* ===== Bottom ===== */
.bottomArea {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  margin-top: var(--row-gap);
}

.adArea {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  /* 広告が横にはみ出してページ全体が縮小されるのを防ぐ */
  overflow: hidden;
  display: flex;
  justify-content: center;
}

.resetButton {
  flex: 0 0 auto;
  height: var(--reset-h);
  padding: 0 18px;
  border-radius: 10px;
  border: none;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  color: #444;
}

/* =========================================================
   レスポンシブ
   ========================================================= */

/* --- タブレット横・小さめのPC（幅 〜1024px） --- */
@media (max-width: 1024px) {
  :root {
    --col2: 170px;
    --team-w: 280px;
  }
}

/* --- スマホ横向き（高さが低い画面） --- */
@media (max-height: 520px) {
  :root {
    --page-pad: 8px;
    --gap: 10px;
    --row-gap: 8px;

    --nav-size: 40px;
    --nav-font: 24px;
    --title-h: 40px;
    --title-font: 17px;

    --team-w: 300px;
    --team-h: 44px;
    --team-score-w: 44px;
    --team-score-font: 24px;
    --center-font: 30px;

    --pbtn-size: 52px;
    --pbtn-font: 20px;
    --cell-h: 36px;
    --cell-w: 42px;
    --cell-font: 22px;
    --name-font: 14px;
    --col1: 34px;
    --col2: 130px;

    --reset-h: 40px;
  }

  .titleBar {
    padding: 0 12px;
    border-radius: 10px;
  }

  /* 名前入力を横並びにして高さを節約 */
  .teamNames {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    padding: 6px;
  }
}

/* --- 高さがさらに低い横向き（小型Android・ブラウザバー表示中など） --- */
@media (max-height: 400px) {
  :root {
    --row-gap: 6px;
    --nav-size: 36px;
    --title-h: 34px;
    --title-font: 15px;
    --team-h: 40px;
    --center-font: 26px;
    --pbtn-size: 46px;
    --cell-h: 32px;
    --cell-w: 38px;
    --cell-font: 20px;
    --reset-h: 36px;
  }
}

/* --- 幅の狭い横向き（iPhone SE 横 667px など） --- */
@media (max-width: 700px) {
  :root {
    --gap: 8px;
    --col2: 100px;
    --pbtn-size: 46px;
    --team-score-w: 40px;
  }
}

/* --- 縦向きのスマホ（横向き推奨だが崩れないようにする） --- */
@media (orientation: portrait) and (max-width: 600px) {
  :root {
    --page-pad: 8px;
    --gap: 8px;
    --row-gap: 10px;
    --nav-size: 40px;
    --nav-font: 24px;
    --title-h: auto;
    --title-font: 15px;
    --team-h: 72px;
    --team-score-w: 40px;
    --team-score-font: 24px;
    --center-font: 26px;
    --pbtn-size: 44px;
    --pbtn-font: 18px;
    --cell-h: 40px;
    --cell-w: 38px;
    --cell-font: 20px;
    --name-font: 13px;
    --col1: 30px;
    --col2: 76px;
    --reset-h: 44px;
  }

  .titleBar {
    min-height: 44px;
    padding: 8px 12px;
  }

  /* 縦向きでは指示文を折り返して全文表示 */
  .headerText {
    white-space: normal;
  }

  .teamNames {
    padding: 6px;
  }

  /* 広告を1行使って表示し、「最初から」は下の行へ */
  .bottomArea {
    flex-wrap: wrap;
  }

  .adArea {
    flex: 1 1 100%;
  }
}
