:root {
  --board: #211714;
  --white: #ffffff;
  --red: #ef0012;
  --green: #00d642;
  --yellow: #ffe600;
  --gray: #666666;
  --page: #f3f3f3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
  color: #222;
}

.app {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 30px 16px 50px;
}

.scorebug {
  width: min(720px, 100%);
  aspect-ratio: 1.7 / 1;
  margin: 0 auto;
  padding: 26px 30px 24px;
  background: var(--board);
  color: var(--white);
  border-radius: 11px;
  display: grid;
  grid-template-rows: .92fr 2px 1.5fr;
  gap: 0;
  font-weight: 800;
  overflow: hidden;
  position: sticky;
  top: 10px;
  z-index: 100;
  box-shadow: 0 6px 18px rgba(0,0,0,.16);
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 0;
}

.inning {
  display: flex;
  align-items: baseline;
  white-space: nowrap;
  font-size: clamp(48px, 7.5vw, 86px);
  letter-spacing: -0.06em;
  line-height: 1;
}

.inning-label,
#inningHalf {
  font-size: 0.46em;
  margin-left: 0.08em;
  letter-spacing: -0.04em;
}

.bases {
  position: relative;
  width: 185px;
  height: 100px;
  flex: 0 0 auto;
}

.base {
  position: absolute;
  width: 64px;
  height: 64px;
  transform: rotate(45deg) scale(.82);
  background: var(--gray);
  transition: .15s ease;
}

.base.active { background: var(--red); }
.base-second { left: 60px; top: 0; }
.base-third  { left: 15px; top: 39px; }
.base-first  { right: 15px; top: 39px; }

.divider.horizontal {
  width: 100%;
  height: 2px;
  background: var(--white);
  border-radius: 99px;
}

.bottom-row {
  display: grid;
  grid-template-columns: 1.08fr 2px .92fr;
  min-height: 0;
}

.teams-panel {
  position: relative;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
  padding: 18px 26px 0 46px;
}

.offense-marker {
  position: absolute;
  left: 0;
  top: 22px;
  width: 20px;
  height: calc(50% - 9px);
  background: var(--red);
  transition: transform .2s ease;
}

.offense-marker.home {
  transform: translateY(calc(100% + 6px));
}

.team-row {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  align-items: center;
  gap: 18px;
}

.team-name {
  background: transparent;
  color: var(--white);
  border-radius: 0;
  height: 82%;
  min-height: 62px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(26px, 4.1vw, 48px);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  letter-spacing: 0.08em;
}

