:root {
  color-scheme: light;
  --ink: #101722;
  --muted: #6c7685;
  --line: rgba(16, 23, 34, 0.12);
  --paper: #edf1f5;
  --panel: rgba(255, 255, 255, 0.88);
  --night: #142033;
  --night-2: #22334a;
  --active: #f04438;
  --active-soft: #fff1ef;
  --field: #19a36f;
  --field-dark: #0c6e4a;
  --electric: #2f6df6;
  --gold: #ffbd2e;
  --shadow: 0 18px 40px rgba(16, 23, 34, 0.18);
  --inner-glow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  background:
    linear-gradient(135deg, rgba(47, 109, 246, 0.14) 0 18%, transparent 18% 100%),
    linear-gradient(165deg, transparent 0 54%, rgba(25, 163, 111, 0.15) 54% 72%, transparent 72%),
    linear-gradient(180deg, #f8fafc 0, #edf1f5 42%, #e7edf3 100%);
  color: var(--ink);
  font-family:
    Inter,
    "SF Pro Display",
    "PingFang SC",
    "Microsoft YaHei",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background:
    repeating-linear-gradient(
      90deg,
      rgba(16, 23, 34, 0.055) 0,
      rgba(16, 23, 34, 0.055) 1px,
      transparent 1px,
      transparent 28px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(16, 23, 34, 0.035) 0,
      rgba(16, 23, 34, 0.035) 1px,
      transparent 1px,
      transparent 28px
    );
  mask-image: linear-gradient(180deg, black 0, transparent 74%);
}

button,
input {
  font: inherit;
}

input[type="number"] {
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.app {
  position: relative;
  width: min(100%, 520px);
  max-width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px max(30px, env(safe-area-inset-bottom));
  overflow-x: clip;
  touch-action: pan-y;
}

.app::before {
  position: absolute;
  top: 86px;
  right: -54px;
  z-index: -1;
  width: 188px;
  height: 188px;
  border: 20px solid rgba(240, 68, 56, 0.18);
  border-bottom-color: rgba(25, 163, 111, 0.22);
  transform: rotate(45deg);
  content: "";
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 116px;
  gap: 14px;
  margin-bottom: 14px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(115deg, rgba(255, 189, 46, 0.92) 0 17%, transparent 17% 100%),
    linear-gradient(160deg, rgba(240, 68, 56, 0.9) 0 28%, transparent 28% 100%),
    linear-gradient(135deg, var(--night) 0, var(--night-2) 100%);
  box-shadow: 0 20px 46px rgba(20, 32, 51, 0.28);
  color: #fff;
}

.top-actions {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.install-button {
  background: rgba(255, 189, 46, 0.96);
  color: var(--night);
}

.install-button[hidden] {
  display: none;
}

.topbar::before,
.topbar::after {
  position: absolute;
  pointer-events: none;
  content: "";
}

.topbar::before {
  right: 68px;
  bottom: -46px;
  width: 132px;
  height: 132px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
}

.topbar::after {
  right: -28px;
  bottom: 12px;
  width: 150px;
  height: 72px;
  border-top: 2px solid rgba(255, 255, 255, 0.45);
  border-bottom: 2px solid rgba(255, 255, 255, 0.22);
  transform: rotate(-24deg);
}

.eyebrow {
  position: relative;
  margin: 0 0 7px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  position: relative;
  max-width: 190px;
  font-size: 30px;
  line-height: 1.05;
  text-wrap: balance;
}

h2 {
  font-size: 18px;
}

.ghost-button,
.primary-button,
.secondary-button {
  position: relative;
  border: 0;
  border-radius: 8px;
  min-height: 46px;
  padding: 0 14px;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    background-color 0.15s ease,
    border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.ghost-button {
  min-width: 68px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  backdrop-filter: blur(10px);
}

.primary-button {
  width: 100%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent),
    var(--field);
  color: #fff;
  box-shadow: 0 10px 20px rgba(12, 110, 74, 0.25);
}

.secondary-button {
  width: 100%;
  border: 1px solid rgba(16, 23, 34, 0.1);
  background: #f4f7fb;
  color: var(--night);
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(47, 109, 246, 0.28);
  outline-offset: 2px;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.team-panel,
.inning-card,
.counter-card,
.detail-section {
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow), var(--inner-glow);
  backdrop-filter: blur(16px);
}

.team-panel {
  position: relative;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 92px;
  padding: 13px;
  overflow: hidden;
}

.team-panel::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 7px;
  background: #cfd8e3;
  content: "";
}

.team-panel::after {
  position: absolute;
  right: 76px;
  top: -24px;
  width: 66px;
  height: 116px;
  background: rgba(47, 109, 246, 0.08);
  transform: skewX(-22deg);
  content: "";
}

.team-panel.active {
  background:
    linear-gradient(112deg, rgba(255, 241, 239, 0.95), rgba(255, 255, 255, 0.92) 72%),
    var(--panel);
}

.team-panel.active::before {
  background: var(--active);
}

.team-panel label {
  position: relative;
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
}

.team-panel input {
  position: relative;
  min-width: 0;
  width: 100%;
  border: 1px solid rgba(16, 23, 34, 0.1);
  border-radius: 8px;
  padding: 10px 11px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-weight: 900;
}

.team-panel .score-input {
  position: relative;
  min-width: 58px;
  width: 74px;
  border: 0;
  background: transparent;
  padding: 4px 0;
  text-align: right;
  font-family: "Arial Black", Impact, system-ui, sans-serif;
  font-size: 48px;
  line-height: 0.9;
  color: var(--night);
  font-variant-numeric: tabular-nums;
}

.team-panel.active .score-input {
  color: var(--active);
}

.inning-card {
  position: relative;
  padding: 13px;
  overflow: hidden;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(25, 163, 111, 0.18), transparent 44%),
    rgba(255, 255, 255, 0.9);
}

.inning-card::before {
  position: absolute;
  top: 12px;
  left: 50%;
  width: 58px;
  height: 58px;
  border: 2px solid rgba(25, 163, 111, 0.32);
  transform: translateX(-50%) rotate(45deg);
  content: "";
}

.inning-card > span {
  position: relative;
  display: block;
  margin-bottom: 10px;
  font-size: 19px;
  font-weight: 950;
}

.inning-stepper {
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  margin-bottom: 10px;
}

.step-button {
  min-height: 42px;
  border: 1px solid rgba(16, 23, 34, 0.12);
  border-radius: 8px;
  background: #f4f7fb;
  color: var(--night);
  font-size: 22px;
  font-weight: 950;
}

.inning-input-wrap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-height: 42px;
  border: 1px solid rgba(16, 23, 34, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 0 10px;
}

.inning-input-wrap span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
}

