:root {
  --table: #262b63;
  --tray: #353b88;
  --tray-hi: #444ba6;
  --sun: #ffd23f;
  --line: #2b2d42;
  --press: 0 4px 0 rgba(10, 12, 44, 0.5);
  --btn: 58px;
  --gap: 10px;
  --ink: #ff5a5f;
  font-family: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Varela Round', system-ui, sans-serif;
  color: #fff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--table);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

body {
  position: fixed;
  inset: 0;
}

#app {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  height: 100%;
  width: 100%;
}

/* Buttons */

.btn {
  position: relative;
  flex: none;
  width: var(--btn);
  height: var(--btn);
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--tray);
  color: #fff;
  box-shadow: var(--press);
  cursor: pointer;
  overflow: hidden;
  font: inherit;
  transition: transform 80ms, box-shadow 80ms, background 120ms;
}

.btn svg {
  width: 62%;
  height: 62%;
  pointer-events: none;
}

.btn:active,
.btn.holding {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(10, 12, 44, 0.5);
}

.btn.on {
  background: var(--sun);
  color: var(--line);
}

.btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.btn:focus-visible,
.swatch:focus-visible,
.tile:focus-visible,
.card:focus-visible {
  outline: 4px solid var(--sun);
  outline-offset: 3px;
}

.btn .ring {
  position: absolute;
  inset: 0;
  background: rgba(255, 90, 95, 0.75);
  transform: scaleY(0);
  transform-origin: bottom;
  pointer-events: none;
}

.btn.holding .ring {
  transform: scaleY(1);
  transition: transform var(--hold, 900ms) linear;
}

.btn svg {
  position: relative;
  z-index: 1;
}

.row {
  display: flex;
  gap: var(--gap);
  align-items: center;
}

.spacer {
  flex: 1;
}

/* Home */

.home {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 18px 16px 28px;
  touch-action: pan-y;
}

.home header {
  width: min(1000px, 100%);
  display: flex;
  align-items: center;
  gap: 12px;
}

.title {
  position: relative;
  margin: 4px 0 6px;
  font-size: clamp(44px, 9vw, 76px);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1;
}

.title svg {
  position: absolute;
  left: -2%;
  bottom: -0.32em;
  width: 104%;
  height: 0.5em;
  overflow: visible;
}

.title path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: scribble 1.4s 0.2s cubic-bezier(0.45, 0, 0.25, 1) forwards;
}

@keyframes scribble {
  to {
    stroke-dashoffset: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .title path {
    animation: none;
    stroke-dashoffset: 0;
  }
}

.tiles {
  width: min(1000px, 100%);
  margin: 26px 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 22px;
}

.tile {
  border: 0;
  padding: 10px;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 6px 0 rgba(10, 12, 44, 0.45);
  display: grid;
  place-items: center;
  cursor: pointer;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 120ms;
}

.tile:active {
  transform: rotate(0deg) scale(0.96);
}

.tile svg {
  width: 88%;
  height: 88%;
}

.tile:nth-child(3n + 1) {
  --tilt: -2deg;
}

.tile:nth-child(3n + 2) {
  --tilt: 1.5deg;
}

.tile:nth-child(3n) {
  --tilt: -0.8deg;
}

/* Hub (piano choices) */

.hub {
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 18px;
}

.hub .tiles {
  align-self: center;
  margin: auto 0;
  width: min(820px, 100%);
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(14px, 3vw, 34px);
}

/* Picker and gallery */

.picker,
.gallery {
  display: flex;
  flex-direction: column;
  padding: 14px 14px 0;
  gap: 14px;
}

.themes {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 4px 10px;
  touch-action: pan-x;
  scrollbar-width: none;
  /* Shrinks to the row's width so it scrolls once there are more themes than fit across. */
  flex: 1 1 0;
  min-width: 0;
}

.themes::-webkit-scrollbar,
.palette::-webkit-scrollbar,
.toolbar::-webkit-scrollbar,
.topbar::-webkit-scrollbar {
  display: none;
}

.theme {
  flex: none;
  width: 76px;
  height: 76px;
  padding: 6px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 0 rgba(10, 12, 44, 0.45);
  cursor: pointer;
}

.theme img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  pointer-events: none;
}

