:root {
  --parchment: #d1c5b6;
  --parchment-light: #e9dfd0;
  --ink: #211a14;
  --button: #aaa197;
  --gold: #fff04a;
  --line: rgba(58, 45, 35, .62);
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Lucida Calligraphy", "Segoe Print", cursive;
  background: #4b443e url("treasure_chest.jpg") center / cover fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(225, 217, 202, .72);
  backdrop-filter: saturate(.6);
}

.app-shell {
  width: min(960px, calc(100% - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
  padding: clamp(16px, 3vw, 30px);
  background: rgba(209, 197, 182, .64);
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(31, 23, 18, .28);
}

.title-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

h1 { margin: 2px 0 0; font-size: clamp(1.65rem, 4vw, 2.4rem); }
.eyebrow { margin: 0; font-family: Georgia, serif; text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; }
.saved-note { max-width: 260px; font-family: Georgia, serif; font-size: .83rem; text-align: right; opacity: .78; }

fieldset {
  margin: 0 0 15px;
  padding: 16px;
  border: 1px solid var(--line);
  background: rgba(225, 217, 202, .28);
}

legend { padding: 0 8px; font-weight: 700; }
.coin-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.coin-grid label { display: grid; gap: 3px; min-width: 0; }
.coin-grid small { font-size: .68rem; }

input, select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 5px 8px;
  border: 1px solid #6f655c;
  border-radius: 3px;
  color: var(--ink);
  background: var(--parchment);
  font: inherit;
}

input:focus, select:focus, button:focus-visible {
  outline: 3px solid rgba(255, 240, 74, .7);
  outline-offset: 2px;
}

.jewel-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.jewel-set { display: grid; grid-template-columns: auto 52px auto 60px auto; align-items: center; gap: 7px; min-width: 0; }
.jewel-set h2 { grid-column: 1 / -1; margin: 0 0 4px; font-size: 1rem; }
.jewel-set label { display: contents; }
.jewel-set span { margin-left: -3px; white-space: nowrap; }

.action-bar, .footer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

.party-label { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.party-label select { width: 72px; }

button {
  min-height: 42px;
  padding: 7px 14px;
  border: 2px outset #eee6da;
  border-radius: 5px;
  color: var(--gold);
  background: var(--button);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-shadow: 0 1px 1px rgba(44, 34, 20, .55);
}
button:hover { filter: brightness(1.06); }
button:active { border-style: inset; transform: translateY(1px); }

.results-frame { min-height: 250px; }
#results {
  min-height: 205px;
  margin: 0;
  padding: 8px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: transparent;
  font: 1rem/1.7 "Lucida Calligraphy", "Segoe Print", cursive;
}

.footer-row { margin-bottom: 0; }
#status { min-height: 1.4em; margin: 0; font-family: Georgia, serif; font-size: .9rem; }

@media (max-width: 760px) {
  .coin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .jewel-grid { grid-template-columns: 1fr; gap: 12px; }
  .jewel-set { grid-template-columns: auto 58px auto 70px auto; }
  .title-row { align-items: start; flex-direction: column; gap: 6px; }
  .saved-note { text-align: left; }
}

@media (max-width: 430px) {
  .app-shell { width: 100%; min-height: 100vh; margin: 0; border-radius: 0; padding: 14px; }
  .coin-grid { gap: 10px; }
  .action-bar { align-items: stretch; flex-direction: column; }
  .party-label { justify-content: space-between; }
  button { width: 100%; }
}
