:root {
  --night-1: #0b1026;
  --night-2: #1b2550;
  --night-3: #3a3f7a;
  --gui: #c6c6c6;
  --gui-light: #ffffff;
  --gui-dark: #555555;
  --gui-edge: #000000;
  --slot: #8b8b8b;
  --slot-dark: #373737;
  --tooltip-bg: #100010f0;
  --tooltip-edge: #2800a0;
  --tooltip-edge-2: #50007f;
  --text: #3f3f3f;
  --grass: #68b034;
  --grass-dark: #4c8a25;
  --dirt: #79553a;
  --dirt-dark: #5d3b1e;
  --gold: #fcdb05;
  --aqua: #55ffff;
  --pink: #ff55ff;
  --yellow: #ffff55;
  --blue: #5555ff;
  --green: #55ff55;
  --red: #ff5555;
  --gray: #aaaaaa;
  --display: "Pixelify Sans", ui-monospace, monospace;
  --body: "Atkinson Hyperlegible", "Trebuchet MS", sans-serif;
  --px: 4px;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--body);
  font-size: 18px;
  color: #fff;
  background: linear-gradient(180deg, var(--night-1) 0%, var(--night-2) 55%, var(--night-3) 100%);
  display: flex;
  flex-direction: column;
}

.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 8% 12%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 23% 30%, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 41% 8%, #ffffaa 50%, transparent 51%),
    radial-gradient(2px 2px at 57% 22%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 71% 6%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 86% 26%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 94% 14%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 33% 44%, #ccd 50%, transparent 51%),
    radial-gradient(2px 2px at 64% 40%, #ccd 50%, transparent 51%);
  animation: twinkle 6s steps(3) infinite;
  z-index: 0;
}

.sky::after {
  content: "";
  position: absolute;
  top: 48px;
  right: 9%;
  width: 56px;
  height: 56px;
  background: #e8e8d0;
  box-shadow: inset -12px -8px 0 #c9c9ad, 0 0 60px 10px #ffffff22;
}

@keyframes twinkle { 50% { opacity: 0.6; } }

.masthead, main { position: relative; z-index: 1; }

.masthead {
  text-align: center;
  padding: 36px 16px 8px;
}

.logo {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  line-height: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.logo span { display: block; }

.logo-top {
  font-size: clamp(40px, 8vw, 76px);
  color: #dcdcdc;
  text-shadow: var(--px) var(--px) 0 #3a3a3a, calc(var(--px) * 2) calc(var(--px) * 2) 0 #0008;
}

.logo-bottom {
  font-size: clamp(48px, 10vw, 96px);
  color: var(--gold);
  text-shadow: var(--px) var(--px) 0 #8a6d00, calc(var(--px) * 2) calc(var(--px) * 2) 0 #0008;
  animation: bob 3.2s ease-in-out infinite;
}

@keyframes bob { 50% { transform: translateY(-4px) rotate(-1deg); } }

.tagline {
  font-family: var(--display);
  color: var(--yellow);
  font-size: 20px;
  margin: 14px 0 0;
  transform: rotate(-2deg);
  text-shadow: 2px 2px 0 #3f3f00;
}

main {
  width: min(1100px, 100% - 24px);
  margin: 16px auto 0;
  flex: 1;
  display: grid;
  align-content: start;
  gap: 28px;
  padding-bottom: 48px;
}

.ground {
  height: 72px;
  background:
    linear-gradient(180deg, var(--grass) 0 18px, var(--grass-dark) 18px 24px, transparent 24px),
    repeating-linear-gradient(90deg, var(--dirt) 0 16px, var(--dirt-dark) 16px 20px, var(--dirt) 20px 36px, #6a4a30 36px 40px);
  border-top: 4px solid #2f5f14;
  position: relative;
  z-index: 1;
}

/* Minecraft GUI panel */
.panel {
  background: var(--gui);
  color: var(--text);
  padding: 22px;
  border: var(--px) solid var(--gui-edge);
  box-shadow:
    inset var(--px) var(--px) 0 var(--gui-light),
    inset calc(var(--px) * -1) calc(var(--px) * -1) 0 var(--gui-dark),
    8px 8px 0 #0006;
  animation: rise 0.45s ease-out both;
}

.panel h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 24px;
  margin: 0 0 14px;
  color: #404040;
}

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.slot {
  background: var(--slot);
  border: 0;
  box-shadow: inset var(--px) var(--px) 0 var(--slot-dark), inset calc(var(--px) * -1) calc(var(--px) * -1) 0 var(--gui-light);
}

/* Buttons: in-game stone button */
.btn {
  font-family: var(--display);
  font-size: 20px;
  color: #fff;
  text-shadow: 2px 2px 0 #3f3f3f;
  background: #6f6f6f;
  border: 3px solid #000;
  box-shadow: inset 3px 3px 0 #aaa, inset -3px -3px 0 #4a4a4a;
  padding: 10px 18px;
  cursor: pointer;
  min-height: 48px;
}

.btn:hover:not(:disabled), .btn:focus-visible {
  background: #7d86c8;
  box-shadow: inset 3px 3px 0 #b8c0ff, inset -3px -3px 0 #4b5294;
  outline: none;
  color: var(--yellow);
}

.btn:disabled { color: #a0a0a0; background: #2c2c2c; box-shadow: none; cursor: wait; }

.btn-go {
  position: relative;
  overflow: hidden;
  background: #3c8527;
  box-shadow: inset 3px 3px 0 #79d156, inset -3px -3px 0 #23561a;
}

.btn-go::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, #ffffff55 45%, #d68bff66 50%, transparent 65%);
  transform: translateX(-100%);
  animation: glint 2.8s ease-in-out infinite;
}

@keyframes glint { 60%, 100% { transform: translateX(100%); } }

.btn-idea { background: #b07d10; box-shadow: inset 3px 3px 0 #f2c94c, inset -3px -3px 0 #6e4d06; }
.btn-small { font-size: 16px; padding: 6px 12px; min-height: 40px; }
.btn-danger:hover:not(:disabled) { background: #a33; box-shadow: inset 3px 3px 0 #e66, inset -3px -3px 0 #611; }

.btn-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }

/* Login */
.login { max-width: 460px; justify-self: center; text-align: center; }
.login p { margin: 0 0 14px; }
.login .label { text-align: left; margin-top: 12px; }
.btn-row.centered { justify-content: center; }

.account {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  font-family: var(--display);
  color: var(--yellow);
  text-shadow: 2px 2px 0 #000;
}

input[type="password"], input[type="text"], textarea {
  width: 100%;
  font-family: var(--body);
  font-size: 20px;
  color: #fff;
  background: #000;
  border: 3px solid #a0a0a0;
  padding: 12px;
  outline: none;
}

input[type="password"]:focus, input[type="text"]:focus, textarea:focus { border-color: #fff; box-shadow: 0 0 0 3px var(--blue); }
textarea { min-height: 110px; resize: vertical; line-height: 1.4; }
textarea::placeholder { color: #8a8a8a; }

/* Hotbar kind picker */
.hotbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0;
  padding: 6px;
  background: #1e1e1e;
  border: 3px solid #000;
  margin-bottom: 18px;
}

.hotbar button {
  position: relative;
  aspect-ratio: 1;
  max-height: 104px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  background: #8b8b8b55;
  border: 3px solid #3c3c3c;
  color: #fff;
  font-family: var(--display);
  font-size: 15px;
  cursor: pointer;
  text-shadow: 2px 2px 0 #000;
}

.hotbar .emoji { font-size: clamp(26px, 5vw, 40px); line-height: 1; filter: drop-shadow(2px 2px 0 #0008); }
.hotbar button:hover { background: #ffffff22; }
.hotbar button:focus-visible { outline: 3px solid var(--yellow); outline-offset: -6px; }

.hotbar button[aria-pressed="true"] {
  border-color: #fff;
  box-shadow: 0 0 0 3px #000, inset 0 0 0 3px #000;
  background: #ffffff30;
  z-index: 1;
  transform: scale(1.06);
}

.hotbar button[aria-pressed="true"] .emoji { animation: bob 1.4s ease-in-out infinite; }

.label { font-family: var(--display); font-size: 18px; display: block; margin-bottom: 8px; color: #404040; }

/* Ideas */
.ideas { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-top: 18px; }

.idea {
  text-align: left;
  font: inherit;
  cursor: pointer;
  padding: 14px;
  color: #fff;
  background: var(--tooltip-bg);
  border: 3px solid var(--tooltip-edge-2);
  outline: 3px solid #100010;
  animation: rise 0.4s ease-out both;
}

.idea:hover, .idea:focus-visible { border-color: var(--aqua); transform: translateY(-3px); }
.idea strong { display: block; font-family: var(--display); color: var(--yellow); font-size: 20px; margin-bottom: 4px; }
.idea span { color: var(--gray); font-size: 16px; }

/* Preview: item tooltip */
.preview { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: start; }

.icon-frame {
  width: 176px;
  height: 176px;
  display: grid;
  place-items: center;
  position: relative;
}

.icon-frame img, .card img { image-rendering: pixelated; width: 128px; height: 128px; }

.icon-frame.loading::after {
  content: "";
  position: absolute;
  width: 48px;
  height: 48px;
  background: conic-gradient(var(--aqua) 0 25%, transparent 0 50%, var(--pink) 0 75%, transparent 0);
  animation: spin 0.8s steps(8) infinite;
}

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

.tooltip {
  background: var(--tooltip-bg);
  color: #fff;
  padding: 14px 18px;
  border: 3px solid transparent;
  border-image: linear-gradient(180deg, var(--tooltip-edge), var(--tooltip-edge-2)) 1;
  outline: 3px solid #100010;
  font-family: var(--display);
  font-size: 18px;
  line-height: 1.35;
  max-width: 560px;
}

.tooltip .name { font-size: 26px; margin: 0 0 2px; }
.rarity-common { color: #fff; }
.rarity-uncommon { color: var(--yellow); }
.rarity-rare { color: var(--aqua); }
.rarity-epic { color: var(--pink); }
.tooltip .lore { color: var(--gray); font-family: var(--body); font-style: italic; margin: 0 0 10px; }
.tooltip .section { color: var(--gray); margin-top: 10px; }
.tooltip ul { list-style: none; margin: 0; padding: 0; }
.tooltip .stat { color: var(--blue); }
.tooltip .power { color: var(--green); }
.tooltip .ability { color: var(--gold); }
.tooltip .warn { color: var(--red); }

/* Crafting grid */
.crafting { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.grid3 { display: grid; grid-template-columns: repeat(3, 56px); grid-auto-rows: 56px; gap: 4px; }
.grid3 .slot, .result-slot {
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 10px;
  line-height: 1.05;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  padding: 3px;
  word-break: break-word;
}
.arrow { font-family: var(--display); font-size: 40px; color: #8b8b8b; }
.result-slot { width: 72px; height: 72px; }
.result-slot img { width: 48px; height: 48px; image-rendering: pixelated; }

/* Library */
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 14px; }

.card {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 14px 10px;
  text-align: center;
  animation: rise 0.4s ease-out both;
}
.card img { width: 72px; height: 72px; }
.card .card-name { font-family: var(--display); font-size: 17px; color: #fff; text-shadow: 2px 2px 0 #000; }
.card .card-kind { font-size: 13px; color: #e0e0e0; text-transform: uppercase; letter-spacing: 0.08em; }
.card .btn-row { margin-top: 4px; gap: 6px; justify-content: center; flex-wrap: nowrap; }
.card .btn-small { padding: 6px 10px; }
.card .placeholder { width: 72px; height: 72px; display: grid; place-items: center; font-size: 40px; }

.empty { font-family: var(--display); color: #555; font-size: 20px; }

.status { font-family: var(--display); min-height: 1.4em; margin: 12px 0 0; color: #2b2b2b; }
.status.error { color: #a00; }

.guide ol { margin: 0; padding-left: 22px; line-height: 1.55; }
.guide li { margin-bottom: 8px; }
.guide code {
  background: #000;
  color: var(--green);
  padding: 2px 6px;
  font-size: 16px;
  word-break: break-all;
}
.guide details { margin-top: 12px; }
.guide summary { font-family: var(--display); font-size: 20px; cursor: pointer; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 720px) {
  body { font-size: 17px; }
  .panel { padding: 16px; }
  .preview { grid-template-columns: 1fr; justify-items: center; }
  .hotbar button { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
