:root {
  color-scheme: light;
  --green: #17613a;
  --green-2: #247c4d;
  --green-soft: #e7f4ec;
  --ink: #17211b;
  --muted: #637069;
  --line: #d5ddd8;
  --surface: #ffffff;
  --surface-2: #f4f7f5;
  --blue: #1769aa;
  --red: #b42318;
  --amber: #946200;
  --shadow: 0 8px 24px rgba(20, 39, 28, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--surface-2); color: var(--ink); }
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: calc(60px + env(safe-area-inset-top));
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  display: grid;
  grid-template-columns: 42px 34px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  color: white;
  background: var(--green);
}
.app-header #back-button[hidden] { display: grid !important; visibility: hidden; }

.header-title { min-width: 0; display: flex; flex-direction: column; }
.header-title strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-title span { font-size: 11px; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; }
.brand-mark span {
  width: 22px; height: 22px; border-radius: 50%; background: white;
  box-shadow: inset -4px -4px 0 #d6e3dc, 12px 12px 0 -9px rgba(255,255,255,.5);
}

.icon-button {
  width: 40px; height: 40px; border: 0; background: transparent; color: inherit;
  display: grid; place-items: center; font-size: 24px; border-radius: 6px;
}
.icon-button:active { background: rgba(255,255,255,.14); }

