:root {
  --bg: #111214;
  --surface: #1c1e22;
  --line: #2c2f35;
  --text: #f1f2f4;
  --muted: #8b919b;
  --accent: #4f8df5;
  --ok: #3ccf6e;
  --error: #ff6b6b;
  --start: #2fe06a;
  --hand: #3d8bff;
  --top: #ff3b30;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.3 -apple-system, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

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

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom)
    max(8px, env(safe-area-inset-left));
}

/* Problem title */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 6px;
  min-height: 56px;
}

.title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.grade {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.names {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.names strong,
.names small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.names strong {
  font-size: 16px;
}

.names small {
  color: var(--muted);
  font-size: 12px;
}

.bt {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  flex: none;
}

.bt svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bt[data-state='on'] {
  border-color: var(--accent);
  background: var(--accent);
}

.bt[data-state='on'] svg {
  stroke: #fff;
}

.bt[data-state='connecting'] {
  animation: pulse 1s ease-in-out infinite;
  border-color: var(--accent);
}

@keyframes pulse {
  50% {
    opacity: 0.4;
  }
}

/* Board */
.board {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  touch-action: none;
}

.board-svg {
  width: 100%;
  height: 100%;
}

.board-svg .dim {
  fill: rgba(0, 0, 0, 0.7);
}

.board-svg .ring {
  fill: none;
  stroke-width: 6;
}

.board-svg .ring[data-role='S'] {
  stroke: var(--start);
}

.board-svg .ring[data-role='P'] {
  stroke: var(--hand);
}

.board-svg .ring[data-role='E'] {
  stroke: var(--top);
}

/* Prev / list / next */
.bottom {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 6px 0 4px;
}

.bottom > button {
  background: var(--surface);
  border-radius: 12px;
  min-height: 52px;
}

#prev,
#next {
  width: 64px;
  font-size: 30px;
  line-height: 1;
}

.bottom > button:disabled {
  opacity: 0.35;
}

.open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.open small {
  color: var(--muted);
  font-size: 12px;
}

.status {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
  font-size: 14px;
}

.status[data-kind='error'] {
  color: var(--error);
}

/* Problem list */
.sheet {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  z-index: 10;
}

.sheet[hidden] {
  display: none;
}

.sheet-head,
.filters,
.sheet-foot {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
}

.filters {
  flex-wrap: wrap;
  padding-top: 0;
}

input[type='search'],
select,
.chip,
.segment,
.sheet-foot button,
#close {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 38px;
  padding: 0 10px;
  font-size: 14px;
}

input[type='search'] {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* no zoom on focus in iOS */
}

#close {
  color: var(--accent);
  font-weight: 600;
}

.segment {
  display: flex;
  padding: 2px;
  gap: 2px;
}

.segment button {
  padding: 0 12px;
  border-radius: 8px;
}

.segment button[aria-checked='true'],
.chip[aria-pressed='true'] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.count {
  margin: 0;
  padding: 0 14px 6px;
  color: var(--muted);
  font-size: 12px;
}

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line);
}

.results button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.results li.active button {
  background: var(--surface);
}

.results .g {
  width: 38px;
  font-weight: 800;
  flex: none;
}

.results .n {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.results .n span,
.results .n small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.results small {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  font-size: 10px;
  font-weight: 800;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0 3px;
  margin-left: 6px;
  vertical-align: 1px;
}

.sheet-foot {
  border-top: 1px solid var(--line);
}

.sheet-foot button {
  flex: 1;
}
