:root {
  color-scheme: light;
  --ink: #1c2430;
  --muted: #617080;
  --paper: #fffdf8;
  --panel: #ffffff;
  --line: #d6dee6;
  --sky: #dff5ff;
  --mint: #00a88f;
  --coral: #f9735b;
  --sun: #ffcf3f;
  --berry: #6d5dfc;
  --shadow: 0 18px 45px rgba(28, 36, 48, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(223, 245, 255, 0.82), rgba(255, 253, 248, 0.95) 46%),
    var(--paper);
  color: var(--ink);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border-radius: 8px;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(109, 93, 252, 0.35);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.masthead {
  position: relative;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding-right: 56px;
}

.masthead h1,
.section-heading h2 {
  margin: 0;
  line-height: 1.05;
}

.masthead h1 {
  max-width: 780px;
  font-size: 2.4rem;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--coral);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.reader-switcher {
  display: grid;
  gap: 6px;
  min-width: 190px;
}

.reader-switcher label,
label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

select,
input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

.dashboard-grid {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(28, 36, 48, 0.1);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.log-panel {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 248px;
  overflow: hidden;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(223, 245, 255, 0.44), rgba(255, 253, 248, 0.86)),
    var(--panel);
}

.log-panel::after {
  content: "";
  position: absolute;
  inset: auto 18px 14px auto;
  width: min(34%, 300px);
  height: 42%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 207, 63, 0.22), rgba(249, 115, 91, 0));
  pointer-events: none;
  z-index: -1;
}

.log-panel > * {
  position: relative;
  z-index: 1;
}

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

.section-heading h2 {
  font-size: 1.35rem;
}

.section-copy {
  max-width: 520px;
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.4;
}

.reader-avatar,
.friend-avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--active-color, var(--mint));
  color: #fff;
  font-size: 1.5rem;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(96px, 150px) minmax(190px, 230px) 1fr;
  gap: 14px;
}

.form-grid label:first-child {
  grid-column: 1 / -1;
}

.form-grid label,
.inline-form label {
  display: grid;
  gap: 7px;
}

.minutes-stepper {
  display: grid;
  grid-template-columns: 44px minmax(74px, 1fr) 44px;
  gap: 6px;
  align-items: center;
}

.minutes-stepper input {
  text-align: center;
  font-weight: 850;
}

.stepper-button {
  display: grid;
  place-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 900;
  box-shadow: inset 0 -2px 0 rgba(28, 36, 48, 0.08);
}

.stepper-button:hover {
  background: var(--sky);
  transform: translateY(-1px);
}

.stepper-button:active {
  transform: translateY(0);
}

.primary-button,
.inline-form button {
  min-height: 46px;
  background: var(--ink);
  color: #fff;
  font-weight: 850;
  padding: 0 18px;
  box-shadow: inset 0 -3px 0 rgba(255, 255, 255, 0.16);
}

.primary-button:hover,
.inline-form button:hover {
  transform: translateY(-1px);
}

.admin-button {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(28, 36, 48, 0.16);
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  box-shadow: 0 8px 20px rgba(28, 36, 48, 0.08);
}

.admin-button:hover {
  transform: translateY(-1px) rotate(12deg);
}

.form-status {
  min-height: 22px;
  margin: -4px 0 0;
  color: var(--mint);
  font-weight: 800;
}

.quilt-panel {
  margin-top: 18px;
  padding: 22px;
}

.quilt-heading {
  align-items: start;
}

.quilt-score {
  display: grid;
  min-width: 150px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: right;
}

.quilt-score strong {
  font-size: 1.45rem;
  line-height: 1;
}

.quilt-score span {
  color: var(--muted);
  font-weight: 800;
}

.quilt-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 260px;
  gap: 20px;
  align-items: stretch;
  margin-top: 18px;
}

.quilt-frame {
  position: relative;
  min-height: 440px;
  overflow: hidden;
  border: 1px solid rgba(28, 36, 48, 0.15);
  border-radius: 8px;
  background: #fffaf0;
}

