:root {
  --bg: #f4ede1;
  --ink: #2c2420;
  --accent: #b5651d;
  --panel: #fffaf2;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  background: #2c2420;
  color: var(--ink);
  overflow: hidden;
}
.hidden { display: none !important; }

.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 14, 10, 0.6);
  z-index: 50;
}
.entry-card {
  background: var(--panel);
  padding: 40px 36px; border-radius: 16px; text-align: center;
  width: min(90vw, 380px); box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.entry-card h1 { font-size: 30px; color: var(--accent); letter-spacing: .1em; }
.entry-card .sub { margin: 14px 0 22px; line-height: 1.7; color: #6b5d50; font-size: 14px; }
.entry-card input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 2px solid #e0d3c0; border-radius: 10px; margin-bottom: 14px;
}
.entry-card input:focus { outline: none; border-color: var(--accent); }
.entry-card button {
  width: 100%; padding: 13px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff; border: none; border-radius: 10px; cursor: pointer;
}
.entry-card button:hover { background: #9c5417; }
.entry-card .hint { margin-top: 18px; font-size: 11px; color: #9a8b7c; line-height: 1.6; }

#stage { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#canvas {
  background: #d9c7ad;
  max-width: 100vw; max-height: 100vh;
  width: auto; height: auto;
  image-rendering: auto;
}

#chat {
  position: fixed; right: 14px; bottom: 14px;
  width: min(88vw, 320px);
  background: var(--panel); border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  display: flex; flex-direction: column; overflow: hidden; z-index: 20;
}
#chatHeader {
  padding: 9px 14px; font-size: 12px; font-weight: 600;
  background: #efe3d2; color: #8a7862;
}
#chatHeader.near { background: #dff0dd; color: #2f7d32; }
#messages {
  height: 200px; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 7px; font-size: 13px;
}
.msg { line-height: 1.45; }
.msg .who { font-weight: 700; margin-right: 5px; }
.msg.self .who { color: var(--accent); }
.msg.shopkeeper .who { color: #2f7d32; }
.msg.system { color: #a99; font-size: 11px; font-style: italic; }
#chatForm { display: flex; border-top: 1px solid #ece0cf; }
#chatInput { flex: 1; border: none; padding: 11px 13px; font-size: 14px; }
#chatInput:focus { outline: none; }
#chatForm button {
  border: none; background: var(--accent); color: #fff;
  padding: 0 16px; font-weight: 600; cursor: pointer;
}

.book-card {
  background: var(--panel); border-radius: 16px; padding: 26px;
  width: min(92vw, 480px); position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.book-card .close {
  position: absolute; top: 10px; right: 14px; border: none; background: none;
  font-size: 26px; cursor: pointer; color: #b0a494; line-height: 1;
}
.book-body { display: flex; gap: 20px; }
#bookCover {
  width: 130px; height: 185px; object-fit: cover; border-radius: 6px;
  background: #e6dccd; flex-shrink: 0; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.book-info h2 { font-size: 17px; line-height: 1.4; margin-bottom: 8px; }
.book-info .author { font-size: 13px; color: #7a6c5d; margin-bottom: 10px; }
.book-info .price { font-size: 20px; font-weight: 700; color: var(--accent); margin-bottom: 12px; }
.book-info .desc {
  font-size: 12px; color: #6b5d50; line-height: 1.6; margin-bottom: 16px;
  max-height: 90px; overflow-y: auto;
}
#buyBtn {
  display: inline-block; background: var(--accent); color: #fff;
  padding: 11px 20px; border-radius: 10px; text-decoration: none; font-weight: 600; font-size: 14px;
}
#buyBtn:hover { background: #9c5417; }
