@import url('https://fonts.googleapis.com/css2?family=IM+Fell+English:ital@0;1&family=Pixelify+Sans:wght@400;500;600;700&display=swap');

:root {
  color-scheme: light;
  --sky: #b9ddc8;
  --grass: #3f7133;
  --grass-deep: #244b2b;
  --leaf: #79a64a;
  --water: #4f9ca6;
  --gold: #e2a93f;
  --sun: #ffd884;
  --soil: #8a653f;
  --wood: #6a4228;
  --wood-dark: #2d1e19;
  --paper: #fff0c7;
  --paper-soft: #f4d997;
  --ink: #261c16;
  --muted: #6c5741;
  --line: #5b3c2a;
  --danger: #a84434;
  --success: #2f7844;
  --shadow: rgba(30, 22, 15, 0.28);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--sky);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Pixelify Sans", system-ui, sans-serif;
  font-size: 1rem;
  letter-spacing: 0;
  background:
    linear-gradient(180deg, rgba(185, 221, 200, 0.9), rgba(246, 221, 151, 0.65) 48%, rgba(61, 110, 51, 0.62)),
    repeating-linear-gradient(90deg, rgba(62, 117, 50, 0.16) 0 42px, rgba(92, 140, 63, 0.16) 42px 78px),
    var(--sky);
}

.page-play {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100svh;
  min-height: 100svh;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 12% 90%, rgba(51, 105, 47, 0.42) 0 18%, transparent 19%),
    radial-gradient(ellipse at 86% 88%, rgba(122, 157, 70, 0.32) 0 20%, transparent 21%),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(37, 77, 40, 0.08) 31px 34px);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4rem;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  border-bottom: 3px solid var(--wood-dark);
  background:
    linear-gradient(180deg, rgba(255, 238, 190, 0.96), rgba(232, 186, 98, 0.96)),
    repeating-linear-gradient(90deg, rgba(106, 66, 40, 0.16) 0 18px, rgba(45, 30, 25, 0.12) 18px 22px);
  box-shadow: 0 6px 0 rgba(40, 29, 22, 0.18);
}

.brand {
  color: var(--wood-dark);
  font-family: "IM Fell English", Georgia, serif;
  font-size: 1.45rem;
  font-weight: 700;
  text-shadow: 1px 1px 0 var(--sun);
}

.site-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
}

.site-nav a,
.link-button,
.counter-chip {
  min-height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.65rem;
  border: 2px solid rgba(45, 30, 25, 0.42);
  background: rgba(255, 240, 199, 0.76);
  box-shadow: 0 3px 0 rgba(45, 30, 25, 0.24);
}

.site-nav a:hover,
.link-button:hover {
  transform: translateY(-1px);
  background: #fff8db;
}

.link-button {
  color: var(--ink);
  cursor: pointer;
}

.counter-chip {
  gap: 0.3rem;
  color: var(--grass-deep);
  font-weight: 700;
}

.session-label,
.eyebrow {
  color: var(--muted);
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 0.35rem;
}

.home-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: clamp(1rem, 2.8vw, 2rem);
}

.hero {
  position: relative;
  display: grid;
  align-items: center;
  grid-template-columns: minmax(18rem, 0.9fr) minmax(20rem, 1.2fr);
  gap: clamp(1.4rem, 4vw, 3rem);
  width: min(76rem, 100%);
  margin: auto;
}

.hero-copy {
  z-index: 1;
  padding: clamp(1.2rem, 3vw, 2rem);
  border: 3px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 240, 199, 0.94), rgba(244, 217, 151, 0.94)),
    repeating-linear-gradient(0deg, rgba(106, 66, 40, 0.07) 0 1px, transparent 1px 7px);
  box-shadow: 8px 8px 0 rgba(43, 30, 22, 0.2);
}

