:root {
  color-scheme: light;
  --paper: #f7f1df;
  --paper-deep: #eadfca;
  --ink: #2d2a36;
  --muted: #716c74;
  --berry: #bd3f75;
  --berry-dark: #a93f72;
  --mint: #60cfad;
  --yellow: #f3d95c;
  --line: rgba(45, 42, 54, 0.16);
  --shadow: 0 16px 44px rgba(67, 46, 55, 0.16);
  font-family: "Avenir Next Rounded", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--paper);
  overscroll-behavior: none;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.85), transparent 28rem),
    linear-gradient(160deg, #fbf6e9 0%, var(--paper) 58%, #eee2cb 100%);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
canvas:focus-visible {
  outline: 4px solid rgba(91, 114, 232, 0.48);
  outline-offset: 3px;
}

#app {
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(10px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  min-height: 44px;
  border: 0;
  padding: 3px 4px 3px 0;
  display: flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  font-size: 15px;
  font-weight: 850;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 35px;
  height: 35px;
  border: 2px solid var(--ink);
  border-radius: 50% 43% 48% 43%;
  display: grid;
  place-items: center;
  transform: rotate(-7deg);
  background: var(--yellow);
  box-shadow: 2px 3px 0 var(--ink);
  font-size: 20px;
  font-weight: 950;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.icon-button {
  min-width: 56px;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 5px 8px;
  display: grid;
  justify-items: center;
  gap: 0;
  background: transparent;
  font-size: 17px;
}

.icon-button:active {
  background: rgba(45, 42, 54, 0.08);
}

.button-label {
  font-size: 11px;
  font-weight: 750;
}

.challenge-banner {
  min-height: 48px;
  border: 2px solid var(--ink);
  border-radius: 15px;
  padding: 7px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #c8f3e4;
  box-shadow: 2px 3px 0 var(--ink);
  font-size: 13px;
}

.challenge-banner:not([hidden]) {
  display: flex;
}

.challenge-banner strong {
  flex: 0 0 auto;
  font-size: 17px;
}

.game-shell {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
}

#gameCanvas {
  width: min(100%, 390px);
  height: auto;
  max-height: calc(100dvh - 230px);
  border: 2px solid var(--ink);
  border-radius: 27px;
  display: block;
  background: #efe9d7;
  box-shadow:
    4px 6px 0 var(--ink),
    0 20px 50px rgba(67, 46, 55, 0.15);
  cursor: pointer;
}

.controls {
  flex: 0 0 auto;
  min-height: 76px;
  display: grid;
  align-items: center;
}

.action-button {
  width: 100%;
  min-height: 70px;
  border: 2px solid var(--ink);
  border-radius: 22px;
  padding: 10px 18px 11px;
  display: grid;
  place-items: center;
  background: var(--berry);
  color: #fffaf0;
  box-shadow: 3px 5px 0 var(--ink);
  text-shadow: 0 1px 0 rgba(45, 42, 54, 0.22);
  transition: transform 90ms ease, box-shadow 90ms ease, background 140ms ease;
}

.action-button:hover {
  background: #cb4d83;
}

.action-button:active,
.pill-button:active,
.wide-button:active {
  transform: translate(2px, 3px);
  box-shadow: 1px 2px 0 var(--ink);
}

.action-button span {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  opacity: 0.85;
}

.action-button strong {
  font-size: 22px;
  letter-spacing: -0.025em;
}

.secondary-actions {
  grid-template-columns: 1.15fr 1fr;
  gap: 7px;
}

.secondary-actions:not([hidden]) {
  display: grid;
}

.pill-button {
  min-height: 52px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 7px 8px;
  background: #fffaf0;
  box-shadow: 2px 3px 0 var(--ink);
  font-size: 13px;
  font-weight: 850;
}

.pill-button.primary {
  background: var(--berry);
  color: white;
}

.footer-note {
  min-height: 24px;
  padding: 1px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.text-button {
  min-height: 34px;
  border: 0;
  padding: 5px 2px;
  background: transparent;
  color: var(--berry-dark);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  font-size: 12px;
  font-weight: 750;
}

.sheet {
  width: min(100% - 20px, 460px);
  max-height: min(88dvh, 780px);
  margin: auto auto max(8px, env(safe-area-inset-bottom));
  border: 2px solid var(--ink);
  border-radius: 28px 28px 18px 18px;
  padding: 18px;
  overflow: auto;
  background: #fffaf0;
  color: var(--ink);
  box-shadow: var(--shadow), 4px 5px 0 var(--ink);
  overscroll-behavior: contain;
  animation: sheet-in 180ms ease-out;
}

.sheet::backdrop {
  background: rgba(37, 31, 39, 0.58);
  backdrop-filter: blur(4px);
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
}

.sheet-header {
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sheet-header h1 {
  margin: 2px 0 0;
  font-size: 27px;
  line-height: 1;
  letter-spacing: -0.035em;
}

.eyebrow {
  color: var(--berry-dark);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.close-button {
  width: 44px;
  height: 44px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--paper);
  font-size: 28px;
  line-height: 1;
}

.shelf-summary {
  margin: 2px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.specimen-card {
  min-height: 156px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 8px;
  overflow: hidden;
  position: relative;
  display: grid;
  grid-template-rows: 96px auto;
  background: var(--card-color, #f3ddac);
  text-align: left;
  box-shadow: 2px 3px 0 var(--ink);
}

.specimen-card[aria-pressed="true"]::after {
  content: "Equipped";
  position: absolute;
  top: 7px;
  right: 7px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 3px 6px;
  background: #fffaf0;
  font-size: 9px;
  font-weight: 850;
}

.specimen-card.quarantine {
  border-style: dashed;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 8px,
    rgba(156, 48, 66, 0.08) 8px,
    rgba(156, 48, 66, 0.08) 16px
  );
}

.specimen-card img {
  width: 100%;
  height: 96px;
  object-fit: contain;
}

.specimen-card strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.specimen-card small {
  display: block;
  margin-top: 2px;
  color: rgba(45, 42, 54, 0.72);
  font-size: 10px;
}

.empty-state {
  min-height: 180px;
  margin: 0;
  border: 2px dashed rgba(45, 42, 54, 0.25);
  border-radius: 18px;
  padding: 54px 30px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.settings-form {
  display: grid;
  gap: 13px;
}

.settings-form > label:not(.toggle-row) {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
}

.settings-form input[type="text"],
.settings-form input:not([type]) {
  width: 100%;
}

#handleInput {
  min-height: 48px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 8px 12px;
  background: white;
  color: var(--ink);
  font-size: 17px;
  -webkit-user-select: text;
  user-select: text;
}

.settings-form small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.toggle-row {
  min-height: 55px;
  border-top: 1px solid var(--line);
  padding: 10px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.toggle-row strong {
  display: block;
  font-size: 14px;
}

.toggle-row input {
  width: 48px;
  height: 28px;
  accent-color: var(--berry);
}

.wide-button {
  width: 100%;
  min-height: 53px;
  border: 2px solid var(--ink);
  border-radius: 17px;
  padding: 10px 16px;
  background: var(--berry);
  color: white;
  box-shadow: 2px 3px 0 var(--ink);
  font-weight: 850;
}

.wide-button.secondary {
  margin-top: 9px;
  background: var(--paper);
  color: var(--ink);
}

.data-actions {
  margin-top: 15px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  justify-content: space-around;
  gap: 8px;
  flex-wrap: wrap;
}

.file-label {
  min-height: 44px;
  position: relative;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

.file-label input {
  width: 100%;
  height: 100%;
  inset: 0;
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.file-label:focus-within {
  outline: 4px solid rgba(91, 114, 232, 0.48);
  outline-offset: 2px;
}

.text-button.danger {
  color: #9c3042;
}

.share-preview {
  width: 100%;
  max-height: 36dvh;
  border: 2px solid var(--ink);
  border-radius: 19px;
  display: block;
  object-fit: contain;
  background: #eadfca;
  box-shadow: 2px 3px 0 var(--ink);
}

.privacy-callout {
  margin: 0 0 12px;
  border: 1px solid rgba(45, 42, 54, 0.22);
  border-radius: 14px;
  padding: 10px 12px;
  background: #eef9f4;
  color: #4f4951;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.share-copy {
  margin: 12px 4px;
  font-size: 14px;
  font-weight: 750;
  text-align: center;
}

.centered {
  width: 100%;
  margin-top: 6px;
  text-align: center;
}

.fine-print {
  margin: 8px 4px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

.data-actions .text-button,
.footer-note .text-button {
  min-height: 48px;
}

.compact-sheet {
  margin: auto;
}

.prose {
  font-size: 15px;
  line-height: 1.52;
}

.prose p:last-child {
  margin-bottom: 0;
}

.toast {
  max-width: calc(100% - 32px);
  min-height: 42px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 9px 16px;
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  box-shadow: 0 8px 24px rgba(30, 26, 33, 0.28);
  font-size: 13px;
  font-weight: 750;
  text-align: center;
}

.sr-only {
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  white-space: nowrap;
}

@media (max-height: 700px) {
  #app {
    gap: 5px;
  }

  #gameCanvas {
    max-height: calc(100dvh - 195px);
  }

  .action-button {
    min-height: 58px;
  }

  .action-button strong {
    font-size: 19px;
  }

  .controls {
    min-height: 62px;
  }

  .footer-note {
    min-height: 21px;
    font-size: 11px;
  }
}

@media (max-width: 355px) {
  .brand > span:last-child {
    display: none;
  }

  .secondary-actions {
    grid-template-columns: 1fr 1fr;
  }

  .pill-button {
    font-size: 11px;
  }
}

@media (min-width: 700px) and (min-height: 800px) {
  #app {
    padding-top: 18px;
    padding-bottom: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
