* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Courier New", Courier, monospace;
  background: radial-gradient(circle at top, #1a1428 0%, #0a0810 55%, #050408 100%);
  color: #e8dcc8;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
}

.header {
  margin-bottom: 1rem;
}

.header-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.header-nav {
  display: flex;
  justify-content: flex-start;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.header-center {
  text-align: center;
  min-width: 0;
}

.header-center h1 {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  letter-spacing: 0.08em;
  color: #f0e6c8;
  text-shadow: 0 0 18px rgba(200, 160, 80, 0.35);
}

.header-center p {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  opacity: 0.75;
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  margin-top: 0.35rem;
}

.header-meta p {
  margin: 0;
}

.countdown {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  opacity: 0.65;
  letter-spacing: 0.04em;
}

.stats-line {
  margin: 0;
  font-size: 0.72rem;
  color: #d4b850;
  letter-spacing: 0.03em;
}

.stats-line[hidden] {
  display: none !important;
}

.countdown--ready {
  opacity: 0.9;
  color: #d4b850;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.countdown--ready:hover {
  color: #f0e6c8;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
}

.header-btn {
  font: inherit;
  font-size: 0.78rem;
  color: #e8dcc8;
  background: #2a2238;
  border: 1px solid #4a3a58;
  border-radius: 4px;
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  white-space: nowrap;
}

.header-btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  line-height: 0;
}

.header-icon {
  display: block;
  flex-shrink: 0;
}

.header-icon--spin {
  animation: header-icon-spin 0.9s linear infinite;
}

@keyframes header-icon-spin {
  to {
    transform: rotate(360deg);
  }
}

.header-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.header-btn:not(:disabled):hover {
  background: #3a3048;
}

.header-btn--share[hidden],
.header-btn--ghost[hidden] {
  display: none;
}

.header-btn--ghost[aria-pressed="true"] {
  background: #5a4830;
  border-color: #d4b850;
  color: #fff8e8;
}

.header-btn--audio[aria-pressed="true"] {
  opacity: 0.65;
}

.canvas-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  border: 2px solid #3a3048;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), inset 0 0 30px rgba(80, 60, 120, 0.15);
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: #120e18;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.loading--done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-title {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: #c8b898;
  animation: loading-pulse 1.6s ease-in-out infinite;
}

.loading-bar {
  width: min(240px, 70%);
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.loading-bar-fill {
  width: 40%;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #6a5030, #d4b850, #6a5030);
  animation: loading-slide 1.1s ease-in-out infinite;
}

.name-prompt {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 3;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: min(320px, calc(100% - 24px));
  padding: 0.75rem 1rem;
  background: rgba(18, 14, 24, 0.92);
  border: 1px solid #4a3a58;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.name-prompt[hidden] {
  display: none;
}

.name-prompt-label {
  margin: 0;
  font-size: 0.82rem;
  color: #c8b898;
}

.name-prompt-input {
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  color: #e8dcc8;
  background: #1a1428;
  border: 1px solid #4a3a58;
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
}

.name-prompt-input:focus {
  outline: none;
  border-color: #d4b850;
}

.name-prompt-actions {
  display: flex;
  gap: 0.5rem;
}

@keyframes loading-slide {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(320%);
  }
}

@keyframes loading-pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #120e18;
}

.hint {
  text-align: center;
  margin-top: 0.85rem;
  font-size: 0.85rem;
  opacity: 0.65;
}

.hint--touch {
  display: none;
}

.touch-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.35rem 0.25rem max(0.35rem, env(safe-area-inset-bottom));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-controls-move,
.touch-controls-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.touch-btn {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  font: inherit;
  font-size: 1.65rem;
  line-height: 1;
  color: #f0e6c8;
  background: #2a2238;
  border: 1px solid #4a3a58;
  border-radius: 50%;
  width: 4.5rem;
  height: 4.5rem;
  padding: 0;
  cursor: pointer;
}

.touch-btn--jump {
  width: 5.5rem;
  height: 5.5rem;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-color: rgba(212, 184, 80, 0.45);
}

.touch-btn--small {
  width: auto;
  min-width: 4rem;
  height: 3rem;
  padding: 0 1rem;
  border-radius: 999px;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.touch-btn--copy[hidden] {
  display: none;
}

.touch-btn:active {
  background: #5a4830;
  border-color: #d4b850;
}

@media (pointer: coarse), (max-width: 720px) {
  .app {
    padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right))
      max(1rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  }

  .header {
    position: relative;
  }

  .header-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "center center"
      "nav actions";
    gap: 0.45rem 0.5rem;
    align-items: center;
  }

  .header-center {
    grid-area: center;
    order: unset;
  }

  .header-center h1 {
    font-size: 1.45rem;
    letter-spacing: 0.06em;
  }

  .header-meta {
    flex-flow: row wrap;
    justify-content: center;
    column-gap: 0.55rem;
    row-gap: 0.15rem;
    margin-top: 0.2rem;
  }

  .header-meta p {
    font-size: 0.68rem;
    opacity: 0.72;
  }

  .header-meta .stats-line {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    max-width: 42%;
    line-height: 1.2;
    text-align: left;
  }

  .header-meta .countdown--ready {
    font-size: 0.68rem;
  }

  .header-nav {
    grid-area: nav;
    justify-content: flex-start;
    flex-wrap: nowrap;
  }

  .header-actions {
    grid-area: actions;
    justify-content: flex-end;
    flex-wrap: nowrap;
  }

  #board-open {
    font-size: 0.72rem;
    padding: 0.45rem 0.55rem;
    letter-spacing: 0.02em;
  }

  .header-btn {
    min-height: 2.75rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
  }

  .header-btn--icon {
    width: 2.5rem;
    height: 2.5rem;
    min-height: 2.5rem;
    padding: 0;
  }

  .archive-close,
  .calendar-nav {
    width: 2.75rem;
    height: 2.75rem;
  }

  .canvas-wrap {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    aspect-ratio: 1;
    max-height: min(100vw - 2rem, calc(100dvh - 14.5rem));
  }

  canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    touch-action: none;
  }

  .touch-controls {
    display: flex;
  }

  .hint--desktop {
    display: none;
  }

  .hint--touch {
    display: block;
  }

  .board-name-row {
    flex-direction: column;
    align-items: stretch;
  }

  .board-name-row .header-btn {
    width: 100%;
  }
}