.team-score {
  width: 88px;
  min-width: 88px;
  height: 82%;
  min-height: 62px;
  border-radius: 14px;
  background: var(--white);
  color: var(--board);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(52px, 7vw, 82px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.divider.vertical {
  width: 2px;
  height: 100%;
  background: var(--white);
}

.count-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding-left: 30px;
}

.count-row {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 9px;
}

.count-label {
  font-size: clamp(38px, 4.8vw, 56px);
  line-height: 1;
}

.lamps {
  display: flex;
  gap: 10px;
}

.lamp {
  width: clamp(34px, 4vw, 48px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--gray);
  flex: 0 0 auto;
}

.lamp.ball.on { background: var(--green); }
.lamp.strike.on { background: var(--yellow); }
.lamp.out.on { background: var(--red); }

.controls {
  margin: 28px auto 0;
  width: min(720px, 100%);
}

.controls h1 {
  margin: 0 0 16px;
  font-size: 25px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.control-card {
  padding: 16px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}

.control-card h2 {
  margin: 0 0 12px;
  font-size: 17px;
}

label {
  display: block;
  margin: 10px 0 7px;
  font-size: 13px;
  color: #555;
}

input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 16px;
}

.button-row {
  display: flex;
  gap: 7px;
}

.button-row.wrap { flex-wrap: wrap; }

button {
  border: 0;
  border-radius: 8px;
  padding: 9px 12px;
  background: #202020;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

button:hover { opacity: .82; }
button:active { transform: translateY(1px); }

.reset-button {
  width: 100%;
  margin-top: 14px;
  background: #b40012;
  padding: 11px;
}

@media (max-width: 720px) {
  .app {
    padding: 16px 10px 36px;
  }

  .scorebug {
    width: min(520px, 100%);
    aspect-ratio: 1.72 / 1;
    padding: 16px 17px 15px;
    border-radius: 9px;
    grid-template-rows: .92fr 2px 1.52fr;
  }

  .inning {
    font-size: clamp(40px, 11vw, 58px);
  }

  .bases {
    width: 128px;
    height: 70px;
  }

  .base {
    width: 44px;
    height: 44px;
  }

  .base-second { left: 42px; top: 0; }
  .base-third { left: 10px; top: 27px; }
  .base-first { right: 10px; top: 27px; }

  .divider.horizontal {
    height: 2px;
  }

  .bottom-row {
    grid-template-columns: 1.08fr 2px .92fr;
  }

  .divider.vertical {
    width: 2px;
  }

  .teams-panel {
    padding: 12px 15px 0 30px;
    gap: 4px;
  }

  .offense-marker {
    width: 13px;
    top: 15px;
    height: calc(50% - 6px);
  }

  .offense-marker.home {
    transform: translateY(calc(100% + 4px));
  }

  .team-row {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 10px;
  }

  .team-name {
    min-height: 42px;
    border-radius: 8px;
    padding: 0 7px;
    font-size: clamp(21px, 6.4vw, 31px);
  }

  .team-score {
    width: 64px;
    min-width: 64px;
    min-height: 42px;
    border-radius: 8px;
    font-size: clamp(44px, 11vw, 58px);
  }

  .count-panel {
    padding-left: 14px;
    gap: 7px;
  }

  .count-row {
    grid-template-columns: 28px 1fr;
    gap: 5px;
  }

  .count-label {
    font-size: clamp(31px, 8.5vw, 42px);
  }

  .lamps {
    gap: 5px;
  }

  .lamp {
    width: clamp(26px, 7.2vw, 35px);
  }

  .controls {
    margin-top: 24px;
    width: min(520px, 100%);
  }

  .controls h1 {
    font-size: 22px;
    margin-bottom: 14px;
  }

  .control-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .control-card {
    padding: 14px;
  }
}

@media (max-width: 420px) {
  .scorebug {
    width: 100%;
    aspect-ratio: 1.78 / 1;
    padding: 13px 13px 12px;
  }

  .inning {
    font-size: 39px;
  }

  .bases {
    width: 112px;
    height: 62px;
  }

  .base {
    width: 39px;
    height: 39px;
  }

  .base-second { left: 36px; }
  .base-third { left: 7px; top: 24px; }
  .base-first { right: 7px; top: 24px; }

  .teams-panel {
    padding: 10px 11px 0 26px;
  }

  .offense-marker {
    width: 11px;
    top: 12px;
  }

  .team-row {
    grid-template-columns: minmax(0, 1fr) 58px;
    gap: 7px;
  }

  .team-name {
    min-height: 37px;
    font-size: 20px;
    border-radius: 7px;
  }

  .team-score {
    width: 58px;
    min-width: 58px;
    min-height: 37px;
    border-radius: 7px;
    font-size: 40px;
  }

  .count-panel {
    padding-left: 10px;
    gap: 5px;
  }

  .count-row {
    grid-template-columns: 25px 1fr;
    gap: 4px;
  }

  .count-label {
    font-size: 29px;
  }

  .lamps {
    gap: 4px;
  }

  .lamp {
    width: 24px;
  }

  .controls h1 {
    font-size: 20px;
  }

  button {
    padding: 8px 11px;
  }
}

/* ===== 2026-08-12 layout refinements ===== */

/* Make the score side / BSO side closer to the reference proportions. */
.bottom-row {
  grid-template-columns: 0.98fr 2px 1.02fr;
}

/* Team names: larger, while keeping the score column fixed. */
.team-row {
  grid-template-columns: minmax(0, 1fr) 88px;
}

.team-name {
  font-size: clamp(31px, 4.7vw, 54px);
  letter-spacing: 0.11em;
  padding-inline: 8px;
}

/* Use more of the BSO panel width so it does not feel empty. */
.count-panel {
  padding-left: 20px;
  padding-right: 8px;
}

.count-row {
  grid-template-columns: 48px max-content;
  gap: 10px;
}

/* Clean, symmetric base layout with clear gaps. */
.bases {
  position: relative;
  width: 190px;
  height: 108px;
  flex: 0 0 auto;
}

.base {
  width: 60px;
  height: 60px;
  transform: rotate(45deg);
  transform-origin: center;
  border-radius: 1px;
  box-shadow: none;
}

.base-second {
  left: 65px;
  top: 4px;
}

.base-third {
  left: 18px;
  top: 48px;
}

.base-first {
  right: 18px;
  top: 48px;
}

@media (max-width: 720px) {
  .bottom-row {
    grid-template-columns: 0.98fr 2px 1.02fr;
  }

  .team-row {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 8px;
  }

  .team-name {
    font-size: clamp(25px, 7.2vw, 35px);
    letter-spacing: 0.105em;
    padding-inline: 4px;
  }

  .count-panel {
    padding-left: 10px;
    padding-right: 2px;
  }

  .count-row {
    grid-template-columns: 30px max-content;
    gap: 6px;
  }

  .bases {
    width: 132px;
    height: 78px;
  }

  .base {
    width: 42px;
    height: 42px;
  }

  .base-second {
    left: 45px;
    top: 2px;
  }

  .base-third {
    left: 12px;
    top: 34px;
  }

  .base-first {
    right: 12px;
    top: 34px;
  }
}

@media (max-width: 420px) {
  .team-row {
    grid-template-columns: minmax(0, 1fr) 58px;
    gap: 6px;
  }

  .team-name {
    font-size: 23px;
    letter-spacing: 0.10em;
  }

  .count-panel {
    padding-left: 7px;
    padding-right: 0;
  }

  .count-row {
    grid-template-columns: 27px max-content;
    gap: 4px;
  }

  .bases {
    width: 118px;
    height: 70px;
  }

  .base {
    width: 37px;
    height: 37px;
  }

  .base-second {
    left: 40px;
    top: 2px;
  }

  .base-third {
    left: 10px;
    top: 31px;
  }

  .base-first {
    right: 10px;
    top: 31px;
  }
}

/* ===== 2026-08-12 v3: 7:3 score/BSO ratio, larger team names, fitted bases ===== */

/* Score area : BSO area = 7 : 3 (divider excluded). */
.bottom-row {
  grid-template-columns: minmax(0, 7fr) 2px minmax(0, 3fr);
}

/* Give team names more visual presence. The score column remains fixed. */
.team-name {
  font-size: clamp(36px, 5.2vw, 60px);
  letter-spacing: 0.11em;
  padding-inline: 8px;
}

/* Compact BSO so the 30% column stays balanced. */
.count-panel {
  padding-left: 16px;
  padding-right: 4px;
  gap: 10px;
}

.count-row {
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 7px;
}

.count-label {
  font-size: clamp(36px, 4.5vw, 52px);
}

.lamps {
  gap: 7px;
}

.lamp {
  width: clamp(30px, 3.6vw, 43px);
}

/* Bases: same clean diamond arrangement, but sized to stay fully inside the board. */
.bases {
  width: 164px;
  height: 92px;
  margin-right: 2px;
}

.base {
  width: 52px;
  height: 52px;
  transform: rotate(45deg);
}

.base-second {
  left: 56px;
  top: 2px;
}

.base-third {
  left: 15px;
  top: 39px;
}

.base-first {
  right: 15px;
  top: 39px;
}

@media (max-width: 720px) {
  .bottom-row {
    grid-template-columns: minmax(0, 7fr) 2px minmax(0, 3fr);
  }

  .team-row {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 8px;
  }

  .team-name {
    font-size: clamp(29px, 8vw, 39px);
    letter-spacing: 0.10em;
    padding-inline: 3px;
  }

  .count-panel {
    padding-left: 8px;
    padding-right: 0;
    gap: 6px;
  }

  .count-row {
    grid-template-columns: 25px minmax(0, 1fr);
    gap: 4px;
  }

  .count-label {
    font-size: clamp(28px, 7.4vw, 38px);
  }

  .lamps {
    gap: 4px;
  }

  .lamp {
    width: clamp(21px, 5.8vw, 29px);
  }

  .bases {
    width: 112px;
    height: 65px;
    margin-right: 0;
  }

  .base {
    width: 36px;
    height: 36px;
  }

  .base-second {
    left: 38px;
    top: 1px;
  }

  .base-third {
    left: 9px;
    top: 28px;
  }

  .base-first {
    right: 9px;
    top: 28px;
  }
}

@media (max-width: 420px) {
  .team-row {
    grid-template-columns: minmax(0, 1fr) 58px;
    gap: 5px;
  }

  .team-name {
    font-size: 27px;
    letter-spacing: 0.09em;
  }

  .count-panel {
    padding-left: 6px;
    gap: 5px;
  }

  .count-row {
    grid-template-columns: 23px minmax(0, 1fr);
    gap: 3px;
  }

  .count-label {
    font-size: 27px;
  }

  .lamps {
    gap: 3px;
  }

  .lamp {
    width: 20px;
  }

  .bases {
    width: 102px;
    height: 60px;
  }

  .base {
    width: 33px;
    height: 33px;
  }

  .base-second {
    left: 34px;
    top: 1px;
  }

  .base-third {
    left: 8px;
    top: 26px;
  }

  .base-first {
    right: 8px;
    top: 26px;
  }
}

/* ===== 2026-08-12 v4: 6:4 score/BSO ratio + smaller bases ===== */

/* Score area : BSO area = 6 : 4 (divider excluded). */
.bottom-row {
  grid-template-columns: minmax(0, 6fr) 2px minmax(0, 4fr);
}

/* Keep the BSO section compact but give it enough room in the 40% column. */
.count-panel {
  padding-left: 14px;
  padding-right: 6px;
}

/* Bases: roughly half the previous mobile visual size. */
.bases {
  width: 92px;
  height: 53px;
  margin-right: 4px;
}

.base {
  width: 29px;
  height: 29px;
  transform: rotate(45deg);
}

.base-second {
  left: 31px;
  top: 1px;
}

.base-third {
  left: 8px;
  top: 23px;
}

.base-first {
  right: 8px;
  top: 23px;
}

@media (max-width: 720px) {
  .bottom-row {
    grid-template-columns: minmax(0, 6fr) 2px minmax(0, 4fr);
  }

  .count-panel {
    padding-left: 8px;
    padding-right: 2px;
  }

  .bases {
    width: 58px;
    height: 34px;
    margin-right: 2px;
  }

  .base {
    width: 18px;
    height: 18px;
  }

  .base-second {
    left: 20px;
    top: 1px;
  }

  .base-third {
    left: 5px;
    top: 15px;
  }

  .base-first {
    right: 5px;
    top: 15px;
  }
}

@media (max-width: 420px) {
  .bottom-row {
    grid-template-columns: minmax(0, 6fr) 2px minmax(0, 4fr);
  }

  .bases {
    width: 54px;
    height: 32px;
  }

  .base {
    width: 17px;
    height: 17px;
  }

  .base-second {
    left: 18px;
    top: 1px;
  }

  .base-third {
    left: 4px;
    top: 14px;
  }

  .base-first {
    right: 4px;
    top: 14px;
  }
}

/* ===== 2026-08-12 v5: 6.5:3.5 layout + 1.5x bases + tighter BSO ===== */

/* Score area : BSO area = 6.5 : 3.5 (divider excluded). */
.bottom-row {
  grid-template-columns: minmax(0, 6.5fr) 2px minmax(0, 3.5fr);
}

/* Use the BSO column efficiently, without leaving a large blank area on the right. */
.count-panel {
  padding-left: 10px;
  padding-right: 8px;
  gap: 10px;
}

.count-row {
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 6px;
  width: 100%;
}

.lamps {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  align-items: center;
}

.lamp {
  width: min(100%, 44px);
  justify-self: start;
}

/* Bases are about 1.5x larger than v4, with explicit symmetric positions.
   Using left for all three avoids the slight first-base offset caused by right positioning. */
.bases {
  width: 128px;
  height: 72px;
  margin-right: 4px;
}

.base {
  width: 42px;
  height: 42px;
  transform: rotate(45deg);
}

.base-second {
  left: 43px;
  top: 1px;
}

.base-third {
  left: 10px;
  top: 31px;
}

.base-first {
  left: 76px;
  right: auto;
  top: 31px;
}

@media (max-width: 720px) {
  .bottom-row {
    grid-template-columns: minmax(0, 6.5fr) 2px minmax(0, 3.5fr);
  }

  .count-panel {
    padding-left: 7px;
    padding-right: 6px;
    gap: 7px;
  }

  .count-row {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 4px;
  }

  .lamps {
    gap: 5px;
  }

  .lamp {
    width: min(100%, 31px);
  }

  .bases {
    width: 82px;
    height: 49px;
    margin-right: 2px;
  }

  .base {
    width: 27px;
    height: 27px;
  }

  .base-second {
    left: 27.5px;
    top: 1px;
  }

  .base-third {
    left: 7px;
    top: 21px;
  }

  .base-first {
    left: 48px;
    right: auto;
    top: 21px;
  }
}

@media (max-width: 420px) {
  .bottom-row {
    grid-template-columns: minmax(0, 6.5fr) 2px minmax(0, 3.5fr);
  }

  .count-panel {
    padding-left: 6px;
    padding-right: 5px;
  }

  .count-row {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 3px;
  }

  .lamps {
    gap: 4px;
  }

  .lamp {
    width: min(100%, 29px);
  }

  .bases {
    width: 80px;
    height: 47px;
  }

  .base {
    width: 26px;
    height: 26px;
  }

  .base-second {
    left: 27px;
    top: 1px;
  }

  .base-third {
    left: 7px;
    top: 20px;
  }

  .base-first {
    left: 47px;
    right: auto;
    top: 20px;
  }
}

/* ===== 2026-08-15 v6: typography and color refinements ===== */
:root {
  --runner-orange: #ff6a00;
  --out-red: #ff1a2d;
}

/* B/S/O labels: monospaced to keep all three letters visually aligned. */
.count-label {
  font-family: "SFMono-Regular", "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-weight: 800;
}

/* Runner/base occupied color. */
.base.active {
  background: var(--runner-orange);
}

/* Make the 回表 / 回裏 part more prominent while keeping the inning number dominant. */
.inning-label,
#inningHalf {
  font-size: 0.56em;
}

/* Slightly brighter out-count lamp. */
.lamp.out.on {
  background: var(--out-red);
}