.theme.on {
  outline: 5px solid var(--sun);
}

.grid {
  flex: 1;
  overflow-y: auto;
  touch-action: pan-y;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 18px;
  padding: 4px 4px 28px;
  align-content: start;
}

.card {
  position: relative;
  border: 0;
  padding: 8px;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 5px 0 rgba(10, 12, 44, 0.45);
  cursor: pointer;
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.card.simple::after {
  content: '';
  position: absolute;
  right: 8px;
  top: 8px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #3cc47c;
}

.empty {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  padding: 50px 0;
  opacity: 0.9;
  font-size: 22px;
}

/* Viewer */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(16, 18, 52, 0.92);
  display: grid;
  grid-template-rows: auto 1fr;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  gap: 14px;
}

.viewer img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  min-height: 0;
}

/* Editor */

.editor {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    'top top'
    'tools stage'
    'palette palette';
  gap: var(--gap);
  padding: var(--gap);
}

.topbar {
  grid-area: top;
  display: flex;
  gap: var(--gap);
  align-items: center;
  overflow-x: auto;
  padding-bottom: 5px;
  touch-action: pan-x;
  scrollbar-width: none;
}

.modebar {
  display: flex;
  gap: var(--gap);
  align-items: center;
  margin: 0 auto;
  padding: 0 6px;
}

.modebar .btn {
  --btn: 52px;
}

.toolbar {
  grid-area: tools;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  overflow-y: auto;
  padding: 2px 6px 6px 2px;
  scrollbar-width: none;
}

.tool {
  background: var(--tray);
}

.tool.on {
  background: var(--tray-hi);
  outline: 4px solid var(--sun);
  outline-offset: -4px;
  transform: translateX(6px);
}

.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  touch-action: none;
  min-width: 0;
  min-height: 0;
}

.page {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
  will-change: transform;
}

.page.round {
  border-radius: 50%;
  overflow: hidden;
}

.page canvas,
.page .overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

.page .overlay {
  pointer-events: none;
  overflow: visible;
}

.paletterow {
  grid-area: palette;
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
}

.sizes {
  display: flex;
  gap: 6px;
  flex: none;
}

.size {
  --btn: 50px;
  background: var(--tray);
}

.size i {
  display: block;
  border-radius: 50%;
  background: var(--ink-css, var(--ink));
}

.size.on {
  background: var(--tray-hi);
  outline: 4px solid var(--sun);
  outline-offset: -4px;
}

/* Colours wrap into as many rows as they need, so every one is in reach without scrolling. */
.palette {
  --sw: 44px;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--sw));
  grid-auto-rows: var(--sw);
  gap: 6px;
  padding: 10px 6px 8px;
  min-width: 0;
}

.swatch {
  flex: none;
  width: var(--sw, 44px);
  height: var(--sw, 44px);
  border-radius: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16), 0 3px 0 rgba(10, 12, 44, 0.45);
  transition: transform 100ms;
}

.swatch.rainbow {
  background: conic-gradient(#ff5a5f, #ffb627, #ffe14d, #3cc47c, #2ec4d6, #4d8dff, #b15cff, #ff5a5f);
}

.swatch.on {
  transform: translateY(-4px) scale(1.12);
  box-shadow: 0 0 0 4px var(--sun), 0 6px 0 rgba(10, 12, 44, 0.45);
}

/* Piano */

.piano {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    'top top'
    'tools stage'
    'keys keys';
  gap: var(--gap);
  padding: var(--gap);
}

.piano .stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 6px;
}

