:root {
  --bg-color: #06196eee;

  --front-bg: #f8da30;
  --icon-color: #414141;
  --icon-selected-color: #414141;
  --icon-disabled-color: #2e2e2eb6;
  --icon-enabled-color: #7a7a7a;
  --ring-color: #e18a2a;

  --back-bg: #ca3b25f1;
  --back-text: #1d1a05;

  /* Sizes that use the same vw/vh factor in both orientations collapse to a
     single min() expression (the original always used the smaller axis). */
  --modal-size: min(4vw, 4vh);
  --round-size: min(7.5vw, 7.5vh);
  --go-size: min(4.5vw, 4.5vh);
  --clock-size: min(34vw, 34vh);
  --dot-size: min(95vw, 95vh);
  --ring-size: min(99vw, 99vh);
}

/* These sizes use different vw/vh factors per orientation, so they need to
   stay tied to actual orientation rather than a min() of both axes. */
@media (orientation: portrait) {
  :root {
    --help-icon-size: 7.7vw;
    --stop-size: 5vw;
    --digit-size: 12vw;
    --digit-size-large: 12vw;
    --infinity-size: 11vw;
    --icon-box-size: 20vw;
    --tile-padding: 1vw;
  }
}

@media (orientation: landscape) {
  :root {
    --help-icon-size: 6.6vh;
    --stop-size: 3.8vh;
    --digit-size: 7vh;
    --digit-size-large: 5vh;
    --infinity-size: 7vh;
    --icon-box-size: 15vh;
    --tile-padding: 1.5vh;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-color);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  scrollbar-width: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

button {
  font: inherit;
  color: inherit;
}

.app {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
}

/* The coin */
.dot {
  position: relative;
  display: flex;
  height: var(--dot-size);
  width: var(--dot-size);
  border-radius: 50%;
  transform-style: preserve-3d;
  transition: transform 0.25s ease;
}

.dot.flipped {
  transform: rotateY(180deg);
}

.dotfront,
.dotback {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.dotfront {
  background: var(--front-bg);
}

.dotback {
  background: var(--back-bg);
  transform: rotateY(180deg);
  transition: background-color 0.4s ease;
}

.dotback.resting {
  background: var(--ring-color);
}

.ring-overlay {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%) scale(1.02);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-overlay.hidden {
  display: none;
}

.ring-spinner {
  width: var(--ring-size);
  height: var(--ring-size);
  animation: ring-rotate 1.6s linear infinite;
}

.ring-spinner-track {
  stroke: var(--ring-color);
  stroke-width: 3;
  stroke-linecap: round;
  transform-origin: center;
  animation: ring-dash 1.6s ease-in-out infinite;
}

@keyframes ring-rotate {
  100% {
    transform: rotate(360deg);
  }
}

@keyframes ring-dash {
  0% {
    stroke-dasharray: 1, 450;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 209, 450;
    stroke-dashoffset: -82;
  }
  100% {
    stroke-dasharray: 209, 450;
    stroke-dashoffset: -291;
  }
}

/* Round options (front) */
.round-options {
  padding-top: 2vw;
  text-align: center;
}

@media (orientation: landscape) {
  .round-options {
    padding-top: 7vh;
  }
}

.section-label {
  color: var(--icon-color);
  opacity: 0.5;
  font-size: min(2.76vw, 2.28vh);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.tile-row {
  display: flex;
  justify-content: center;
}

.go-row {
  display: flex;
  justify-content: center;
  margin-top: 1.4vw;
}

@media (orientation: landscape) {
  .go-row {
    margin-top: 1.2rem;
  }
}

.tile-button {
  background: none;
  border: none;
  padding: var(--tile-padding);
  border-radius: calc(var(--icon-box-size) * 0.2 + var(--tile-padding));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tile-button:disabled {
  cursor: default;
}

.tile-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(65, 65, 65, 0.25);
}

.icon-tile {
  position: relative;
  width: var(--icon-box-size);
  height: var(--icon-box-size);
  border-radius: calc(var(--icon-box-size) * 0.2);
  box-shadow: inset 0 0 0 calc(var(--icon-box-size) * 0.055) var(--icon-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--icon-color);
}

.icon-tile.disabled {
  box-shadow: inset 0 0 0 calc(var(--icon-box-size) * 0.055) var(--icon-disabled-color);
  color: var(--icon-disabled-color);
}

.icon-tile.selected {
  box-shadow: none;
  background: var(--icon-selected-color);
  color: var(--front-bg);
}

.digit-text {
  font-size: var(--digit-size);
  font-weight: bold;
  line-height: 1;
}

.digit-text.large {
  font-size: var(--digit-size-large);
}

.digit-text.go-text {
  font-size: var(--go-size);
}

.infinity-glyph {
  font-size: var(--infinity-size);
  line-height: 1;
}

/* Stopwatch (back) */
.stopwatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 7.5vw;
}

@media (orientation: landscape) {
  .stopwatch {
    margin-top: 5.6vh;
  }
}

.stopwatch.hidden {
  display: none;
}

.clock {
  color: var(--back-text);
  line-height: 1;
  font-weight: bold;
  font-size: var(--clock-size);
}

.round-label {
  color: var(--back-text);
  line-height: 1.2;
  font-size: var(--round-size);
  padding-top: 3.5vw;
}

@media (orientation: landscape) {
  .round-label {
    padding-top: 2.6vh;
  }
}

.stop-button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--back-text);
  font-size: var(--stop-size);
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.04em;
  padding: 0.45em 1em;
  border-radius: 999px;
  opacity: 0.75;
  margin-top: 3.2vw;
}

