*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: linear-gradient(160deg, #e8f5e9 0%, #c8e6c9 40%, #a5d6a7 100%);
  color: #1b5e20;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(0.75rem, 3vw, 1.25rem);
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.header {
  margin-bottom: 0.75rem;
}

.header__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.title {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.timer-settings {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.timer-settings-label {
  font-size: 0.875rem;
  opacity: 0.85;
  white-space: nowrap;
}

.timer-select {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.35rem 0.5rem;
  border: 2px solid #2e7d32;
  border-radius: 0.5rem;
  background: #fff;
  color: #1b5e20;
  cursor: pointer;
  touch-action: manipulation;
}

.timer-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.timer-select:focus-visible {
  outline: 2px solid #1b5e20;
  outline-offset: 2px;
}

.timer-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.timer-label {
  font-size: 0.875rem;
  opacity: 0.85;
}

.timer-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 3.25ch;
}

.timer-value--warn {
  color: #c62828;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.score-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  margin-left: auto;
}

.score-label {
  font-size: 0.875rem;
  opacity: 0.85;
}

.score-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 2.5ch;
}

.btn-start,
.btn-reset {
  padding: 0.45rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 600;
  border: 2px solid #2e7d32;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-start {
  background: #2e7d32;
  color: #fff;
}

.btn-start:hover:not(:disabled) {
  background: #1b5e20;
}

.btn-start:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-reset {
  background: #fff;
  color: #1b5e20;
}

.btn-reset:hover {
  background: #e8f5e9;
}

.btn-start:focus-visible,
.btn-reset:focus-visible {
  outline: 2px solid #1b5e20;
  outline-offset: 2px;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  opacity: 0.9;
  line-height: 1.4;
}

.sum-display {
  margin: 0.35rem 0 0;
  min-height: 1.25em;
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #c62828;
}

.board-wrap {
  background: rgba(255, 255, 255, 0.45);
  border-radius: 1rem;
  padding: clamp(0.5rem, 2vw, 0.75rem);
  box-shadow: 0 4px 24px rgba(27, 94, 32, 0.12);
}

.board {
  display: grid;
  gap: clamp(3px, 1vw, 6px);
  width: 100%;
  user-select: none;
  touch-action: none;
}

.board--locked {
  pointer-events: none;
  opacity: 0.72;
  filter: grayscale(0.15);
}

.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 800;
  font-size: clamp(0.7rem, 2.8vw, 1.05rem);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  border: 2px solid rgba(45, 12, 16, 0.9);
  background-color: transparent;
  background-image: url("../assets/apple.png");
  background-repeat: no-repeat;
  background-position: center 52%;
  background-size: 92% 92%;
  color: #fff;
  text-shadow:
    0 0 3px rgba(0, 0, 0, 0.65),
    0 1px 2px rgba(0, 0, 0, 0.5);
  box-shadow: 0 2px 8px rgba(30, 8, 10, 0.22);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
}

@media (prefers-reduced-motion: reduce) {
  .cell {
    transition: none;
  }
}

.cell--empty {
  visibility: hidden;
  pointer-events: none;
  border-color: transparent;
  background-color: transparent;
  background-image: none;
  box-shadow: none;
}

.cell--selected {
  border-color: #f5c84c;
  filter: brightness(1.12) saturate(1.05);
  box-shadow:
    0 0 0 3px rgba(230, 140, 20, 0.95),
    0 4px 14px rgba(180, 90, 10, 0.35);
  z-index: 1;
}

.cell:active:not(.cell--empty) {
  transform: scale(0.96);
}

@media (max-width: 480px) {
  .board {
    gap: 4px;
  }

  .cell {
    border-width: 2px;
    font-size: clamp(0.65rem, 3.5vw, 0.95rem);
  }

  .timer-settings {
    order: 2;
    width: 100%;
    justify-content: flex-start;
  }

  .timer-wrap {
    order: 3;
  }

  .score-wrap {
    margin-left: 0;
    width: 100%;
    order: 5;
  }

  .header__actions {
    order: 4;
    margin-left: auto;
    width: 100%;
    justify-content: flex-end;
  }
}

@media (min-width: 481px) {
  .header__row {
    flex-wrap: nowrap;
  }
}