.keys {
  grid-area: keys;
  display: flex;
  gap: 6px;
  height: clamp(110px, 24vh, 200px);
  touch-action: none;
}

.key {
  flex: 1;
  position: relative;
  border: 0;
  border-radius: 6px 6px 16px 16px;
  background: #fff;
  box-shadow: 0 6px 0 rgba(10, 12, 44, 0.5);
  overflow: hidden;
  transition: transform 60ms;
}

.key i {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 10px;
  height: 22%;
  border-radius: 12px;
  background: var(--key);
}

.key.down {
  transform: translateY(5px);
  box-shadow: 0 1px 0 rgba(10, 12, 44, 0.5);
  background: var(--key);
}

.key.down i {
  background: #fff;
  opacity: 0.4;
}

.key.glow {
  animation: glow 0.9s ease-in-out infinite alternate;
}

@keyframes glow {
  from {
    box-shadow: 0 6px 0 rgba(10, 12, 44, 0.5), 0 0 0 0 var(--sun);
  }
  to {
    box-shadow: 0 6px 0 rgba(10, 12, 44, 0.5), 0 0 0 7px var(--sun);
  }
}

/* Tunes */

.piano.tunes {
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    'top'
    'stage'
    'keys';
}

.tunes .picture {
  grid-area: stage;
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.tuneframe {
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 0 rgba(10, 12, 44, 0.45);
}

.tuneframe canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.tuneframe .pulse {
  animation: pulse 1.1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from {
    opacity: 0.12;
  }
  to {
    opacity: 0.6;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tuneframe .pulse {
    animation: none;
    opacity: 0.4;
  }
}

.tunegrid .tunecard {
  aspect-ratio: auto;
  display: grid;
  gap: 6px;
  justify-items: center;
  color: var(--line);
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 12px 8px 14px;
}

.tunepic svg {
  width: 100%;
  height: auto;
  display: block;
}

/* Home tile labels */

.tilebox {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.tilebox .tile {
  width: 100%;
}

.tilelabel {
  font-size: 19px;
  font-weight: 700;
}

.btn.resume svg {
  width: 80%;
  height: 80%;
}

/* Settings sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(16, 18, 52, 0.85);
  display: grid;
  place-items: center;
  padding: 20px;
}

.sheet .panel {
  width: min(460px, 100%);
  background: var(--tray);
  border-radius: 22px;
  padding: 22px;
  display: grid;
  gap: 18px;
  font-size: 19px;
  box-shadow: 0 8px 0 rgba(10, 12, 44, 0.5);
}

.sheet h2 {
  margin: 0;
  font-size: 24px;
}

.sheet label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.sheet input[type='range'] {
  width: 55%;
  accent-color: var(--sun);
}

.sheet input[type='checkbox'] {
  width: 28px;
  height: 28px;
  accent-color: var(--sun);
}

.sheet select {
  font: inherit;
  font-size: 17px;
  border-radius: 10px;
  padding: 6px 8px;
}

.sheet .note {
  font-size: 15px;
  opacity: 0.8;
  margin: 0;
}

.pill {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  background: var(--sun);
  color: var(--line);
  box-shadow: var(--press);
  position: relative;
  overflow: hidden;
}

.pill.danger {
  background: #ff8a8d;
}

.pill .ring {
  position: absolute;
  inset: 0;
  background: rgba(200, 30, 40, 0.5);
  transform: scaleX(0);
  transform-origin: left;
}

.pill.holding .ring {
  transform: scaleX(1);
  transition: transform var(--hold, 900ms) linear;
}

/* Sparkle when a picture is finished or saved */

.burst {
  position: absolute;
  pointer-events: none;
  inset: 0;
  overflow: hidden;
}

.burst i {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  animation: pop 1.1s ease-out forwards;
}

@keyframes pop {
  from {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }
  to {
    transform: translate(var(--dx), var(--dy)) rotate(260deg) scale(0.3);
    opacity: 0;
  }
}

/* Narrow and portrait screens */

@media (orientation: portrait) {
  .editor {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      'top'
      'stage'
      'tools'
      'palette';
  }

  .piano {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      'top'
      'stage'
      'tools'
      'keys';
  }

  .toolbar {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 2px 8px;
    touch-action: pan-x;
  }

  .tool.on {
    transform: translateY(-5px);
  }
}

@media (max-width: 600px), (max-height: 520px) {
  :root {
    --btn: 48px;
    --gap: 8px;
  }

  .btn {
    border-radius: 14px;
  }

  .modebar .btn,
  .size {
    --btn: 44px;
  }

  .swatch {
    width: 40px;
    height: 40px;
  }

  .keys {
    height: clamp(90px, 22vh, 160px);
  }
}

/* Phones: mode controls drop to their own row, and the palette folds into two rows */

.topbar .push {
  margin-left: auto;
}

@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 8px;
    overflow: visible;
  }

  .topbar .modebar {
    order: 10;
    flex: 1 1 100%;
    justify-content: center;
    margin: 0;
  }

  .modebar:empty {
    display: none;
  }
}

@media (orientation: portrait) and (max-width: 600px) {
  .paletterow {
    gap: 8px;
  }

  .sizes {
    display: grid;
    grid-template-columns: repeat(2, 34px);
    gap: 6px;
  }

  .size {
    --btn: 34px;
    border-radius: 10px;
  }

  .size i {
    max-width: 22px;
    max-height: 22px;
  }

  .palette {
    --sw: 31px;
    gap: 5px;
    padding: 8px 4px;
  }
}

/* Phones on their side: the palette moves to a column on the right so the page keeps its height */

@media (orientation: landscape) and (max-height: 520px) {
  .editor {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      'top top top'
      'tools stage palette';
  }

  .tool,
  .piano .tool {
    --btn: 40px;
  }

  .toolbar {
    gap: 6px;
  }

  .paletterow {
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    gap: 8px;
  }

  .sizes {
    display: grid;
    grid-template-columns: repeat(2, 36px);
    gap: 6px;
  }

  .size {
    --btn: 36px;
    border-radius: 10px;
  }

  .size i {
    max-width: 24px;
    max-height: 24px;
  }

  .palette {
    --sw: 36px;
    flex: 1;
    grid-template-columns: repeat(2, var(--sw));
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: pan-y;
    padding: 6px 4px;
  }

  .swatch.on {
    transform: scale(1.1);
  }
}

/* Mixing tray */

.mixswatch {
  display: grid;
  place-items: center;
  background: #f3e3c3;
  color: var(--line);
}

.mixswatch svg {
  width: 82%;
  height: 82%;
}

.sheet.mixer {
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
}

.sheet.mixer .panel {
  width: min(760px, 100%);
  max-height: 100%;
  overflow-y: auto;
  gap: 14px;
  padding: 16px;
}

.traybox {
  display: grid;
  place-items: center;
  min-width: 0;
}

canvas.tray {
  display: block;
  border-radius: 28px;
  background: #fbf8f1;
  box-shadow: 0 6px 0 rgba(10, 12, 44, 0.45);
  touch-action: none;
}

.pots {
  display: grid;
  grid-template-columns: repeat(auto-fill, 44px);
  gap: 8px;
  justify-content: center;
}

.pot {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 0 rgba(10, 12, 44, 0.45);
  cursor: pointer;
}

.pot i {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: var(--pot);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.pot.on {
  outline: 4px solid var(--sun);
  outline-offset: 2px;
}

.usebar {
  justify-content: center;
  gap: 16px;
}

.chosen {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  box-shadow: 0 0 0 4px #fff, 0 6px 0 rgba(10, 12, 44, 0.45);
}

.chosen.empty {
  background: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.18) 0 6px, transparent 6px 12px) !important;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.4);
}

.btn.use {
  --btn: 60px;
  background: var(--sun);
  color: var(--line);
}