@media (orientation: landscape) {
  .stop-button {
    margin-top: 2.4vh;
  }
}

.stop-button:hover {
  opacity: 1;
}

.stop-button:focus-visible {
  opacity: 1;
  outline: none;
  box-shadow: 0 0 0 0.35em rgba(29, 26, 5, 0.15);
}

/* Corner actions */
.corner-actions {
  position: absolute;
  bottom: 1vw;
  right: 1vw;
  display: flex;
  gap: 0.5rem;
}

.icon-button {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: 50%;
  color: var(--icon-color);
  font-size: var(--help-icon-size);
  line-height: 1;
}

.icon-button:hover {
  background: rgba(19, 54, 85, 0.08);
}

.icon-button:focus-visible {
  outline: 2px solid var(--icon-color);
  outline-offset: 2px;
}

.gear-glyph {
  font-size: 1em;
}

/* Settings modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.28);
  z-index: 2000;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  position: relative;
  width: min(84vw, 760px);
  max-height: 82vh;
  overflow-y: auto;
  scrollbar-width: none;
  border-radius: 24px;
  border: 1px solid rgba(19, 54, 85, 0.12);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 22px 60px rgba(19, 54, 85, 0.18);
  padding: clamp(18px, 3vw, 32px);
  color: var(--icon-color);
}

.modal-card::-webkit-scrollbar {
  display: none;
}

.modal-title {
  font-size: var(--modal-size);
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 0 0 1rem;
}

.modal-sublabel {
  opacity: 0.7;
  font-size: var(--modal-size);
  margin: 0 0 0.5rem;
}

.modal-hint {
  font-size: 0.72em;
  opacity: 0.8;
}

.chip-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.chip {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--icon-color);
  background: transparent;
  color: var(--icon-color);
  cursor: pointer;
  font-size: var(--modal-size);
}

.chip:hover {
  background: rgba(19, 54, 85, 0.06);
}

.chip.selected {
  background: var(--icon-color);
  color: var(--front-bg);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.text-button,
.filled-button {
  border: none;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 1rem;
}

.text-button {
  background: none;
  color: var(--icon-color);
}

.filled-button {
  background: var(--icon-color);
  color: var(--front-bg);
}

.filled-button:disabled {
  opacity: 0.45;
  cursor: default;
}