.app-main { width: min(100%, 920px); margin: 0 auto; padding: 14px 12px 24px; }
.bottom-nav {
  position: fixed; z-index: 45; left: 0; right: 0; bottom: 0;
  height: calc(62px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: white; border-top: 1px solid var(--line);
}
.bottom-nav button {
  border: 0; background: white; color: var(--muted); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.bottom-nav button span { font-size: 21px; line-height: 1; }
.bottom-nav button.active { color: var(--green); font-weight: 700; background: var(--green-soft); }

.screen-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 2px 0 14px; }
.screen-head h1 { margin: 0; font-size: 22px; }
.screen-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.section-title { margin: 20px 0 8px; font-size: 16px; }
.stack { display: grid; gap: 10px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.hole-actions {
  display: grid;
  grid-template-columns: .82fr .82fr .9fr 1.08fr 1.08fr;
  gap: 8px;
}

.hole-actions .button {
  min-width: 0;
  min-height: 58px;
  padding: 9px 4px;
  font-size: 20px;
  font-weight: 800;
  white-space: nowrap;
}

#penalty-minus,
#penalty-plus {
  font-size: 16px;
}

.button {
  min-height: 42px; border: 1px solid var(--line); border-radius: 6px; padding: 9px 13px;
  background: white; color: var(--ink); font-weight: 650;
}
.button.primary { background: var(--green); border-color: var(--green); color: white; }
.button.secondary { color: var(--green); border-color: #8bb39c; background: var(--green-soft); }
.button.danger { color: var(--red); border-color: #e2a29c; background: #fff3f1; }
.button.small { min-height: 34px; padding: 6px 9px; font-size: 13px; }
.button:disabled { opacity: .45; cursor: default; }

.summary-band {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 7px; overflow: hidden;
}
.summary-item { background: white; padding: 11px 6px; text-align: center; min-width: 0; }
.summary-item span { display: block; color: var(--muted); font-size: 11px; }
.summary-item strong { display: block; margin-top: 3px; font-size: 18px; overflow-wrap: anywhere; }

.panel { background: white; border: 1px solid var(--line); border-radius: 7px; padding: 12px; }
.notice { padding: 10px 12px; border-left: 4px solid var(--blue); background: #edf7ff; color: #164d75; font-size: 13px; }
.warning { border-left-color: var(--amber); background: #fff8e6; color: #654600; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); border: 1px dashed #b8c3bc; }

.list { display: grid; gap: 1px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--line); }
.list-row {
  width: 100%; border: 0; background: white; color: inherit; padding: 12px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; text-align: left; align-items: center;
}
.list-row:active { background: var(--green-soft); }
.list-main { min-width: 0; }
.list-title { font-weight: 720; overflow-wrap: anywhere; }
.list-detail { margin-top: 3px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.list-value { font-weight: 800; color: var(--green); text-align: right; }
.hole-current { box-shadow: inset 4px 0 var(--green); }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field { display: grid; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid #aebbb3; border-radius: 6px; padding: 10px; background: white; color: var(--ink);
}
.field textarea { min-height: 70px; resize: vertical; }
.select-button {
  width: 100%;
  min-height: 42px;
  border: 1px solid #aebbb3;
  border-radius: 6px;
  padding: 10px 42px 10px 10px;
  background-color: white;
  color: var(--ink);
  font: inherit;
  text-align: left;
  position: relative;
}
.select-button::before,
.select-button::after {
  content: "";
  position: absolute;
  right: 15px;
  width: 9px;
  height: 9px;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
}
.select-button::before {
  top: calc(50% - 10px);
  transform: rotate(225deg);
}
.select-button::after {
  top: calc(50% + 1px);
  transform: rotate(45deg);
}
.select-button:disabled {
  opacity: .55;
}
.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.choice-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-weight: 750;
}
.choice-button.selected {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}
.toggle-line { display: inline-flex; align-items: center; gap: 9px; min-height: 42px; }
.toggle-control {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  padding: 2px 4px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.toggle-control:focus-visible {
  outline: 3px solid rgba(23, 97, 58, .28);
  outline-offset: 3px;
  border-radius: 6px;
}
.toggle-control:focus:not(:focus-visible) {
  outline: none;
}
.toggle-control:active {
  background: transparent;
}
.toggle-control:disabled {
  opacity: .5;
  cursor: default;
}
.toggle-control:disabled .state-pill {
  background: white;
  border-color: #b8c3bc;
  color: var(--muted);
}
.toggle-mark {
  width: 28px;
  flex: 0 0 28px;
  color: #8b9690;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 27px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}
.toggle-control[data-checked="true"] .toggle-mark {
  color: var(--green);
}
.state-pill {
  min-width: 42px;
  padding: 3px 8px;
  border: 1px solid #8b9690;
  border-radius: 4px;
  color: var(--muted);
  background: white;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}
.state-pill.on {
  background: var(--green);
  border-color: var(--green);
  color: white;
}
.state-pill.off {
  background: white;
  border-color: #8b9690;
  color: var(--muted);
}

.shot-form { display: grid; gap: 11px; }
.gps-box { display: grid; gap: 8px; background: #eef6ff; border: 1px solid #b4d0e8; padding: 10px; border-radius: 7px; }
.gps-status { color: #27516e; font-size: 12px; overflow-wrap: anywhere; }
.shot-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.tag { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 7px; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-size: 11px; }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.warn { background: #fff4d7; color: #755100; }

.score-table { width: 100%; border-collapse: collapse; background: white; font-size: 13px; }
.score-table th, .score-table td { padding: 8px 5px; border-bottom: 1px solid var(--line); text-align: right; }
.score-table th:first-child, .score-table td:first-child { text-align: left; }
.score-table tfoot { font-weight: 800; }

.analysis-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.metric { background: white; border: 1px solid var(--line); border-radius: 7px; padding: 12px; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 4px; font-size: 23px; }
.bar { height: 9px; background: #e6ece8; overflow: hidden; margin-top: 8px; border-radius: 3px; }
.bar span { display: block; height: 100%; background: var(--green-2); }

#map { width: 100%; height: min(66vh, 620px); min-height: 360px; border: 1px solid var(--line); border-radius: 7px; background: #e8eeea; }
.map-label { background: var(--green); color: white; border: 2px solid white; border-radius: 4px; padding: 3px 6px; font-weight: 700; white-space: nowrap; box-shadow: 0 2px 5px rgba(0,0,0,.25); }

.app-dialog {
  position: fixed;
  z-index: 90;
  left: 50%;
  top: 50%;
  width: min(calc(100% - 24px), 620px);
  max-height: 86vh;
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: white;
  color: var(--ink);
  transform: translate(-50%, -50%);
}
.app-dialog[hidden] { display: none !important; }
body.dialog-open::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(11, 21, 15, .55);
}
.dialog-shell { max-height: 86vh; display: flex; flex-direction: column; margin: 0; background: white; color: var(--ink); border-radius: inherit; overflow: hidden; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-content { padding: 12px; overflow-y: auto; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }

.toast {
  position: fixed; z-index: 100; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom));
  width: min(calc(100% - 30px), 460px); transform: translate(-50%, 20px);
  padding: 10px 13px; background: #17211b; color: white; border-radius: 6px; text-align: center;
  opacity: 0; pointer-events: none; transition: .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  body { padding-bottom: 72px; }
  .app-main { padding: 22px 20px 42px; }
  .bottom-nav { height: 54px; padding: 0; box-shadow: 0 -3px 9px rgba(0,0,0,.05); }
  .bottom-nav button { flex-direction: row; gap: 7px; font-size: 13px; }
  .bottom-nav button span { font-size: 17px; }
  .analysis-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 390px) {
  .summary-band { grid-template-columns: repeat(2, 1fr); }
  .field-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
}
