:root {
  --mansion-layout-height: 100dvh;
  --mansion-keyboard-inset: 0px;
  --mansion-toolbar-height: calc(56px + env(safe-area-inset-top));
  /* 키보드 판의 기본 자리 — 키보드가 뜨기 전에는 화면 위쪽. index.html 이 키보드 높이를 안 뒤 px 로 덮어쓴다. */
  --mansion-sheet-top: max(12px, env(safe-area-inset-top));
  background: #080b1b;
  color: #f4ead1;
}

* { box-sizing: border-box; }
html { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { position: fixed; inset: 0; width: 100%; height: var(--mansion-layout-height); margin: 0; overflow: hidden; overscroll-behavior: none; background: radial-gradient(circle at 50% 15%, #1c2347 0%, #080b1b 58%, #02030a 100%); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans KR", sans-serif; }

#unity-container {
  position: fixed;
  top: var(--mansion-toolbar-height);
  right: 0;
  left: 0;
  width: 100%;
  height: calc(var(--mansion-layout-height) - var(--mansion-toolbar-height));
  overflow: hidden;
  background: #080b1b;
}

#unity-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

#mansion-toolbar {
  position: fixed;
  z-index: 40;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(56px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid #ad8b4c50;
  background: #0b1021;
  color: #e6d5ac;
}
#mansion-toolbar[hidden], #mansion-menu[hidden] { display: none; }
.mansion-wordmark { overflow: hidden; white-space: nowrap; font-family: Georgia, "Noto Serif KR", serif; font-size: 14px; font-weight: 600; letter-spacing: .08em; }
.mansion-toolbar-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; }
#mansion-lunel { display: flex; align-items: center; gap: 3px; color: #e8dfc8; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#mansion-lunel img { display: block; width: 26px; height: 26px; object-fit: contain; }
#mansion-lunel[data-known="false"], #mansion-lunel[data-empty="true"] { color: #989eb0; }
#mansion-menu-toggle, #mansion-menu-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #c6a26055;
  border-radius: 10px;
  background: transparent;
  color: #e6d5ac;
  cursor: pointer;
  touch-action: manipulation;
}
#mansion-menu-toggle[aria-expanded="true"] { background: #c6a26017; border-color: #c6a26099; }
#mansion-menu { position: fixed; z-index: 50; inset: var(--mansion-toolbar-height) 0 0; }
#mansion-menu-backdrop { position: absolute; inset: 0; background: #020511a6; }
#mansion-menu-panel {
  position: absolute;
  top: 8px;
  right: max(12px, env(safe-area-inset-right));
  width: min(320px, calc(100% - 24px));
  max-height: calc(100% - 20px - env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 12px 12px;
  border: 1px solid #b6975c9c;
  border-radius: 16px;
  background: linear-gradient(145deg, #182138, #0c1226 74%);
  box-shadow: 0 18px 50px #0008;
  color: #f0e6ce;
  animation: mansion-menu-in .16s ease-out;
}
.mansion-menu-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-left: 12px; margin-bottom: 9px; }
.mansion-menu-heading h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .02em; }
#mansion-menu-close { border-color: transparent; color: #c7ba9d; }
.mansion-menu-row {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 58px;
  margin: 0;
  padding: 13px 12px;
  border: 0;
  border-top: 1px solid #c6a26024;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.mansion-menu-row > svg { flex: 0 0 auto; color: #c9ad74; }
.mansion-menu-arrow, .mansion-menu-value { margin-left: auto; color: #bcb6a8; }
.mansion-menu-arrow { font-size: 24px; line-height: 1; }
.mansion-menu-value { padding: 4px 9px; border: 1px solid #c6a26040; border-radius: 999px; font-size: 12px; }
.mansion-menu-value[data-on="true"] { border-color: #629f9866; background: #32696026; color: #abd2c8; }
.mansion-menu-row:disabled { opacity: .5; cursor: wait; }
#mansion-menu-toggle:focus-visible, #mansion-menu-close:focus-visible, .mansion-menu-row:focus-visible { outline: 2px solid #e0bc75; outline-offset: 2px; }
@media (hover: hover) {
  #mansion-menu-toggle:hover, #mansion-menu-close:hover, .mansion-menu-row:not(:disabled):hover { background: #c6a26012; }
}
@keyframes mansion-menu-in { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #mansion-menu-panel { animation: none; } }

#unity-loading {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
  background: radial-gradient(circle at 50% 35%, rgba(35,45,90,.94), rgba(5,7,18,.98) 68%);
  transition: opacity .35s ease, visibility .35s ease;
}
#unity-loading.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
#unity-loading h1 { margin: 0; font-size: clamp(22px, 6vw, 38px); font-weight: 700; letter-spacing: -.04em; }
#unity-loading p { margin: 0; color: #d4caaf; font-size: clamp(14px, 3.6vw, 17px); }
.eyebrow { color: #d7b46b !important; font-size: 12px !important; font-weight: 700; letter-spacing: .17em; }
.progress-track { width: min(330px, 82vw); height: 7px; overflow: hidden; border: 1px solid rgba(227,190,112,.65); border-radius: 999px; background: rgba(0,0,0,.36); }
#unity-progress { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #bd8848, #f1d58e); transition: width .12s ease; }

#unity-warning { position: fixed; z-index: 20; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(92vw, 680px); display: grid; gap: 8px; pointer-events: none; }
#unity-warning > div { padding: 11px 14px; border-radius: 12px; color: white; background: rgba(26,31,55,.95); box-shadow: 0 8px 28px rgba(0,0,0,.34); font-size: 14px; }
#unity-warning > .error { background: rgba(120,32,38,.96); }

/* 키보드 판 — 손님이 치는 글이 보이는 진짜 HTML 입력칸.
   휴대폰에서는 Unity 내장 MobileKeyboard.js 가 body > div > input(+OK 단추)로 만들고,
   Unity 가 모바일로 보지 않는 좁은 창에서는 WebGLInput 의 input 자체다. index.html 이 포커스
   순간 .mansion-keyboard-sheet 를 붙이고 --mansion-sheet-top 으로 자리를 준다.
   키보드가 뜨기 전에는 화면 위쪽(Safari 가 페이지를 밀어 올릴 이유가 없다) — 그동안은 숨겨 두고,
   키보드 높이를 안 뒤 키보드 바로 위에서 나타난다. 캔버스는 한 픽셀도 움직이지 않는다. */
html.mansion-handheld .mansion-keyboard-sheet {
  position: fixed !important;
  z-index: 32000 !important;
  top: var(--mansion-sheet-top) !important;
  bottom: auto !important;
  left: max(4vw, env(safe-area-inset-left)) !important;
  right: max(4vw, env(safe-area-inset-right)) !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  border: 1px solid rgba(232,194,112,.95) !important;
  border-radius: 14px !important;
  background: rgba(13,20,48,.98) !important;
  box-shadow: 0 10px 32px rgba(0,0,0,.52) !important;
  color: #fbf8ef !important;
  font: 18px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans KR", sans-serif !important;
  overflow: hidden !important;
  transition: top .24s ease;
  /* 키보드가 0.45초 안에 안 뜨면(하드웨어 키보드·데스크톱 좁은 창) 위쪽에서 그냥 나타난다 */
  animation: mansion-sheet-wait .18s ease .45s both;
}
html.mansion-handheld.mansion-keyboard-open .mansion-keyboard-sheet {
  transition: none;
  animation: mansion-sheet-rise .18s ease both;
}
@keyframes mansion-sheet-wait { from { opacity: 0; } to { opacity: 1; } }
@keyframes mansion-sheet-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

html.mansion-handheld div.mansion-keyboard-sheet {
  display: flex !important;
  align-items: stretch !important;
  padding: 0 !important;
}

/* 판 안의 입력칸(Unity) / 입력 요소 자체가 판인 경우(WebGLInput) — 글자 모양은 같다 */
html.mansion-handheld div.mansion-keyboard-sheet input,
html.mansion-handheld div.mansion-keyboard-sheet textarea,
html.mansion-handheld input.mansion-keyboard-sheet,
html.mansion-handheld textarea.mansion-keyboard-sheet {
  min-height: 54px !important;
  height: 54px !important;
  padding: 13px 15px !important;
  outline: none !important;
  color: #fbf8ef !important;
  font: 18px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans KR", sans-serif !important;
  caret-color: #f0cf88 !important;
  touch-action: manipulation !important;
  resize: none !important;
  -webkit-appearance: none !important;
  appearance: none !important;
}
html.mansion-handheld div.mansion-keyboard-sheet textarea,
html.mansion-handheld textarea.mansion-keyboard-sheet {
  height: min(20vh, 112px) !important;
}
html.mansion-handheld div.mansion-keyboard-sheet input,
html.mansion-handheld div.mansion-keyboard-sheet textarea {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  width: auto !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* Unity 의 OK 단추 — index.html 이 「완료」로 바꿔 단다 */
html.mansion-handheld .mansion-keyboard-done {
  position: static !important;
  flex: 0 0 auto !important;
  left: auto !important;
  top: auto !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  padding: 0 18px !important;
  border: 0 !important;
  border-left: 1px solid rgba(232,194,112,.35) !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: #f0cf88 !important;
  font: 600 16px/1 system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans KR", sans-serif !important;
  letter-spacing: .04em;
  touch-action: manipulation !important;
  -webkit-appearance: none !important;
  appearance: none !important;
}

@media (orientation: landscape) and (max-height: 520px) {
  #unity-loading { align-content: center; gap: 7px; }
  #unity-loading h1 { font-size: 22px; }
  .progress-track { width: min(310px, 64vw); }
  html.mansion-handheld div.mansion-keyboard-sheet input,
  html.mansion-handheld div.mansion-keyboard-sheet textarea,
  html.mansion-handheld input.mansion-keyboard-sheet,
  html.mansion-handheld textarea.mansion-keyboard-sheet { height: 50px !important; min-height: 50px !important; }
}
