:root {
  --ink: #123a36;
  --muted: #587773;
  --primary: #0f766e;
  --primary-dark: #0c625c;
  --border: #b9ddd7;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #dcfaf3; }

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: #ecfdf9;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
}
body.is-dialog-open { overflow: hidden; }

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
[hidden] { display: none !important; }

.game-shell {
  position: relative;
  display: grid;
  min-height: 100svh;
  place-items: center;
  overflow-x: hidden;
  padding: 22px 14px;
  background:
    radial-gradient(circle at 12% 8%, rgba(45, 212, 191, 0.24), transparent 30%),
    radial-gradient(circle at 92% 88%, rgba(251, 191, 36, 0.21), transparent 30%),
    linear-gradient(160deg, #e7fcf7 0%, #f9fffd 48%, #fff9ea 100%);
}

.ambient {
  position: fixed;
  border-radius: 999px;
  opacity: 0.55;
  pointer-events: none;
}
.ambient-one { width: 170px; height: 170px; left: -85px; top: 18%; background: #5eead4; }
.ambient-two { width: 130px; height: 130px; right: -55px; bottom: 8%; background: #fcd34d; }

.game-card, .state-card {
  position: relative;
  z-index: 1;
  width: min(100%, 500px);
  border: 1px solid rgba(13, 148, 136, 0.22);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 26px 70px rgba(15, 118, 110, 0.17), 0 2px 8px rgba(18, 58, 54, 0.08);
  padding: clamp(18px, 4vw, 30px);
  backdrop-filter: blur(12px);
}

.state-card {
  display: grid;
  max-width: 430px;
  justify-items: center;
  gap: 13px;
  padding: 42px 28px;
  text-align: center;
}
.state-card h1, .state-card p { margin: 0; }
.state-card p { color: var(--muted); font-size: 0.95rem; }
.state-symbol { border-radius: 999px; background: #fff1d6; color: #8c4b08; padding: 7px 11px; font-size: 0.82rem; font-weight: 900; }

.spinner {
  width: 34px;
  height: 34px;
  border: 4px solid #b9ddd7;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.game-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.eyebrow { margin: 0 0 3px; color: var(--primary); font-size: 0.84rem; font-weight: 800; letter-spacing: 0.05em; }
h1 { margin: 0; font-size: clamp(1.45rem, 6vw, 2rem); font-weight: 900; letter-spacing: -0.04em; }
.question-number { flex: 0 0 auto; border-radius: 999px; background: #fff4d5; color: #8a4b08; padding: 7px 11px; font-size: 0.8rem; font-weight: 800; }
.guide { min-height: 24px; margin: 16px 0 12px; color: #4a6f6a; text-align: center; font-size: 0.95rem; font-weight: 700; }

.maze-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(4px, 1.5vw, 7px);
  width: min(100%, 400px);
  margin: 0 auto;
  touch-action: none;
  user-select: none;
}
.maze-board.is-validating { opacity: 0.72; pointer-events: none; }
.maze-cell {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  min-width: 0;
  border: 2px solid #71c9bf;
  border-radius: clamp(8px, 2.4vw, 13px);
  background: #fff;
  color: #173f3b;
  box-shadow: 0 2px 0 rgba(15, 118, 110, 0.09);
  cursor: crosshair;
  transition: transform 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
}
.maze-cell:active { transform: scale(0.96); }
.maze-cell.is-start { background: #dcfce7; border-color: #3aad73; }
.maze-cell.is-goal { background: #ffe4e9; border-color: #ef8294; }
.maze-cell.is-traced { border-color: #0f9e91; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.62); }
.path-overlay { position: absolute; z-index: 2; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.path-segment { stroke: #69b3a3; stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; stroke-dasharray: 1; animation: draw-segment 0.12s ease-out both; }
.path-segment.without-animation { animation: none; stroke-dashoffset: 0; }
.path-start { fill: #69b3a3; }
.cell-character { position: relative; z-index: 3; font-size: clamp(1.15rem, 6vw, 1.75rem); font-weight: 900; line-height: 1; }
.cell-badge { position: absolute; z-index: 4; border-radius: 999px; color: #fff; font-size: clamp(0.42rem, 1.8vw, 0.59rem); font-weight: 900; line-height: 1; padding: 3px 4px; }
.start-badge { left: 3px; top: 3px; background: #13854d; }
.goal-badge { right: 3px; bottom: 3px; background: #d83f5f; }

.reset-button, .primary-button, .secondary-button {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}
.puzzle-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 15px; }
.puzzle-actions button { display: flex; min-height: 44px; align-items: center; justify-content: center; gap: 5px; border-radius: 12px; font-size: 0.85rem; font-weight: 900; white-space: nowrap; }
.reset-button { margin: 0; }
.reset-button:disabled { cursor: wait; opacity: 0.62; }
.secondary-button { background: #dff8f1; color: #145e58; }
.share-puzzle-button { border: 0; background: #0f766e; color: #fff; box-shadow: 0 5px 12px rgba(15, 118, 110, 0.2); cursor: pointer; }
.share-puzzle-button:hover { background: #0a655e; transform: translateY(-1px); }
.share-puzzle-button:disabled { cursor: wait; opacity: 0.7; transform: none; }
.primary-button { background: var(--primary); color: #fff; }
.primary-button:hover { background: var(--primary-dark); }

.answer-panel { margin-top: 17px; border-radius: 18px; background: #f1fbf8; padding: 15px; }
.question-copy { margin: 0 0 12px; text-align: center; font-size: 0.95rem; font-weight: 800; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.choice-grid button { min-height: 44px; border: 1px solid var(--border); border-radius: 11px; background: #fff; color: var(--ink); font-size: 1rem; font-weight: 800; cursor: pointer; }
.app-link { display: flex; min-height: 44px; align-items: center; justify-content: center; gap: 8px; border-radius: 12px; color: var(--primary); font-weight: 800; text-decoration: none; }
.app-link:hover { background: #edf9f6; }
.primary-link { margin-top: 6px; background: var(--primary); color: #fff; padding: 0 18px; }
footer { margin-top: 16px; border-top: 1px solid #d5ebe7; padding-top: 13px; }
footer p { margin: 0; color: #6a8581; text-align: center; font-size: 0.78rem; }
.store-promo { display: grid; justify-items: center; gap: 4px; margin-top: 13px; border-radius: 16px; background: #f1fbf8; padding: 13px; text-align: center; }
.store-promo strong { color: #145e58; font-size: 0.95rem; }
.store-promo > span { color: #6a8581; font-size: 0.72rem; }
.store-links { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; width: 100%; margin-top: 8px; }
.store-link { display: inline-flex; min-height: 48px; align-items: center; justify-content: center; line-height: 0; text-decoration: none; transition: transform 0.12s ease, filter 0.12s ease; }
.store-link[hidden] { display: none; }
.store-link:hover { filter: brightness(1.06); transform: translateY(-2px); }
.store-badge-image { display: block; width: auto; height: 48px; max-width: 100%; }
.privacy-link { margin-top: 10px; }
.privacy-link a { color: #55736f; font-size: 0.7rem; text-underline-offset: 2px; }

.result-dialog { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; }
.result-backdrop { position: absolute; inset: 0; background: rgba(18, 58, 54, 0.48); backdrop-filter: blur(5px); animation: fade-in 0.2s ease-out both; }
.result-card {
  position: relative;
  width: min(100%, 420px);
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 28px;
  background: linear-gradient(145deg, #fff9df 0%, #fff1df 52%, #fff1f4 100%);
  box-shadow: 0 26px 70px rgba(120, 70, 20, 0.3);
  animation: result-pop 0.42s cubic-bezier(0.22, 1.35, 0.5, 1) both;
}
.result-content { position: relative; z-index: 2; padding: 24px 22px 20px; }
.result-heading { display: flex; align-items: center; justify-content: center; gap: 9px; color: #8a481d; }
.result-heading h2 { margin: 0; font-size: clamp(1.8rem, 8vw, 2.35rem); font-weight: 950; letter-spacing: 0.02em; }
.celebration-icon { display: inline-block; font-size: 1.75rem; animation: celebrate 0.65s ease-out 0.12s both; }
.answer-reveal {
  margin-top: 16px;
  border: 1px solid rgba(236, 158, 65, 0.52);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(255, 252, 235, 0.98), rgba(255, 241, 219, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  padding: 15px 16px 14px;
  text-align: center;
}
.answer-label { margin: 0; color: #9b6b43; font-size: 0.8rem; font-weight: 800; }
.answer-reveal strong { display: block; margin-top: 1px; color: #3f3027; font-size: clamp(2rem, 10vw, 2.7rem); font-weight: 950; line-height: 1.25; }
.answer-caption { display: inline-flex; margin: 10px 0 0; border: 1px solid #f2c45e; border-radius: 999px; background: linear-gradient(90deg, #fff0ac, #ffd9a8); color: #804619; padding: 6px 12px; font-size: 0.8rem; font-weight: 900; }
.result-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.result-actions button { min-height: 48px; border-radius: 14px; font-size: 0.95rem; font-weight: 900; }
.share-button { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; background: linear-gradient(135deg, #f07b45, #e8526c); color: #fff; box-shadow: 0 8px 18px rgba(216, 73, 82, 0.25); cursor: pointer; }
.share-button:hover { filter: brightness(0.97); transform: translateY(-1px); }
.share-button:disabled { cursor: wait; opacity: 0.7; transform: none; }
.replay-button, .retry-button { min-height: 42px !important; border: 1px solid #e9ad79; border-radius: 12px !important; background: rgba(255, 255, 255, 0.62); color: #8a4c24; padding: 0 7px; font-size: 0.82rem !important; cursor: pointer; }
.retry-button { border-color: rgba(233, 173, 121, 0.7); background: rgba(255, 255, 255, 0.42); }
.retry-button:hover { background: rgba(255, 255, 255, 0.8); }
.share-status { min-height: 20px; margin: 10px 0 0; color: #86542f; text-align: center; font-size: 0.8rem; font-weight: 800; }
.result-store { margin-top: 4px; border-top: 1px solid rgba(213, 159, 94, 0.42); padding-top: 11px; }
.result-store > p { margin: 0; color: #8a4c24; text-align: center; font-size: 0.8rem; font-weight: 900; }
.result-star { position: absolute; z-index: 1; color: rgba(248, 190, 65, 0.52); line-height: 1; pointer-events: none; }
.result-star-one { right: -18px; top: -17px; font-size: 7.2rem; transform: rotate(12deg); }
.result-star-two { left: -9px; bottom: -16px; color: rgba(244, 156, 92, 0.34); font-size: 5rem; transform: rotate(-16deg); }
.confetti { position: absolute; z-index: 3; width: 9px; height: 22px; border-radius: 999px; pointer-events: none; animation: confetti-drop 0.75s ease-out both; }
.confetti-one { left: 10%; top: -22px; background: #f59e0b; transform: rotate(23deg); animation-delay: 0.08s; }
.confetti-two { left: 29%; top: -24px; background: #2dd4bf; transform: rotate(-18deg); animation-delay: 0.2s; }
.confetti-three { right: 25%; top: -22px; background: #fb7185; transform: rotate(34deg); animation-delay: 0.14s; }
.confetti-four { right: 8%; top: -20px; background: #60a5fa; transform: rotate(-28deg); animation-delay: 0.25s; }

.share-dialog { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 20px; }
.share-dialog-backdrop { position: absolute; inset: 0; background: rgba(18, 58, 54, 0.48); backdrop-filter: blur(5px); animation: fade-in 0.2s ease-out both; }
.share-dialog-card { position: relative; width: min(100%, 390px); border: 1px solid rgba(15, 118, 110, 0.2); border-radius: 24px; background: #fff; box-shadow: 0 24px 60px rgba(18, 58, 54, 0.26); padding: 23px 20px 18px; animation: result-pop 0.26s ease-out both; }
.share-dialog-card h2 { margin: 0; color: #145e58; text-align: center; font-size: 1.35rem; font-weight: 950; }
.share-dialog-card > p { margin: 7px 0 0; color: #587773; text-align: center; font-size: 0.82rem; font-weight: 700; }
.share-steps { display: grid; gap: 10px; margin: 18px 0 0; padding: 0; list-style: none; }
.share-step { display: grid; grid-template-columns: 31px minmax(0, 1fr); gap: 10px; border: 1px solid #d5ebe7; border-radius: 15px; background: #f8fdfc; padding: 12px; }
.share-step-number { display: grid; width: 29px; height: 29px; place-items: center; border-radius: 999px; background: #dff8f1; color: #0f766e; font-size: 0.86rem; font-weight: 950; }
.share-step strong { display: block; color: #123a36; font-size: 0.9rem; }
.share-step p { margin: 3px 0 9px; color: #6a8581; font-size: 0.72rem; font-weight: 700; }
.copy-share-text-button, .share-image-button { width: 100%; min-height: 40px; border: 0; border-radius: 10px; font-size: 0.84rem; font-weight: 900; cursor: pointer; }
.copy-share-text-button { background: #dff8f1; color: #145e58; }
.copy-share-text-button.is-complete { background: #d8f7e4; color: #187647; }
.share-image-button { background: #0f766e; color: #fff; box-shadow: 0 4px 10px rgba(15, 118, 110, 0.2); }
.share-image-button:disabled { background: #b7d7d2; box-shadow: none; cursor: not-allowed; }
.share-dialog-status { min-height: 18px; margin: 11px 0 0; color: #8a4c24; text-align: center; font-size: 0.75rem; font-weight: 800; }
.share-dialog-close { display: block; margin: 3px auto 0; border: 0; background: transparent; color: #587773; padding: 7px 14px; font-size: 0.78rem; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes draw-segment { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes result-pop { from { opacity: 0; transform: translateY(22px) scale(0.84); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes celebrate { from { opacity: 0; transform: scale(0.35) rotate(-22deg); } to { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes confetti-drop { 0% { opacity: 0; translate: 0 0; } 30% { opacity: 1; } 100% { opacity: 0.9; translate: 0 118px; rotate: 150deg; } }

@media (max-width: 390px) {
  .game-shell { padding: 8px; }
  .game-card { border-radius: 20px; padding: 15px 12px; }
  .guide { margin-top: 11px; }
  .answer-panel { margin-top: 12px; padding: 12px; }
  .result-dialog { padding: 12px; }
  .result-content { padding: 21px 15px 16px; }
  .result-actions { gap: 8px; }
  .result-actions button { font-size: 0.86rem; }
  .store-badge-image { height: 43px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
