:root {
  --bg: #f6f7f2;
  --ink: #162019;
  --muted: #637066;
  --line: #d8ddd3;
  --panel: #ffffff;
  --navy: #17324d;
  --green: #1e7a47;
  --orange: #d86f27;
  --gold: #e3b341;
  --red: #b43d35;
  --blue: #3468a6;
  --shadow: 0 10px 24px rgba(22, 32, 25, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  -webkit-tap-highlight-color: transparent;
}

button,
select,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
}

.status-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--navy);
  border-radius: 8px;
  background: var(--navy);
  box-shadow: var(--shadow);
}

.status-bar > div {
  min-width: 0;
  padding: 10px 8px;
  background: var(--navy);
  color: #fff;
}

.label {
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  line-height: 1.15;
}

.value {
  margin-top: 4px;
  overflow: hidden;
  font-size: 17px;
  font-weight: 750;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count {
  color: #ffe19a;
}

.quick-actions,
.submit-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.submit-strip {
  grid-template-columns: 1fr 0.62fr;
  position: sticky;
  bottom: 0;
  z-index: 9;
  padding: 8px 0 0;
  background: linear-gradient(rgba(246, 247, 242, 0), var(--bg) 24%);
}

.control-button,
.submit-button,
.export-button,
.small-button,
.dialog-actions button {
  min-height: 44px;
  border-radius: 8px;
  background: #e8ece4;
  color: var(--ink);
  font-weight: 750;
}

.control-button {
  padding: 8px 6px;
  font-size: 13px;
}

.primary-control {
  background: #d8ede0;
  color: #143b25;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.submit-button {
  min-height: 58px;
  background: var(--green);
  color: #fff;
  font-size: 19px;
}

.submit-button.ready {
  background: var(--orange);
}

.export-button {
  min-height: 58px;
  background: var(--blue);
  color: #fff;
}

.danger {
  color: #fff;
  background: var(--red);
}

.panel {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(22, 32, 25, 0.04);
}

.state-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.mini-stat {
  min-width: 0;
  padding: 10px 8px;
  background: #fff;
}

.mini-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.mini-stat strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone-and-result {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 20px;
}

.zone-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(44px, 1fr));
  gap: 5px;
  padding: 0 10px 10px;
}

.zone-button {
  aspect-ratio: 1 / 1;
  min-height: 46px;
  border: 2px solid transparent;
  border-radius: 7px;
  background: #efe7d3;
  color: #2a2417;
  font-weight: 850;
}

.zone-button.strike-zone {
  background: #d8ede0;
  color: #143b25;
}

.zone-button.selected {
  border-color: var(--orange);
  background: var(--orange);
  color: #fff;
}

.button-grid {
  display: grid;
  gap: 8px;
  padding: 0 10px 10px;
}

.result-grid {
  grid-template-columns: repeat(2, 1fr);
}

.result-button,
.pitch-type-button,
.pitch-detail-button,
.action-button,
.confidence-button,
.speed-button {
  min-height: 48px;
  border-radius: 8px;
  background: #eef1eb;
  color: var(--ink);
  font-weight: 750;
}

.result-button.selected,
.pitch-type-button.selected,
.pitch-detail-button.selected,
.action-button.selected,
.confidence-button.selected,
.speed-button.selected {
  background: var(--navy);
  color: #fff;
}

.result-button[data-value="ball"].selected {
  background: var(--green);
}

.result-button[data-value="called_strike"].selected,
.result-button[data-value="swinging_strike"].selected,
.result-button[data-value="foul"].selected {
  background: var(--red);
}

.speed-controls {
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.speed-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  padding: 0 10px 10px;
}

.pitch-type-grid {
  grid-template-columns: repeat(6, 1fr);
}

.side-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 10px 10px;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

select,
input {
  min-height: 42px;
  padding: 0 8px;
}

textarea {
  display: block;
  margin: 0 10px 10px;
  padding: 10px;
  resize: vertical;
}

.action-grid {
  grid-template-columns: repeat(2, 1fr);
}

.pitch-detail-grid {
  grid-template-columns: repeat(4, 1fr);
}

.confidence-grid {
  grid-template-columns: repeat(3, 1fr);
}

.recent-list {
  display: grid;
  gap: 1px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  background: var(--line);
}

.recent-row {
  display: grid;
  grid-template-columns: 64px 1fr 72px;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 8px 10px;
  background: #fff;
  font-size: 13px;
}

.recent-row strong {
  font-size: 14px;
}

.recent-row span {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

dialog {
  width: min(92vw, 360px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(12, 20, 16, 0.42);
}

.dialog-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.dialog-actions button:last-child {
  background: var(--green);
  color: #fff;
}

.batter-side-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.batter-side-buttons button {
  min-height: 80px;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  font-size: 28px;
  font-weight: 850;
}

@media (max-width: 760px) {
  .app-shell {
    padding-inline: 8px;
  }

  .status-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .quick-actions {
    grid-template-columns: repeat(2, 1fr);
  }

  .state-panel {
    grid-template-columns: repeat(2, 1fr);
  }

  .zone-and-result {
    grid-template-columns: 1fr;
  }

  .zone-grid {
    grid-template-columns: repeat(5, minmax(52px, 1fr));
  }

  .pitch-type-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .side-controls {
    grid-template-columns: 1fr;
  }
}
