@layer reset, base, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { color-scheme: light; }
  body, h1, h2, h3, p { margin: 0; }
  button, input, select { font: inherit; }
  img { display: block; max-width: 100%; }
  button, a { -webkit-tap-highlight-color: transparent; }
}

@layer base {
  :root {
    --forest: #173c32;
    --forest-dark: #0c2922;
    --cream: #f3eddf;
    --paper: #fffdf7;
    --ink: #1e2824;
    --muted: #66716c;
    --line: #d6d0c2;
    --orange: #dc5d38;
    --orange-dark: #b84224;
    --yellow: #f1c75b;
    --shadow: 0 18px 45px rgb(29 42 36 / .12);
    --radius: 12px;
  }

  body {
    min-height: 100vh;
    background:
      radial-gradient(circle at 12% 4%, rgb(241 199 91 / .24), transparent 24rem),
      var(--cream);
    color: var(--ink);
    font-family: "Trebuchet MS", "Gill Sans", sans-serif;
    line-height: 1.5;
  }

  body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .18;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
    mix-blend-mode: multiply;
  }

  h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; line-height: 1.08; }
  h1 { max-width: 13ch; font-size: clamp(3rem, 7vw, 6.6rem); letter-spacing: -.055em; }
  h2 { font-size: clamp(1.75rem, 3vw, 2.55rem); letter-spacing: -.03em; }
  h3 { font-size: 1.1rem; }
  button, select, input { min-height: 46px; }
  button, a, select { cursor: pointer; }
  :focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
  [hidden] { display: none !important; }
}