.hero h1,
.form-panel h1,
.play-panel h1,
.content-panel h1 {
  margin: 0 0 0.75rem;
  font-family: "IM Fell English", Georgia, serif;
  font-size: clamp(2.5rem, 6vw, 5rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.hero p,
.form-panel p,
.content-panel p {
  max-width: 44rem;
  color: var(--muted);
  line-height: 1.55;
}

.hero-art {
  min-height: clamp(20rem, 45vw, 34rem);
  border: 4px solid var(--wood-dark);
  background:
    linear-gradient(90deg, rgba(255, 240, 199, 0.88) 0 24%, rgba(255, 240, 199, 0.12) 46%),
    url("/assets/adventure-banner.png") center / cover no-repeat;
  box-shadow: 10px 10px 0 rgba(43, 30, 22, 0.22);
  image-rendering: auto;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.button {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 3px solid var(--wood-dark);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(45, 30, 25, 0.34);
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: linear-gradient(180deg, #ffdd79, var(--gold));
}

.button.secondary {
  background: linear-gradient(180deg, #fff4ca, var(--paper-soft));
}

.button.danger {
  color: #fff6df;
  background: linear-gradient(180deg, #c85b46, var(--danger));
}

.download-menu {
  position: relative;
  z-index: 3;
}

.download-menu summary {
  list-style: none;
}

.download-menu summary::-webkit-details-marker {
  display: none;
}

.download-options {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  min-width: 11rem;
  padding: 0.35rem;
  border: 3px solid var(--wood-dark);
  background: var(--paper);
  box-shadow: 0 6px 0 rgba(45, 30, 25, 0.28);
}

.download-options a {
  display: block;
  padding: 0.55rem 0.75rem;
  color: var(--ink);
}

.download-options a:hover {
  background: #fff8db;
}

.adventure-bar {
  width: min(76rem, 100%);
  margin: 1.5rem auto 0;
  padding: 0.75rem 1rem;
  border: 3px solid var(--grass-deep);
  background: rgba(36, 75, 43, 0.9);
  color: #fff8cf;
  text-align: center;
  font-weight: 700;
  box-shadow: 0 5px 0 rgba(24, 45, 29, 0.32);
}

.adventure-bar:hover {
  transform: translateY(-1px);
  background: rgba(48, 99, 52, 0.94);
}

.page-layout,
.form-layout,
.builder-layout {
  width: min(76rem, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.admin-layout {
  width: 100%;
  min-height: calc(100vh - 4rem);
}

.play-layout {
  --chat-width: clamp(18rem, 22vw, 22rem);
  --chat-gap: 1rem;
  --play-pad: clamp(1rem, 3vw, 2rem);
  --play-panel-pad: clamp(1rem, 3vw, 1.75rem);
  --play-chrome-height: 6.75rem;
  --play-available-height: var(--play-available-height-px, calc(100svh - 4rem - (var(--play-pad) * 2)));
  --play-max-game-height: var(--play-max-game-height-px, calc(var(--play-available-height) - (var(--play-panel-pad) * 2) - var(--play-chrome-height)));
  --play-max-panel-width: var(--play-max-panel-width-px, calc((var(--play-max-game-height) / 9 * 16) + (var(--play-panel-pad) * 2)));
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: var(--play-pad) calc(var(--chat-width) + var(--chat-gap) + 1rem) var(--play-pad) var(--play-pad);
  display: grid;
  place-items: center stretch;
  overflow: hidden;
}

.form-layout {
  min-height: calc(100vh - 4rem);
  display: grid;
  place-items: center;
}

.form-panel,
.content-panel,
.play-panel,
.guide-panel {
  width: min(100%, 48rem);
  padding: clamp(1rem, 3vw, 1.75rem);
  border: 3px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 240, 199, 0.96), rgba(241, 211, 141, 0.96)),
    repeating-linear-gradient(90deg, rgba(106, 66, 40, 0.08) 0 20px, transparent 20px 24px);
  box-shadow: 8px 8px 0 rgba(43, 30, 22, 0.18);
}

.play-panel,
.guide-panel,
.content-panel.wide {
  width: min(100%, 76rem);
}

.admin-layout .admin-panel {
  width: 100%;
  max-width: none;
}

.play-layout .play-panel {
  width: min(100%, var(--play-max-panel-width));
  max-width: none;
  height: min-content;
  max-height: var(--play-available-height);
  justify-self: center;
  display: flex;
  flex-direction: column;
  padding: var(--play-panel-pad);
  overflow: hidden;
}

.play-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.game-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
  margin: 0 0 0.75rem;
}

.game-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 3px solid var(--wood-dark);
  background: #111;
}

.game-aspect {
  width: 100%;
  height: min(100%, var(--play-max-game-height));
  max-height: var(--play-max-game-height);
  flex: 0 1 var(--play-max-game-height);
  aspect-ratio: 16 / 9;
  min-height: 0;
}

.play-panel.frame-expanded {
  position: fixed;
  inset: 0.5rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: auto;
  padding-top: 4rem;
}

.play-layout .play-panel.frame-expanded {
  width: auto;
  max-width: none;
  height: auto;
  max-height: none;
  justify-self: auto;
  padding: 1rem;
}

.play-layout .play-panel.frame-expanded .play-heading {
  flex: 0 0 auto;
}

.play-panel.frame-expanded .game-frame {
  height: 100%;
}

.play-panel.frame-expanded .game-aspect {
  flex: 1 1 auto;
  width: 100%;
  height: auto;
  max-height: none;
  min-height: 0;
  aspect-ratio: auto;
}

.play-chat-dock {
  position: fixed;
  top: calc(4rem + 1rem);
  right: 1rem;
  bottom: 1rem;
  z-index: 8;
  width: var(--chat-width, clamp(18rem, 22vw, 22rem));
  overflow: hidden;
  border: 3px solid var(--line);
  background: var(--paper);
  box-shadow: 8px 8px 0 rgba(43, 30, 22, 0.18);
}

.chat-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--paper);
}

.game-frame-expanded .play-chat-dock {
  display: none;
}

.page-chat-embed {
  min-height: 100vh;
  overflow: hidden;
  background: var(--paper);
}

.chat-embed-shell {
  height: 100vh;
  padding: 0;
  overflow: hidden;
}

.chat-embed-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.55rem;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0.75rem;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.chat-embed-panel h1 {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

label {
  display: grid;
  gap: 0.35rem;
  margin: 0.8rem 0;
  color: var(--wood-dark);
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 3px solid var(--line);
  padding: 0.7rem;
  background: #fff9dc;
  color: var(--ink);
}

textarea {
  min-height: 8rem;
  resize: vertical;
}

.form-message {
  min-height: 1.5rem;
  margin: 0.75rem 0;
  font-weight: 700;
}

.form-message.error {
  color: var(--danger);
}

.form-message.success {
  color: var(--success);
}

.bug-toggle {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
}

.page-play .bug-toggle {
  right: auto;
  left: 1rem;
}

.bug-panel {
  position: fixed;
  right: 1rem;
  bottom: 5rem;
  z-index: 20;
  width: min(24rem, calc(100vw - 2rem));
  padding: 1rem;
  border: 3px solid var(--line);
  background: var(--paper);
  box-shadow: 8px 8px 0 rgba(43, 30, 22, 0.22);
}

.chat-window {
  height: 56vh;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  gap: 0.65rem;
  align-content: start;
  padding: 0.75rem;
  border: 3px solid var(--line);
  background: rgba(255, 249, 220, 0.86);
}

.chat-embed-panel .chat-window {
  height: 100%;
  min-height: 0;
  align-self: stretch;
}

.chat-embed-panel .chat-form {
  grid-template-columns: 1fr;
  margin-top: 0;
  align-self: end;
}

.chat-embed-panel .button {
  width: 100%;
}

.chat-embed-panel .form-message {
  min-height: 0;
  margin: 0;
}

.chat-message {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: start;
  padding: 0.55rem;
  background: rgba(244, 217, 151, 0.62);
}

.chat-message p {
  margin: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.chat-message time {
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.chat-form.chat-readonly {
  grid-template-columns: 1fr;
}

.guide-grid,
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.85rem;
}

.guide-grid article,
.admin-user-row {
  padding: 0.9rem;
  border: 2px solid rgba(91, 60, 42, 0.55);
  background: rgba(255, 249, 220, 0.56);
}

.admin-user-row {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(18rem, auto);
  gap: 1rem;
  margin: 0.75rem 0;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
}

.admin-actions label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
}

.admin-actions input[type="checkbox"] {
  width: auto;
}

@media (max-width: 820px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero-art {
    min-height: 18rem;
    order: -1;
  }

  .site-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .site-nav {
    justify-content: flex-start;
  }

  .chat-form,
  .admin-user-row {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 1100px) {
  .page-play {
    display: block;
    height: auto;
    min-height: 100svh;
    overflow: visible;
  }

  .play-layout {
    height: auto;
    min-height: calc(100svh - 4rem);
    padding-right: clamp(1rem, 3vw, 2rem);
    place-items: center stretch;
    overflow: visible;
  }

  .play-chat-dock {
    position: static;
    width: min(100%, 76rem);
    height: 24rem;
    min-height: 0;
    margin: 0 auto 1rem;
  }
}

@media (max-height: 599px) {
  .page-play {
    display: block;
    height: auto;
    min-height: 100svh;
    overflow: visible;
  }

  .play-layout {
    height: auto;
    min-height: calc(100svh - 4rem);
    overflow: visible;
  }

  .play-layout .play-panel {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .game-aspect {
    height: auto;
    max-height: none;
    flex-basis: auto;
  }
}