.inning-input-wrap input {
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--night);
  text-align: center;
  font-weight: 950;
}

.half-row,
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.half-pill {
  position: relative;
  min-height: 42px;
  border: 1px solid rgba(16, 23, 34, 0.12);
  border-radius: 8px;
  background: #f4f7fb;
  color: var(--muted);
  font-weight: 950;
}

.half-pill.active {
  border-color: rgba(240, 68, 56, 0.22);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent),
    var(--active);
  color: #fff;
  box-shadow: 0 9px 18px rgba(240, 68, 56, 0.24);
}

.count-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.counter-card {
  position: relative;
  display: flex;
  min-height: 178px;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  overflow: hidden;
}

.counter-card::before {
  position: absolute;
  top: 0;
  right: 0;
  width: 64px;
  height: 64px;
  background: var(--accent, rgba(25, 163, 111, 0.16));
  clip-path: polygon(100% 0, 0 0, 100% 100%);
  content: "";
}

.counter-card:nth-child(1) {
  --accent: rgba(47, 109, 246, 0.2);
}

.counter-card:nth-child(2) {
  --accent: rgba(255, 189, 46, 0.28);
}

.counter-card:nth-child(3) {
  --accent: rgba(25, 163, 111, 0.24);
}

.counter-card:nth-child(4) {
  --accent: rgba(240, 68, 56, 0.2);
}

.counter-card span {
  position: relative;
  color: var(--muted);
  font-size: 13px;
  font-weight: 950;
}

.counter-card .count-input {
  position: relative;
  width: 100%;
  border: 0;
  background: transparent;
  font-family: "Arial Black", Impact, system-ui, sans-serif;
  font-size: 54px;
  line-height: 0.92;
  color: var(--night);
  font-variant-numeric: tabular-nums;
}

.counter-card .button-row {
  grid-template-columns: 1fr;
}

.detail-section {
  padding: 14px;
  overflow: hidden;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-title span {
  border: 1px solid rgba(240, 68, 56, 0.14);
  border-radius: 999px;
  background: var(--active-soft);
  color: var(--active);
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 950;
  white-space: nowrap;
}

.score-table-wrap {
  overflow-x: auto;
  border: 1px solid rgba(16, 23, 34, 0.1);
  border-radius: 8px;
  background: #fff;
}

.score-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  background: #fff;
}

.score-table th,
.score-table td {
  min-width: 44px;
  border-bottom: 1px solid rgba(16, 23, 34, 0.09);
  padding: 12px 8px;
  text-align: center;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.score-table th {
  background: #f5f7fb;
  color: var(--muted);
  font-size: 12px;
}

.score-table th:first-child,
.score-table td:first-child {
  position: sticky;
  left: 0;
  min-width: 92px;
  max-width: 140px;
  background: #fff;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 1;
}

.score-table th:first-child {
  background: #f5f7fb;
}

.score-table th:last-child,
.score-table td:last-child {
  color: var(--active);
}

.table-score-input {
  width: 44px;
  border: 1px solid rgba(16, 23, 34, 0.1);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--night);
  padding: 8px 4px;
  text-align: center;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.score-table tr:last-child td {
  border-bottom: 0;
}

.score-table tr.active-row td:first-child {
  background: var(--active-soft);
  color: var(--active);
}

@media (min-width: 430px) {
  .scoreboard {
    grid-template-columns: 1fr 0.95fr 1fr;
    align-items: stretch;
  }

  .team-panel {
    grid-template-columns: 1fr;
    min-height: 158px;
    text-align: center;
  }

  .team-panel::before {
    inset: 0 0 auto;
    width: 100%;
    height: 7px;
  }

  .team-panel .score-input {
    min-width: 0;
    width: 100%;
    text-align: center;
  }
}