.quilt-board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  width: 100%;
  height: 100%;
  min-height: 440px;
  background: #fffaf0;
}

.quilt-tile {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 44px;
  padding: 3px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.78);
  background: #fff7ec;
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 2px rgba(28, 36, 48, 0.45);
  transition:
    opacity 520ms ease,
    transform 520ms ease;
}

.quilt-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.62), rgba(255, 246, 224, 0.88)),
    #fff7ec;
}

.quilt-tile.is-filled::before {
  background-image:
    linear-gradient(to top, color-mix(in srgb, var(--tile-color, #00a88f) 24%, transparent) var(--tile-fill, 0%), rgba(255, 251, 241, 0.48) var(--tile-fill, 0%)),
    var(--tile-image);
  background-position:
    center,
    var(--tile-bg-x) var(--tile-bg-y);
  background-size:
    auto,
    1000% 1000%;
}

.quilt-tile.is-new {
  z-index: 2;
  animation: patchPop 1.6s ease both;
}

.quilt-tile:not(.is-filled) {
  text-shadow: none;
}

.quilt-tile span,
.quilt-tile small {
  position: relative;
  z-index: 1;
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quilt-tile span {
  font-size: clamp(0.54rem, 1vw, 0.74rem);
  font-weight: 900;
}

.quilt-tile small {
  font-size: clamp(0.48rem, 0.8vw, 0.64rem);
  font-weight: 850;
}

.quilt-board.is-complete .quilt-tile {
  transform: scale(1);
}

.quilt-board.is-complete {
  animation: revealGlow 1.2s ease both;
}

.quilt-board.is-complete .quilt-tile.is-filled::before {
  background-image: var(--tile-image);
  background-position: var(--tile-bg-x) var(--tile-bg-y);
  background-size: 1000% 1000%;
}

.quilt-board.is-previewing .quilt-tile.is-filled::before {
  background-image: var(--tile-image);
  background-position: var(--tile-bg-x) var(--tile-bg-y);
  background-size: 1000% 1000%;
}

.quilt-board.is-complete .quilt-tile span,
.quilt-board.is-complete .quilt-tile small,
.quilt-board.is-previewing .quilt-tile span,
.quilt-board.is-previewing .quilt-tile small {
  opacity: 0;
}

.quilt-ribbon {
  position: absolute;
  right: 16px;
  bottom: 16px;
  padding: 10px 13px;
  border-radius: 8px;
  background: rgba(28, 36, 48, 0.9);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 14px 30px rgba(28, 36, 48, 0.22);
}

.quilt-ribbon[hidden] {
  display: none;
}

.quilt-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 0;
}

.quilt-side strong {
  display: block;
  margin-top: 5px;
  font-size: 1.2rem;
}

.quilt-side p {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.45;
}

@keyframes revealGlow {
  0% {
    box-shadow: inset 0 0 0 0 rgba(255, 207, 63, 0);
  }

  60% {
    box-shadow: inset 0 0 0 12px rgba(255, 207, 63, 0.52);
  }

  100% {
    box-shadow: inset 0 0 0 0 rgba(255, 207, 63, 0);
  }
}

@keyframes patchPop {
  0% {
    transform: scale(0.58) rotate(-5deg);
    box-shadow: 0 0 0 0 rgba(255, 207, 63, 0);
  }

  28% {
    transform: scale(1.16) rotate(2deg);
    box-shadow: 0 0 0 5px rgba(255, 207, 63, 0.55);
  }

  100% {
    transform: scale(1) rotate(0deg);
    box-shadow: 0 0 0 0 rgba(255, 207, 63, 0);
  }
}

.stat-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0;
}

.content-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.95fr;
  gap: 18px;
  align-items: start;
}

.content-grid > .panel {
  padding: 22px;
}

.friends-panel {
  grid-column: 1 / -1;
}

.log-history {
  grid-column: 1 / -1;
}

.friend-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.friend-card {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.friend-card.is-active {
  border-color: var(--active-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--active-color) 18%, transparent);
}

.friend-card-top {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.friend-card h3,
.friend-card p {
  margin: 0;
}

.friend-card h3 {
  font-size: 1rem;
}

.friend-card p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.87rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.friend-card strong {
  font-size: 1rem;
  white-space: nowrap;
}

.mini-meter {
  height: 12px;
  margin-top: 13px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef3f6;
}

.mini-meter span {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--active-color, var(--mint));
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 18px;
}

.field-block {
  display: grid;
  gap: 7px;
  margin-top: 18px;
}

.ghost-button {
  width: 100%;
  min-height: 42px;
  margin-top: 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.ghost-button:hover {
  border-color: var(--coral);
  color: var(--coral);
}

.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
}

.admin-modal[hidden] {
  display: none;
}

.admin-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 36, 48, 0.46);
}

