html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #0d0c0a; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#root { position: absolute; left: 0; top: 0; width: 880px; height: 495px; transform-origin: 0 0; overflow: hidden; background: #f3ead8; color: #15130f; }
#cv { position: absolute; left: 0; top: 0; display: block; width: 880px; height: 495px; touch-action: none; }
#ui { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#ui .layer { position: absolute; inset: 0; pointer-events: none; }
#ui .btn, #ui .panel, #ui .edcontent, #ui .modal-back, #ui textarea, #ui input, #ui .scroll { pointer-events: auto; }

/* ---------- brush-stroke buttons ---------- */
.btn {
  position: relative; box-sizing: border-box; border: 0; margin: 0; padding: 0 14px;
  min-height: 56px; min-width: 56px;
  background-color: transparent;
  background-image: var(--btn-ink, url(assets/ui-button.webp));
  background-position: center; background-size: 104% 366%; background-repeat: no-repeat;
  color: #f3ead8; font: inherit; font-weight: 800; font-size: 20px; line-height: 1.1; letter-spacing: 0.02em;
  text-shadow: 1px 1px 0 #15130f, -1px -1px 0 #15130f, 1px -1px 0 #15130f, -1px 1px 0 #15130f, 0 2px 0 #15130f, 2px 3px 2px rgba(0, 0, 0, 0.4);
  cursor: pointer; display: flex; align-items: center; justify-content: center; text-align: center; gap: 6px;
  transition: transform 0.14s cubic-bezier(0.3, 1.6, 0.5, 1), filter 0.14s, opacity 0.14s;
  -webkit-tap-highlight-color: transparent; outline: none; white-space: nowrap;
}
.btn.red, .btn.on { background-image: var(--btn-red, url(assets/ui-button.webp)); }
.btn:active { transform: scale(0.93, 0.88); }
.btn.focus { transform: scale(1.06); filter: drop-shadow(0 0 3px #b3261e) drop-shadow(0 0 6px rgba(179, 38, 30, 0.85)); z-index: 2; }
@media (hover: hover) { .btn:hover { filter: brightness(1.35) drop-shadow(0 0 4px rgba(179, 38, 30, 0.7)); } }
.btn.small { font-size: 18px; }
.btn.big { flex-direction: column; gap: 4px; font-size: 30px; font-weight: 900; padding: 0 30px; }
.btn.big .sub { font-size: 15px; font-weight: 700; color: #e6d9c0; letter-spacing: 0.04em; }
.btn.name { justify-content: flex-start; padding-left: 20px; overflow: hidden; }
.btn.disabled { opacity: 0.38; filter: grayscale(1); cursor: default; }
.btn.danger { color: #ffc4b8; }
.btn.tab { opacity: 0.5; flex: 1; font-size: 19px; padding: 0 6px; }
.btn.tab.on { opacity: 1; }

/* paper cards (lists, slots, rivals) */
.btn.item, .btn.slot, .btn.card {
  background-image: none; background-color: rgba(250, 245, 234, 0.82);
  border: 2px solid rgba(21, 19, 15, 0.65); border-radius: 3px 8px 4px 9px;
  color: #15130f; text-shadow: none; font-weight: 800;
  box-shadow: 2px 3px 0 rgba(21, 19, 15, 0.18);
}
.btn.item { justify-content: flex-start; padding: 0 10px; font-size: 19px; gap: 8px; width: 100%; flex: none; }
.btn.item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.btn.item .tag { font-size: 13px; color: #b3261e; font-weight: 800; }
.btn.item.sel, .btn.slot.sel { background-color: #15130f; color: #f3ead8; border-color: #15130f; }
.btn.item.sel .tag { color: #ff9f8f; }
.btn.slot { justify-content: flex-start; padding: 0 8px; font-size: 17px; gap: 6px; overflow: hidden; }
.btn.slot.empty { border-style: dashed; color: #8a8276; }
.btn.slot.armed { border-color: #b3261e; box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.55); }
.btn.slot .snm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.seal { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 24px; height: 24px; border-radius: 4px; background: #b3261e; color: #f3ead8; font-size: 15px; font-weight: 900; text-shadow: none; transform: rotate(-4deg); }
.btn.card { flex-direction: column; align-items: flex-start; justify-content: center; gap: 3px; padding: 6px 14px; white-space: normal; text-align: left; }
.btn.card .cn { font-size: 20px; font-weight: 900; }
.btn.card .cd { font-size: 14px; font-weight: 700; color: #5a544b; }
.btn.card .cs { font-size: 13px; font-weight: 700; color: #b3261e; }
.btn.card.foe { border-style: dashed; }

/* ---------- panels ---------- */
.panel { box-sizing: border-box; background: rgba(243, 236, 222, 0.97); border: 3px solid #15130f; border-radius: 4px 10px 6px 12px; box-shadow: 3px 5px 0 rgba(21, 19, 15, 0.22); }
#root.pimg .panel { border: 22px solid transparent; border-radius: 0; background: none; border-image: var(--panel-img) 60 fill / 22px / 0 stretch; box-shadow: none; }
.scroll { overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.scroll::-webkit-scrollbar, .edcontent::-webkit-scrollbar { width: 6px; }
.scroll::-webkit-scrollbar-thumb, .edcontent::-webkit-scrollbar-thumb { background: rgba(21, 19, 15, 0.35); border-radius: 3px; }
.list { display: flex; flex-direction: column; gap: 6px; padding: 2px 6px 24px 2px; box-sizing: border-box; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 4px 6px 30px 4px; box-sizing: border-box; }
.grid3 .btn.card { min-height: 92px; }

/* ---------- editor ---------- */
.edpanel { display: flex; flex-direction: column; gap: 6px; padding: 8px 6px 6px 8px; }
#root.pimg .edpanel { padding: 0; }
.tabs { display: flex; gap: 4px; flex: none; }
.edcontent { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 2px 6px 40px 2px; display: flex; flex-direction: column; gap: 8px; }
.esec { flex: none; font-size: 17px; font-weight: 900; color: #b3261e; border-bottom: 2px solid rgba(21, 19, 15, 0.5); padding: 6px 2px 2px; margin-top: 4px; }
.erow { flex: none; display: flex; flex-direction: column; gap: 3px; }
.elabel { font-size: 15px; font-weight: 800; color: #5a544b; padding-left: 2px; }
.estep { flex: none; display: flex; gap: 6px; align-items: center; }
.evalue { flex: 1; min-width: 0; height: 52px; display: flex; align-items: center; justify-content: center; font-size: 19px; font-weight: 900; background: rgba(255, 255, 255, 0.5); border: 2px solid rgba(21, 19, 15, 0.55); border-radius: 3px 7px 4px 6px; white-space: nowrap; overflow: hidden; }
.btn.sq { width: 56px; min-width: 56px; height: 56px; padding: 0; font-size: 21px; flex: none; }
.btn.sq.wide { width: auto; flex: 1; font-size: 16px; padding: 0 6px; }
.btn.wide2 { width: 100%; flex: none; font-size: 18px; }
.btn.wide3 { flex: 1; min-width: 0; font-size: 16px; padding: 0 6px; }
.chips { flex: none; display: flex; flex-wrap: wrap; gap: 6px; }
.btn.chip { flex: 1 1 40%; min-width: 0; font-size: 17px; padding: 0 8px 0 24px; }
.btn.chip::after { content: ""; position: absolute; left: 12px; top: 50%; width: 11px; height: 11px; margin-top: -5px; border-radius: 50%; background: var(--dot, transparent); box-shadow: 0 0 0 2px #f3ead8; }
.btn.chip.add { padding-left: 8px; }
.einfo { flex: none; font-size: 14px; line-height: 1.45; color: #3a352e; padding: 0 2px; }
.tlctrl { display: flex; gap: 6px; align-items: center; }

/* ---------- modal ---------- */
.modal-back { position: absolute; inset: 0; background: rgba(20, 18, 15, 0.5); display: flex; align-items: center; justify-content: center; z-index: 30; animation: fadeIn 0.18s ease-out; }
.modal { position: relative; width: 560px; max-height: 470px; display: flex; flex-direction: column; gap: 12px; padding: 18px 24px; animation: pop 0.28s cubic-bezier(0.3, 1.5, 0.5, 1); }
.modal h2 { margin: 0; font-size: 28px; font-weight: 900; color: #15130f; text-shadow: 2px 2px 0 rgba(179, 38, 30, 0.25); }
.modal .mbody { font-size: 17px; line-height: 1.5; color: #2a2620; overflow-y: auto; touch-action: pan-y; max-height: 270px; }
.modal .mbody p { margin: 0 0 8px; }
.modal .mbody b { color: #b3261e; }
.modal .mbtns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; flex: none; }
.modal .mbtns .btn { min-width: 150px; }
.modal .tgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-height: 250px; overflow-y: auto; touch-action: pan-y; padding: 4px; }
.modal .tgrid .btn { font-size: 18px; padding: 0 8px; }
.field { box-sizing: border-box; width: 100%; font: inherit; font-size: 20px; font-weight: 800; color: #15130f; background: rgba(255, 255, 255, 0.7); border: 2px solid #15130f; border-radius: 3px 8px 4px 7px; padding: 10px 12px; outline: none; -webkit-user-select: text; user-select: text; touch-action: manipulation; }
textarea.field { height: 120px; resize: none; font-size: 13px; font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }
.field:focus { border-color: #b3261e; box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.25); }

/* results panel */
.result { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 20px 26px; animation: drop 0.36s cubic-bezier(0.3, 1.5, 0.5, 1); }
.result h2 { margin: 0; font-size: 38px; font-weight: 900; color: #b3261e; text-shadow: 2px 2px 0 rgba(21, 19, 15, 0.2); }
.result p { margin: 0; font-size: 18px; font-weight: 700; text-align: center; color: #2a2620; }
.result .mbtns { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }
.result .mbtns .btn { min-width: 140px; }

/* ---------- toast ---------- */
.toast { position: absolute; left: 50%; top: 66px; transform: translate(-50%, -16px); opacity: 0; background: rgba(21, 19, 15, 0.9); color: #f3ead8; padding: 10px 22px; font-size: 18px; font-weight: 800; border-radius: 3px 9px 4px 8px; pointer-events: none; transition: opacity 0.2s, transform 0.25s cubic-bezier(0.3, 1.5, 0.5, 1); z-index: 50; white-space: nowrap; max-width: 760px; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 0 0 2px #b3261e inset; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- ink wipe ---------- */
#wipe { position: absolute; top: -2px; bottom: -2px; left: -12%; width: 124%; pointer-events: none; z-index: 40; visibility: hidden; transform: translateX(-105%);
  background: linear-gradient(90deg, rgba(21, 19, 15, 0) 0%, rgba(21, 19, 15, 0.85) 4%, #15130f 9%, #15130f 91%, rgba(21, 19, 15, 0.85) 96%, rgba(21, 19, 15, 0) 100%); }
#wipe.in { visibility: visible; animation: wipeIn 0.26s cubic-bezier(0.6, 0, 0.9, 0.5) forwards; }
#wipe.out { visibility: visible; animation: wipeOut 0.38s cubic-bezier(0.2, 0.6, 0.4, 1) forwards; }
@keyframes wipeIn { from { transform: translateX(-105%); } to { transform: translateX(0); } }
@keyframes wipeOut { from { transform: translateX(0); } to { transform: translateX(105%); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(0.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes drop { 0% { transform: translateY(-60px) scale(0.9); opacity: 0; } 100% { transform: none; opacity: 1; } }
.enter { animation: drop 0.32s cubic-bezier(0.3, 1.5, 0.5, 1) both; }

/* ---------- intro cutscene ---------- */
#introBox { position: fixed; inset: 0; display: none; z-index: 100; background: #000 url(assets/title-bg.webp) center / cover no-repeat; }
#introBox.on { display: block; }
#vid { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: transparent; }
#skipBtn { position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); min-width: 130px; height: 56px; z-index: 2; }
