:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --vermilion: #a63d2e;
  --gold: #f2ba56;
  --ink: #4d392b;
  --paper: #fff6dc;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; background: #211a16; overscroll-behavior: none; }
body { min-height: 100vh; min-height: 100dvh; display: flex; justify-content: center; color: var(--ink); }
button { font: inherit; -webkit-tap-highlight-color: transparent; }
.app-shell {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, 440px);
  height: min(100vh, 956px);
  height: min(100dvh, 956px);
  min-height: 560px;
  background: #70432e;
  container-type: size;
}
.shrine-background { position: absolute; inset: 0; z-index: -2; width: 100%; height: 100%; object-fit: cover; object-position: center; }
.scene-shade { position: absolute; inset: 0; z-index: -1; background: transparent; transition: background-color .25s ease; }
.app-shell.is-drawing .scene-shade { background: rgb(0 0 0 / 12%); }
.app-shell.modal-open .home-dog,
.app-shell.modal-open .home-controls,
.app-shell.modal-open .draw-overlay { visibility: hidden; }
.home-dog {
  position: absolute; z-index: 1; left: 50%; top: 53%;
  width: 40%; max-width: 180px; height: 23%;
  padding: 0; border: 0; background: transparent; transform: translateX(-50%);
  display: grid; place-items: end center; cursor: pointer;
}
.home-dog img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center bottom; filter: drop-shadow(0 3px 4px rgb(0 0 0 / 14%)); }
.home-dog:focus-visible, .red-gold-button:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.home-controls {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: max(24px, calc(var(--safe-bottom) + 16px));
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 0 14px;
}
.guide {
  margin: 0; max-width: 100%; padding: 10px 18px; border: 1px solid rgb(255 255 255 / 88%); border-radius: 999px;
  background: rgb(255 246 220 / 96%); color: #513522; font-size: 15px; font-weight: 700; text-align: center;
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}
.red-gold-button {
  min-height: 48px; min-width: 144px; padding: 10px 24px; border: 2px solid #f2ba56; border-radius: 999px;
  background: linear-gradient(180deg, #b03928, #751b12); color: #fff; font-size: 15px; font-weight: 750;
  box-shadow: 0 4px 8px rgb(0 0 0 / 22%); cursor: pointer;
}
.red-gold-button:active { transform: translateY(1px); }
.again-button[hidden] { display: none; }

.draw-overlay { position: absolute; z-index: 2; inset: 0; pointer-events: none; display: none; }
.app-shell.is-drawing .draw-overlay { display: block; }
.app-shell.is-drawing .home-dog img { animation: dog-rattle .24s ease-in-out 8 alternate; }
.omikuji-box {
  position: absolute; top: 53%; left: 60%; width: 25%; max-height: 20%; object-fit: contain;
  transform-origin: 50% 50%;
}
.app-shell.is-drawing .omikuji-box { animation: box-rattle .24s ease-in-out infinite alternate; }
.omikuji-rod {
  position: absolute; left: 73%; top: 61%; width: 6px; height: 62px; border-radius: 4px;
  background: linear-gradient(90deg, #ead9a7, #fff8dc, #d4bd83); box-shadow: 0 1px 3px rgb(30 20 10 / 35%);
  opacity: 0; transform: translate(-50%, -100%) rotate(-13deg); transform-origin: center bottom;
}
.app-shell.is-drawing .omikuji-rod.visible { opacity: 1; animation: rod-pop .38s cubic-bezier(.2,.8,.3,1) both; }
@keyframes dog-rattle { from { transform: rotate(-2deg) translateY(0); } to { transform: rotate(2deg) translateY(-4px); } }
@keyframes box-rattle { from { transform: rotate(-13deg); } to { transform: rotate(13deg); } }
@keyframes rod-pop { from { translate: 0 12px; opacity: 0; } to { translate: 0 -12px; opacity: 1; } }

.result-overlay { position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; padding: calc(var(--safe-top) + 14px) 0 calc(var(--safe-bottom) + 14px); background: rgb(0 0 0 / 42%); }
.result-overlay[hidden] { display: none; }
.omikuji-card {
  position: relative; isolation: isolate; display: flex; flex-direction: column; align-items: stretch; gap: 9px;
  width: calc(100% - 44px); max-width: 396px; height: 70%; height: 70dvh;
  max-height: calc(100% - 4px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  padding: 18px 21px 14px; border: 2px solid var(--fortune-color, var(--vermilion)); border-radius: 20px;
  background: linear-gradient(145deg, #fff9e6 0%, #f5e9c8 52%, #fff6dd 100%);
  box-shadow: 0 16px 36px rgb(0 0 0 / 34%); animation: card-in .38s cubic-bezier(.2,.85,.25,1) both;
}
.omikuji-card::-webkit-scrollbar { display: none; }
@keyframes card-in { from { opacity: 0; transform: scale(.94) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.fortune-superDog { --fortune-color: #c65e9c; border: 4px solid transparent; background: linear-gradient(145deg,#fff9e6,#f5e9c8,#fff6dd) padding-box, conic-gradient(#ff6c8d,#ffca55,#58c878,#52c9e8,#9878ef,#ff6c8d) border-box; }
.fortune-superGreat { --fortune-color: #c29131; border: 3px solid #d2a53e; }
.fortune-great { --fortune-color: #ad301f; }
.fortune-middle, .fortune-small, .fortune-normal, .fortune-late { --fortune-color: #a63d2e; }
.fortune-bad { --fortune-color: #474440; border-color: #55504b; }
.paw { position: absolute; z-index: -1; color: var(--fortune-color); opacity: .18; font-size: 25px; pointer-events: none; }
.paw-top { top: 16px; left: 16px; }
.paw-bottom { right: 16px; bottom: 14px; transform: rotate(25deg); }
.card-header { flex: 0 0 auto; color: #593a2a; text-align: center; font-family: Georgia, "Hiragino Mincho ProN", serif; font-size: 17px; font-weight: 800; }
.fortune-name {
  flex: 0 0 auto; margin: 0; color: var(--fortune-color); text-align: center; white-space: nowrap;
  font-family: Georgia, "Hiragino Mincho ProN", serif; font-size: 34px; line-height: 1.15; font-weight: 900;
}
.fortune-superDog .fortune-name { color: transparent; background: linear-gradient(90deg,#ef5e8b,#f4a844,#54a96b,#468fc2,#8763d3); background-clip: text; }
.result-dog-wrap { position: relative; flex: 0 0 140px; display: grid; place-items: center; isolation: isolate; }
.result-dog-wrap::before { content: ""; position: absolute; z-index: -1; inset: 0; margin: auto; width: 150px; height: 150px; border-radius: 50%; opacity: 0; pointer-events: none; }
.fortune-superDog .result-dog-wrap::before { opacity: 1; background: radial-gradient(circle, rgb(255 107 151 / 32%), rgb(255 217 91 / 20%) 38%, transparent 72%); }
.fortune-superGreat .result-dog-wrap::before { opacity: 1; background: radial-gradient(circle, rgb(255 201 57 / 38%), transparent 70%); }
.result-dog { display: block; width: 160px; height: 140px; object-fit: contain; }
.fortune-great .result-dog { filter: drop-shadow(0 0 8px rgb(250 210 85 / 40%)); }
.result-comment { flex: 0 0 auto; margin: 0; color: #4d392b; text-align: center; white-space: pre-line; overflow-wrap: normal; word-break: keep-all; font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif; font-size: 14px; line-height: 1.5; font-weight: 600; }
.card-divider { flex: 0 0 1px; width: 100%; margin: 2px 0; background: color-mix(in srgb, var(--fortune-color) 40%, transparent); }
.fortune-info { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; }
.info-row { min-width: 0; padding: 7px 10px; border-radius: 10px; background: rgb(255 255 255 / 45%); }
.info-label { display: block; margin-bottom: 3px; color: var(--fortune-color); font-size: 11px; line-height: 1.25; font-weight: 800; }
.info-value { display: flex; align-items: center; gap: 7px; min-width: 0; color: #493b31; font-size: 13px; line-height: 1.35; font-weight: 650; overflow-wrap: anywhere; }
.color-swatch { flex: 0 0 13px; width: 13px; height: 13px; border: 1px solid rgb(0 0 0 / 13%); border-radius: 50%; background: #7a4f33; }
.fortune-superDog .color-swatch { background: #c5a47b; }
.close-button { align-self: center; flex: 0 0 48px; margin-top: auto; width: 144px; }
.fortune-superDog .result-dog.fresh { animation: celebrate .45s ease-in-out 3; }
.fortune-superGreat .result-dog.fresh { animation: happy-hop .5s ease-in-out 2; }
.fortune-bad .result-dog.fresh { animation: sad-shake .45s ease-in-out 2; }
@keyframes celebrate { 50% { transform: translateY(-7px) rotate(5deg) scale(1.04); } }
@keyframes happy-hop { 50% { transform: translateY(-5px) scale(1.03); } }
@keyframes sad-shake { 25% { transform: translateX(-3px) rotate(-2deg); } 75% { transform: translateX(3px) rotate(2deg); } }
.confetti-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: -18px; width: 8px; height: 13px; border-radius: 2px; animation: confetti-fall var(--duration,2.4s) linear var(--delay,0s) forwards; }
@keyframes confetti-fall { to { transform: translate3d(var(--drift,10px),110vh,0) rotate(740deg); opacity: .9; } }

@media (max-width: 360px) {
  .omikuji-card { width: calc(100% - 28px); padding-left: 15px; padding-right: 15px; gap: 7px; }
  .result-dog-wrap { flex-basis: 112px; }
  .result-dog, .result-dog-wrap::before { width: 140px; height: 112px; }
  .fortune-name { font-size: 32px; }
}
@media (max-height: 720px) {
  .app-shell { min-height: 100dvh; }
  .omikuji-card { gap: 6px; padding-top: 12px; padding-bottom: 10px; }
  .result-dog-wrap { flex-basis: 110px; }
  .result-dog, .result-dog-wrap::before { height: 110px; }
  .fortune-info { gap: 5px; }
  .info-row { padding-top: 5px; padding-bottom: 5px; }
}