@layer components {
  .site-header {
    width: min(1500px, calc(100% - 40px));
    margin: 0 auto;
    min-height: 82px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgb(23 60 50 / .22);
  }
  .brand { display: inline-flex; align-items: center; gap: 10px; color: var(--forest); font: 700 1.05rem Georgia, serif; text-decoration: none; }
  .brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--forest); color: var(--cream); }
  .privacy-note { color: var(--muted); font-size: .85rem; }

  main { width: min(1500px, calc(100% - 40px)); margin: 0 auto; }
  .welcome { min-height: calc(100vh - 82px); display: grid; grid-template-columns: 1.2fr .8fr; align-items: center; gap: clamp(40px, 8vw, 140px); padding: 72px 0 100px; }
  .eyebrow { margin-bottom: 14px; color: var(--orange-dark); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
  .lede { max-width: 620px; margin-top: 26px; color: #48534e; font: 1.25rem/1.6 Georgia, serif; }

  .import-form { padding: clamp(24px, 4vw, 44px); background: var(--forest); color: white; box-shadow: var(--shadow); border-radius: var(--radius); transform: rotate(.7deg); }
  .import-form label { display: block; margin-bottom: 8px; font-weight: 700; }
  .import-form .token-label { margin-top: 16px; }
  .load-shelf-button { width: 100%; margin-top: 18px; }
  .input-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
  input, select { width: 100%; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); color: var(--ink); padding: 0 14px; }
  input::placeholder { color: #8b918e; }
  .form-hint { margin-top: 12px; color: #c6d4cf; font-size: .82rem; }
  .status { min-height: 1.5em; margin-top: 16px; color: #ffe18f; font-size: .9rem; }
  .status[data-kind="error"] { color: #ffc1b3; }

  .button { border: 0; border-radius: 7px; padding: 0 20px; font-weight: 800; transition: transform .15s ease, background .15s ease; }
  .button:hover { transform: translateY(-2px); }
  .button:active { transform: translateY(0); }
  .button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
  .button-primary { background: var(--yellow); color: var(--forest-dark); }
  .button-primary:hover { background: #ffdb78; }
  .button-secondary { background: var(--forest); color: white; }
  .text-button { border: 0; background: transparent; color: var(--forest); font-weight: 800; text-decoration: underline; text-underline-offset: 4px; }

  .workspace { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 36px; padding: 56px 0 100px; align-items: start; }
  .shelf-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 30px; }
  .filters { display: grid; grid-template-columns: minmax(180px, 1.4fr) repeat(3, minmax(130px, .65fr)); gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: rgb(255 253 247 / .72); }
  .filters label > span { display: block; margin: 0 0 5px 3px; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
  .game-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
  .game-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: rgb(255 253 247 / .82); transition: transform .18s ease, box-shadow .18s ease; }
  .game-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgb(29 42 36 / .1); }
  .cover { aspect-ratio: 1.42; overflow: hidden; background: #ddd7c9; }
  .cover img { width: 100%; height: 100%; object-fit: cover; }
  .cover img[src=""] { visibility: hidden; }
  .game-info { padding: 15px; }
  .game-info h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .game-meta { margin-top: 7px; color: var(--muted); font-size: .78rem; }
  .game-foot { display: flex; justify-content: space-between; margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: .75rem; font-weight: 800; }
  .game-foot a, .bgg-link { color: var(--orange-dark); text-decoration: none; }
  .rating { color: var(--forest); }
  .empty-state { margin-top: 20px; padding: 56px 24px; border: 1px dashed #aaa293; border-radius: 10px; text-align: center; }
  .empty-state p { margin: 10px 0 20px; color: var(--muted); }

  .picker { position: sticky; top: 20px; min-height: 570px; padding: 28px; border-radius: var(--radius); background: var(--forest); color: white; box-shadow: var(--shadow); }
  .picker-topline { display: flex; align-items: center; justify-content: space-between; }
  .picker .eyebrow { color: #f5cc63; margin-bottom: 0; }
  .match-count { color: #bcd0ca; font-size: .75rem; }
  .pick-placeholder { min-height: 385px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
  .pick-placeholder p { max-width: 29ch; margin-top: 15px; color: #c7d6d1; }
  .die { position: relative; width: 90px; height: 90px; margin-bottom: 34px; border: 2px solid #f1c75b; border-radius: 18px; transform: rotate(8deg); }
  .die span { position: absolute; width: 10px; height: 10px; border-radius: 50%; background: #f1c75b; }
  .die span:nth-child(1) { top: 18px; left: 18px; } .die span:nth-child(2) { top: 18px; right: 18px; }
  .die span:nth-child(3) { inset: 0; margin: auto; } .die span:nth-child(4) { bottom: 18px; left: 18px; } .die span:nth-child(5) { bottom: 18px; right: 18px; }
  .picked-game { min-height: 385px; padding-top: 22px; }
  .picked-art { height: 210px; overflow: hidden; border-radius: 7px; background: #31584d; }
  .picked-art img { width: 100%; height: 100%; object-fit: cover; }
  .picked-kicker { margin-top: 20px; color: #f1c75b; font-size: .75rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
  .picked-game h2 { margin-top: 4px; }
  .picked-meta { margin: 8px 0 12px; color: #c7d6d1; }
  .bgg-link { color: #f6d77e; font-size: .85rem; font-weight: 800; }
  .button-roll { width: 100%; background: var(--orange); color: white; font-size: 1rem; }
  .button-roll:hover { background: #ec6b45; }
  .keyboard-hint { margin-top: 12px; color: #9eb5ae; font-size: .72rem; text-align: center; }
  kbd { padding: 1px 6px; border: 1px solid #769087; border-bottom-width: 2px; border-radius: 4px; color: white; font: inherit; }
  .picker.is-rolling .picked-art { animation: shuffle .45s ease both; }
  @keyframes shuffle { 0% { opacity: .25; transform: scale(.96) rotate(-1deg); } 100% { opacity: 1; transform: scale(1) rotate(0); } }
}

@layer responsive {
  @media (max-width: 1100px) {
    .workspace { grid-template-columns: minmax(0, 1fr) 330px; }
    .game-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filters { grid-template-columns: 1fr 1fr; }
  }
  @media (max-width: 780px) {
    .site-header, main { width: min(100% - 24px, 1500px); }
    .privacy-note { display: none; }
    .welcome { min-height: auto; grid-template-columns: 1fr; gap: 42px; padding: 56px 0 72px; }
    h1 { font-size: clamp(3.2rem, 16vw, 5.2rem); }
    .import-form { transform: none; }
    .input-row { grid-template-columns: 1fr; }
    .workspace { display: flex; flex-direction: column; padding-top: 34px; }
    .picker { position: relative; top: auto; order: -1; width: 100%; min-height: 0; }
    .pick-placeholder, .picked-game { min-height: 300px; }
    .picked-art { height: 180px; }
  }
  @media (max-width: 520px) {
    .site-header { min-height: 68px; }
    .welcome { padding-top: 38px; }
    .lede { font-size: 1.05rem; }
    .filters, .game-grid { grid-template-columns: 1fr; }
    .shelf-heading { align-items: start; }
    .picker { padding: 22px; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
  }
}