.archive-dialog {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.archive-dialog[hidden] {
  display: none;
}

.archive-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 4, 8, 0.72);
}

.archive-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  padding: 0.85rem;
  border: 1px solid #3a3048;
  border-radius: 8px;
  background: #120e18;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}

.archive-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.archive-panel-head h2 {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c8b898;
  font-weight: normal;
}

.archive-close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  color: #e8dcc8;
  background: #2a2238;
  border: 1px solid #4a3a58;
  border-radius: 4px;
  cursor: pointer;
}

.archive-close:hover {
  background: #3a3048;
}

.calendar {
  padding: 0;
}

.calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.calendar-title {
  flex: 1;
  text-align: center;
  font-size: 0.95rem;
  color: #f0e6c8;
}

.calendar-nav,
.calendar-today {
  font: inherit;
  color: #e8dcc8;
  background: #2a2238;
  border: 1px solid #4a3a58;
  border-radius: 4px;
  cursor: pointer;
}

.calendar-nav {
  width: 2rem;
  height: 2rem;
  padding: 0;
  line-height: 1;
}

.calendar-nav:disabled,
.calendar-today:disabled {
  opacity: 0.35;
  cursor: default;
}

.calendar-nav:not(:disabled):hover,
.calendar-today:not(:disabled):hover {
  background: #3a3048;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
}

.calendar-weekdays {
  margin-bottom: 0.35rem;
  font-size: 0.7rem;
  text-align: center;
  opacity: 0.55;
}

.calendar-pad {
  aspect-ratio: 1;
}

.calendar-day {
  aspect-ratio: 1;
  padding: 0;
  font: inherit;
  font-size: 0.82rem;
  color: #6a6078;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: default;
}

.calendar-day--playable {
  color: #e8dcc8;
  cursor: pointer;
}

.calendar-day--playable:hover {
  background: rgba(255, 255, 255, 0.06);
}

.calendar-day--selected {
  background: #5a4830;
  border-color: #d4b850;
  color: #fff8e8;
}

.calendar-day--today:not(.calendar-day--selected) {
  border-color: #6a5840;
}

.calendar-day--cleared .calendar-day-num {
  box-shadow: inset 0 -2px 0 #7cb87c;
}

.calendar-day--late .calendar-day-num {
  border-bottom: 2px dashed #6a8068;
}

.calendar-day--first {
  position: relative;
  overflow: hidden;
}

.calendar-day--first .calendar-day-num {
  box-shadow: inset 0 -2px 0 #d4b850;
  border-bottom: none;
  color: #f0e6a0;
}

.calendar-day-trophy {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 0.7rem;
  height: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  line-height: 1;
  overflow: hidden;
  pointer-events: none;
}

.calendar-day--missed:not(.calendar-day--cleared):not(.calendar-day--late) {
  opacity: 0.42;
}

.calendar-stats {
  margin: 0.75rem 0 0;
  font-size: 0.78rem;
  color: #c8b8a0;
  text-align: center;
}

.calendar-legend {
  margin: 0.35rem 0 0;
  font-size: 0.7rem;
  color: #6a6078;
  text-align: center;
}

.calendar-foot {
  display: flex;
  justify-content: center;
  margin-top: 0.65rem;
}

.calendar-today {
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
}

.board-panel {
  width: min(100%, 400px);
}

.board-date {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  color: #f0e6c8;
}

.board-status {
  margin: 0 0 0.65rem;
  font-size: 0.75rem;
  opacity: 0.65;
}

.board-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid #2a2238;
  border-radius: 4px;
}

.board-empty {
  padding: 0.85rem;
  font-size: 0.8rem;
  opacity: 0.55;
  text-align: center;
}

.board-row {
  display: grid;
  grid-template-columns: 2.4rem 4.5rem 1fr;
  gap: 0.4rem;
  align-items: center;
  padding: 0.4rem 0.55rem;
  font-size: 0.78rem;
  border-bottom: 1px solid rgba(74, 58, 88, 0.45);
}

.board-row:last-child {
  border-bottom: none;
}

.board-row--you {
  background: rgba(90, 72, 48, 0.45);
}

.board-rank {
  color: #d4b850;
}

.board-time {
  font-variant-numeric: tabular-nums;
}

.board-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-you {
  margin: 0.65rem 0 0;
  font-size: 0.78rem;
  color: #c8b898;
}

.board-name-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.board-name-label {
  font-size: 0.75rem;
  opacity: 0.7;
}

.board-name-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.8rem;
  color: #e8dcc8;
  background: #1a1428;
  border: 1px solid #4a3a58;
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
}

.board-name-input:focus {
  outline: 1px solid #d4b850;
  outline-offset: 1px;
}

.board-foot {
  display: flex;
  justify-content: center;
  margin-top: 0.65rem;
}