.admin-dialog {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(28, 36, 48, 0.28);
}

.admin-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.admin-header h2,
.admin-section h3 {
  margin: 0;
}

.admin-header h2 {
  font-size: 1.35rem;
  line-height: 1.1;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: #fff8f7;
  color: var(--coral);
  font-size: 1.2rem;
  font-weight: 900;
}

.admin-section {
  display: grid;
  gap: 10px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.admin-section p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.4;
}

.admin-section label {
  display: grid;
  gap: 7px;
}

.admin-section input[type="file"] {
  min-height: auto;
  padding: 11px;
}

.danger-button {
  min-height: 44px;
  border: 1px solid rgba(249, 115, 91, 0.36);
  background: #fff1ef;
  color: #b93d2e;
  font-weight: 850;
  padding: 0 16px;
}

.danger-button:hover {
  background: #ffe6e2;
}

.admin-status {
  min-height: 22px;
  margin: 0;
  color: var(--mint);
  font-weight: 850;
}

.quilt-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  width: min(460px, calc(100% - 32px));
  transform: translateX(-50%);
  padding: 14px 16px;
  border: 1px solid rgba(0, 168, 143, 0.34);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  font-weight: 900;
  text-align: center;
  box-shadow: 0 18px 50px rgba(28, 36, 48, 0.18);
  animation: toastIn 260ms ease both;
}

.quilt-toast[hidden] {
  display: none;
}

.quilt-toast.is-milestone {
  border-color: rgba(255, 207, 63, 0.74);
  background: #fff8d7;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.history-list {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-list strong,
.history-list span {
  display: block;
  overflow-wrap: anywhere;
}

.history-list span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.delete-log {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  background: #fff8f7;
  color: var(--coral);
  font-size: 1.05rem;
  font-weight: 900;
}

.empty-state {
  margin-top: 18px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.confetti-piece {
  position: fixed;
  top: -12px;
  z-index: 10;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  background: var(--confetti-color);
  pointer-events: none;
  animation: fall 850ms ease-in forwards;
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(260deg);
    opacity: 0.2;
  }
}

@media (max-width: 850px) {
  .app-shell {
    width: min(100% - 22px, 680px);
    padding-top: 18px;
  }

  .masthead,
  .content-grid,
  .quilt-layout {
    grid-template-columns: 1fr;
  }

  .masthead {
    display: grid;
    align-items: start;
  }

  .masthead h1 {
    font-size: 2rem;
  }

  .log-panel {
    min-height: 0;
    padding: 18px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.9)),
      var(--panel);
  }

  .quilt-frame,
  .quilt-board {
    min-height: 360px;
  }
}

@media (max-width: 520px) {
  .form-grid,
  .inline-form,
  .friend-card-top,
  .history-list li {
    grid-template-columns: 1fr;
  }

  .friend-card strong {
    justify-self: start;
  }

  .section-heading {
    align-items: start;
  }

  .quilt-panel {
    padding: 16px;
  }

  .quilt-score {
    width: 100%;
    text-align: left;
  }

  .quilt-frame,
  .quilt-board {
    min-height: 310px;
  }

  .quilt-tile {
    min-height: 31px;
  }

  .quilt-tile span {
    font-size: 0.5rem;
  }

  .quilt-tile small {
    display: none;
  }
}
