:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --primary: #0b2545;
  --accent: #00a8e8;
  --paper: #ffffff;
  --panel: #f5f7fa;
  --line: #e4e9f0;
  --muted: #718096;
  --danger: #eb5757;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #ffffff;
  color: var(--primary);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.login-shell {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 20px;
  background: #f5f7fa;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(100%, 380px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-card input {
  min-height: 46px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--primary);
  background: #ffffff;
}

.login-error,
.sync-warning {
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 28px 18px;
  border-right: 1px solid var(--line);
  background: var(--paper);
}

.sidebar h1,
h2,
h3,
p {
  margin: 0;
}

.sidebar h1 {
  margin-top: 4px;
  font-size: 26px;
  line-height: 1;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

nav {
  display: grid;
  gap: 8px;
}

.nav-button,
.ghost,
.primary {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.nav-button {
  padding: 0 14px;
  background: transparent;
  color: var(--primary);
  text-align: left;
}

.nav-link {
  display: inline-grid;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  color: var(--danger);
  font-weight: 800;
  text-decoration: none;
}

.nav-button.active {
  background: var(--primary);
  color: white;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.topbar > div,
.panel,
.history-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.topbar > div {
  padding: 16px;
}

.topbar strong {
  display: block;
  margin-top: 6px;
  color: var(--accent);
  font-size: 28px;
}

.topbar small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.cloud-card.synced strong {
  color: #0f9f6e;
}

.cloud-card.syncing strong {
  color: #0ea5e9;
}

.cloud-card.offline strong {
  color: var(--danger);
}

.sync-warning {
  grid-column: 1 / -1;
}

.grid {
  display: grid;
  gap: 18px;
}

.two-col {
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
}

.panel {
  padding: 18px;
}

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

.section-head h2 {
  margin-top: 4px;
  font-size: 21px;
}

.target-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  background: white;
  color: var(--primary);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.session-form {
  display: grid;
  gap: 12px;
}

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

input,
select {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--primary);
  font-size: 16px;
}

.primary {
  padding: 0 16px;
  background: var(--accent);
  color: white;
}

.ghost {
  padding: 0 14px;
  background: white;
  color: var(--primary);
  border: 1px solid var(--line);
}

.danger {
  color: var(--danger);
}

.wide {
  width: 100%;
  margin-top: 14px;
}

.active-card {
  display: grid;
  gap: 14px;
}

.active-card p,
.hint,
.muted {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.current-score-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.current-score-summary span {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.current-score-summary strong {
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
}

.score-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.score-chip {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  font-weight: 900;
}

.score-chip.score-10,
.score-count-chip.score-10 {
  background: #f0c419;
  color: #0b2545;
}

.score-chip.score-9,
.score-count-chip.score-9 {
  background: #ffe17a;
  color: #0b2545;
}

.score-chip.score-8,
.score-count-chip.score-8 {
  background: #d94141;
  color: #ffffff;
}

.score-chip.score-7,
.score-count-chip.score-7 {
  background: #ff7a70;
  color: #ffffff;
}

.score-chip.score-6,
.score-count-chip.score-6 {
  background: #0d8bd6;
  color: #ffffff;
}

.score-chip.score-5,
.score-count-chip.score-5 {
  background: #61c3ff;
  color: #0b2545;
}

.score-chip.score-m,
.score-count-chip.score-m {
  background: #2d3748;
  color: #ffffff;
}

.score-frequency {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 5px;
  vertical-align: middle;
}

.score-count-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  color: white;
  font-size: 12px;
  font-weight: 900;
}

.score-count-chip b,
.score-count-chip i,
.score-count-chip em {
  font-style: normal;
}


.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.end-photo-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.end-photo-card > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.end-photo-card strong {
  font-size: 14px;
}

.end-photo-card span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.end-photo-card .hint {
  grid-column: 1 / -1;
}

.file-button {
  display: inline-grid;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.keypad button,
.score-picker button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: white;
  color: var(--primary);
  font-weight: 900;
}

.score-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.score-picker button.active {
  background: var(--primary);
  color: white;
}

.target-panel,
.photo-panel {
  display: grid;
  align-content: start;
}

.target-canvas,
.photo-canvas {
  display: block;
  width: 100%;
  max-width: 760px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: white;
  touch-action: manipulation;
  user-select: none;
}

.target-canvas.small {
  max-width: 420px;
  margin: 12px auto;
}

.photo-tools {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.photo-context,
.photo-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.photo-context span,
.photo-summary span {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.photo-context strong,
.photo-summary strong {
  overflow: hidden;
  color: var(--primary);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.export-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.export-card > div {
  min-width: 0;
}

.export-card strong {
  display: block;
  overflow: hidden;
  color: var(--primary);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.export-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
}

.photo-arrow-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.photo-arrow-row {
  display: grid;
  grid-template-columns: 42px 42px minmax(0, 1fr) 76px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.photo-arrow-row > strong {
  font-size: 14px;
}

.photo-arrow-row > span:not(.score-chip) {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-arrow-row select {
  min-height: 38px;
  padding: 0 8px;
  font-size: 14px;
}

.empty.compact {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.history-list,
.group-list,
.end-list {
  display: grid;
  gap: 10px;
}

.group-list {
  gap: 12px;
}

.history-section {
  display: grid;
  gap: 10px;
}

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

.history-section-head strong {
  color: var(--primary);
}

.history-section-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.history-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  padding: 16px 86px 16px 16px;
  color: var(--primary);
  text-align: left;
}

.history-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 168, 232, 0.12);
}

.history-card span,
.history-score span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.history-score {
  text-align: right;
}

.history-score strong {
  color: var(--accent);
}

.recent-panel {
  display: grid;
  gap: 12px;
}

.recent-list {
  display: grid;
  gap: 10px;
}

.latest-session-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 96px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--primary);
  text-align: left;
}

.latest-session-card > div:first-child,
.latest-score {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.latest-session-card strong {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.latest-session-card span {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.latest-score {
  justify-items: end;
  text-align: right;
}

.latest-score strong {
  color: var(--accent);
  font-size: 34px;
  line-height: 1;
}

.delete {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--danger) !important;
}

.empty {
  padding: 32px 14px;
  border: 1px dashed #c8d2df;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.detail-nav {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.detail-nav .ghost {
  min-width: 92px;
}

.detail-summary,
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.detail-summary span,
.metrics span {
  padding: 12px;
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-weight: 700;
}

.detail-summary strong,
.metrics strong {
  color: var(--primary);
}

.aggregate-box {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.aggregate-list {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.group-overall {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.group-chart-canvas {
  display: block;
  width: 100%;
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.group-pie-canvas {
  display: block;
  width: 100%;
  min-height: 230px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.aggregate-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.aggregate-head strong {
  display: block;
  margin-top: 4px;
}

.aggregate-head span {
  color: var(--accent);
  font-weight: 900;
  white-space: nowrap;
}

.insight-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.insight-row {
  display: grid;
  grid-template-columns: 62px repeat(5, minmax(62px, 1fr));
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.insight-row strong {
  color: var(--primary);
}

.insight-row small {
  grid-column: 2 / -1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.insight-row.aggregate {
  background: var(--panel);
}

.end-row {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: white;
}

.end-row > div {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

@media (max-width: 920px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 20;
    height: auto;
    padding: 8px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    border-right: 0;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .sidebar > div {
    display: none;
  }

  nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .nav-button {
    min-height: 48px;
    padding: 0 8px;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
  }

  .nav-link {
    display: none;
  }

  .two-col,
  .detail-summary,
  .metrics,
  .current-score-summary,
  .photo-context,
  .photo-summary,
  .export-card {
    grid-template-columns: 1fr;
  }

  .insight-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .insight-row strong,
  .insight-row small {
    grid-column: 1 / -1;
  }

  .aggregate-head {
    display: grid;
  }

  .aggregate-head span {
    white-space: normal;
  }

  .main {
    padding: max(12px, env(safe-area-inset-top)) 12px calc(86px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: -12px -12px 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
  }

  .topbar > div {
    padding: 10px;
  }

  .topbar strong {
    font-size: 21px;
  }

  .topbar small {
    font-size: 11px;
  }

  .panel {
    padding: 14px;
  }

  .target-panel,
  .photo-panel {
    padding: 8px;
  }

  .section-head {
    align-items: flex-start;
    padding: 6px 6px 0;
  }

  .section-head h2 {
    font-size: 19px;
  }

  .target-badge {
    min-height: 32px;
    font-size: 12px;
  }

  .keypad,
  .score-picker {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .keypad button,
  .score-picker button,
  .primary,
  .ghost {
    min-height: 50px;
  }

  .target-canvas,
  .photo-canvas {
    max-width: none;
    border-radius: 10px;
  }

  .history-card {
    grid-template-columns: 1fr;
    padding-right: 16px;
  }

  .latest-session-card {
    grid-template-columns: 1fr;
  }

  .latest-score {
    justify-items: start;
    text-align: left;
  }

  .history-score {
    text-align: left;
  }

  .end-photo-card {
    grid-template-columns: 1fr;
  }

  .photo-arrow-row {
    grid-template-columns: 36px 38px minmax(0, 1fr) 68px;
    gap: 6px;
  }

  .delete {
    position: static;
    transform: none;
    margin-top: 8px !important;
  }
}

@media (max-width: 420px) {
  .main {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    margin-left: -10px;
    margin-right: -10px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar .eyebrow {
    font-size: 10px;
  }

  .topbar strong {
    font-size: 18px;
  }

  .score-chip {
    min-width: 34px;
    height: 34px;
  }

  .end-row {
    grid-template-columns: 58px minmax(0, 1fr) 36px;
  }
}
