@font-face {
  font-family: "Gamay Editorial";
  src: url("Gamay Editorial Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Neogrotesk Ess Alt";
  src: url("NeogroteskEssAlt-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f1efe6;
  --paper-strong: #e8e3d5;
  --text-dark: #1c1c1c;
  --panel-bg: rgba(255, 255, 255, 0.2);
  --panel-border: rgba(0, 0, 0, 0.12);
  --red: #b50d0d;
  --red-2: #c51f1f;
  --orange: #f26b1c;
  --yellow: #f1d000;
  --blue: #0d4ea2;
  --green: #0d5f2d;
  --shadow: rgba(28, 28, 28, 0.18);
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: "Neogrotesk Ess Alt", sans-serif;
  background: #ffffff;
  color: var(--text-dark);
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    linear-gradient(90deg, rgba(181, 13, 13, 0.06) 1px, transparent 1px),
    linear-gradient(#fff 0 0);
  background-size: 48px 48px;
}

.site-header,
.site-footer {
  width: min(98vw, 1200px);
  display: flex;
  align-items: center;
}

.site-header {
  min-height: 54px;
  justify-content: space-between;
  border-bottom: 1px solid rgba(28, 28, 28, 0.16);
}

.game-logo {
  display: block;
  width: min(170px, 24vw);
  max-height: 48px;
  object-fit: contain;
}

.header-copy {
  display: grid;
  gap: 2px;
  margin-left: auto;
  margin-right: 24px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.header-copy span,
.header-mark,
.site-footer {
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.header-copy span {
  color: var(--red);
}

.header-copy strong {
  font-family: "Gamay Editorial", serif;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
}

.header-mark {
  color: rgba(28, 28, 28, 0.55);
}

.page-shell {
  flex: 0 1 auto;
}

.page-shell {
  position: relative;
  width: min(98vw, 1200px);
  aspect-ratio: 16 / 9;
  border-radius: 0;
  overflow: visible;
  box-shadow: 0 10px 28px rgba(28, 28, 28, 0.14);
  background: var(--paper);
}

@media (orientation: landscape) {
  body {
    justify-content: flex-start;
    padding: 8px 12px 10px;
  }

  .site-header,
  .site-footer {
    width: min(96vw, 1000px);
  }

  .page-shell {
    width: min(92vw, 1000px);
    max-height: calc(100vh - 110px);
  }
}

@media (orientation: landscape) and (max-width: 900px) {
  body {
    gap: 0;
    padding: 0;
    justify-content: center;
  }

  .site-header,
  .site-footer {
    display: none;
  }

  .page-shell {
    width: 100vw;
    height: auto;
    max-width: 100vw;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 0;
  }

  canvas {
    width: 100%;
    height: auto;
  }
}

.site-footer {
  min-height: 28px;
  gap: 12px;
  color: rgba(28, 28, 28, 0.65);
}

.site-footer > span:first-child {
  color: var(--green);
  font-weight: 700;
}

.footer-line {
  flex: 1;
  height: 1px;
  background: rgba(28, 28, 28, 0.18);
}

.social-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 5px 14px;
}

.social-link {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: var(--text-dark);
  text-decoration: none;
  transition: color 0.15s ease, transform 0.15s ease;
}

.social-link img {
  display: block;
  width: 15px;
  height: 15px;
}

.site-link {
  width: auto;
  padding: 0 2px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.linkedin-link > span:first-child {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 2px;
  background: var(--text-dark);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.social-link:hover,
.social-link:focus-visible {
  color: var(--red);
  transform: translateY(-1px);
}

.social-link:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-shell::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--red) 0 20%, var(--orange) 20% 40%, var(--yellow) 40% 60%, var(--blue) 60% 80%, var(--green) 80% 100%);
  z-index: 3;
  pointer-events: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: linear-gradient(180deg, #f0efe7 0%, #f0efe7 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
  touch-action: none;
}

.hud {
  position: absolute;
  top: 14px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  z-index: 2;
  pointer-events: none;
}

.hud > div {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 0;
  padding: 5px 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dark);
  text-transform: uppercase;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.06);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.hud > div.is-hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  pointer-events: none;
}

.health-display #healthCounter {
  display: inline-flex;
  gap: 3px;
  font-size: 1.15rem;
  line-height: 1;
  letter-spacing: 0;
}

.heart {
  display: inline-block;
  transition: color 0.18s ease, transform 0.18s ease;
}

.heart.is-full {
  color: var(--red);
}

.heart.is-empty {
  color: rgba(181, 13, 13, 0.3);
}

.debug-hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
  display: grid;
  gap: 4px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(28, 28, 28, 0.16);
  color: var(--text-dark);
  font-family: "Neogrotesk Ess Alt", sans-serif;
  font-size: 0.7rem;
  line-height: 1.2;
  pointer-events: none;
}

.debug-hud.is-hidden {
  display: none;
}

.debug-hud .label {
  min-width: 48px;
  margin-right: 5px;
  font-size: 0.6rem;
}

.label {
  display: inline-block;
  margin-right: 8px;
  color: var(--text-dark);
  text-transform: uppercase;
  font-size: 0.6rem;
  font-family: "Neogrotesk Ess Alt", sans-serif;
  font-weight: 400;
}

.number-progress {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 3px;
  border: 1px solid rgba(109, 76, 65, 0.45);
  border-radius: 50%;
  background: rgba(255, 231, 163, 0.38);
  color: rgba(109, 76, 65, 0.55);
  font-size: 0.78rem;
  line-height: 1;
  letter-spacing: 0;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.number-progress:last-child {
  margin-right: 0;
}

.number-progress.is-collected {
  border-color: #b97849;
  background: #ffe7a3;
  color: #6d4c41;
  box-shadow: 0 0 8px rgba(255, 216, 105, 0.75);
  transform: translateY(-1px);
}

.message-box {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  background: rgba(241, 239, 230, 0.72);
  backdrop-filter: blur(2px);
  transition: opacity 0.2s ease;
  z-index: 100;
  overflow: auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.message-box > div {
  width: min(100%, 620px);
  max-width: 100%;
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 18px 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.94), rgba(247,242,228,0.9));
  border: 1px solid rgba(28, 28, 28, 0.14);
  box-shadow: 0 18px 40px rgba(28, 28, 28, 0.22), inset 0 1px 0 rgba(255,255,255,0.9);
  gap: 6px !important;
  border-radius: 28px;
}

.message-box.hidden {
  opacity: 0;
  pointer-events: none;
}

.message-box h1 {
  margin: 0 0 12px;
  font-size: clamp(2.1rem, 4vw, 3.8rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--red);
  font-family: "Gamay Editorial", serif;
  font-weight: 700;
  line-height: 0.92;
}

.message-box h2 {
  font-family: "Gamay Editorial", serif;
  font-weight: 700;
}

.message-box p {
  margin: 0 0 20px;
  font-size: 1rem;
  color: var(--text-dark);
  font-family: "Neogrotesk Ess Alt", sans-serif;
  font-weight: 400;
  letter-spacing: 0.04em;
  max-width: 560px;
}

.message-box a {
  color: var(--red);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.message-box a:hover,
.message-box a:focus-visible {
  color: var(--red-2);
}

.title-card,
.game-over-card {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 6px 8px 10px;
  text-align: center;
}

.game-over-card {
  transform: translateY(-clamp(16px, 5vh, 48px));
}

.title-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(181, 13, 13, 0.12), rgba(242, 107, 28, 0.12));
  border: 1px solid rgba(181, 13, 13, 0.2);
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.7rem;
  font-weight: 700;
}

.title-badge.game-over-badge {
  background: linear-gradient(90deg, rgba(13, 78, 162, 0.10), rgba(13, 95, 45, 0.10));
  border-color: rgba(13, 78, 162, 0.2);
  color: var(--blue);
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}

#musicButton {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 44px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  background: rgba(28, 28, 28, 0.06);
  color: var(--text-dark);
  border: 1px solid rgba(28, 28, 28, 0.12);
  box-shadow: none;
}

#musicButton:hover {
  background: rgba(28, 28, 28, 0.12);
}

.message-box input {
  width: min(100%, 260px);
  padding: 8px 10px;
  border: 1px solid rgba(28, 28, 28, 0.28);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text-dark);
  font: inherit;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.ranking-form {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: min(100%, 300px);
}

.ranking-form-title {
  margin-bottom: 4px !important;
  font-weight: 700;
}

.ranking-form label {
  width: min(100%, 260px);
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ranking-form .consent-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: min(100%, 260px);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.72rem;
}

.consent-label input {
  width: auto;
  flex: 0 0 auto;
  margin: 2px 0 0;
}

.form-error {
  min-height: 1.1em;
  margin: 0 !important;
  color: var(--red) !important;
  font-size: 0.76rem !important;
  letter-spacing: 0 !important;
}

#rankingBoard {
  width: min(100%, 300px);
  max-height: 220px;
  overflow: hidden;
}

#rankingBoard h2 {
  margin: 4px 0 8px;
}

#rankingBoard.is-expanded {
  max-height: min(52vh, 420px);
  overflow-y: auto;
  padding-right: 8px;
}

.secondary-button {
  padding: 9px 16px;
  background: rgba(28, 28, 28, 0.08);
  color: var(--text-dark);
  box-shadow: none;
}

.secondary-button:hover {
  background: rgba(28, 28, 28, 0.14);
  box-shadow: none;
}

#rankingBoard ol {
  margin: 0;
  padding-left: 26px;
  text-align: left;
}

#rankingBoard li {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 3px 0;
}

.touch-controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  min-height: 50px;
  padding: 0;
  display: none;
  justify-content: space-between;
  align-items: end;
  z-index: 1;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom);
}

.direction-controls {
  display: flex;
  gap: 6px;
}

.touch-button {
  width: 80px;
  height: 80px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  background: rgba(28, 28, 28, 0.64);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.22);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

.touch-button:active,
.touch-button.is-pressed {
  background: var(--red);
  transform: scale(0.94);
}

.touch-jump {
  margin-left: auto;
  margin-right: 0;
}

button {
  border: none;
  border-radius: 0;
  padding: 12px 26px;
  font-size: 0.9rem;
  font-family: "Neogrotesk Ess Alt", sans-serif;
  font-weight: 400;
  cursor: pointer;
  background: linear-gradient(90deg, var(--red) 0%, var(--red-2) 100%);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  box-shadow: 0 10px 20px rgba(181, 13, 13, 0.18);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 12px 22px rgba(181, 13, 13, 0.22);
}

@media (max-width: 640px) {
  body {
    width: 100%;
    min-height: 100dvh;
    overflow: hidden;
    padding: 0;
    background: #ffffff;
    gap: 6px;
  }

  .site-header,
  .site-footer {
    width: calc(100vw - 20px);
  }

  .site-header {
    min-height: 40px;
  }

  .game-logo {
    width: min(130px, 36vw);
    max-height: 34px;
  }

  .header-copy {
    margin-right: 10px;
  }

  .header-copy span,
  .header-mark,
  .site-footer {
    font-size: 0.48rem;
  }

  .header-copy strong {
    font-size: 0.78rem;
  }

  .site-footer {
    min-height: 22px;
    gap: 6px;
  }

  .social-links {
    justify-content: center;
    gap: 3px 8px;
  }

  .social-link {
    width: 20px;
    height: 20px;
  }

  .site-link {
    width: auto;
    font-size: 0.46rem;
  }

  .social-link img {
    width: 13px;
    height: 13px;
  }

  .game-logo {
    margin-top: 0;
  }

  .page-shell {
    width: 100%;
    height: auto;
    max-width: 1200px;
    max-height: none;
    margin-bottom: 96px;
    aspect-ratio: 16 / 9;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    border-bottom: 0;
  }

  .hud {
    top: 10px;
    left: 10px;
    right: 10px;
    gap: 5px;
    justify-content: flex-start;
  }

  .hud > div {
    padding: 3px 5px;
    font-size: 0.58rem;
  }

  .label {
    display: block;
    margin-right: 0;
    font-size: 0.48rem;
  }

  .touch-controls {
    display: flex;
    top: 100%;
    bottom: auto;
    left: 0;
    right: 0;
    min-height: 96px;
    padding: 8px max(12px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom));
    align-items: center;
    background: #ffffff;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
  }

  .message-box {
    padding: 12px;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .message-box img {
    max-width: 55vw !important;
    max-height: 20svh;
    object-fit: contain;
  }

  .message-box p {
    font-size: clamp(0.68rem, 2.5vw, 0.8rem);
    line-height: 1.2;
    margin-bottom: 6px;
  }

  .message-box h2 {
    margin: 4px 0;
    font-size: 1.1rem;
  }

  .message-box > div {
    max-height: calc(100% - 8px);
    overflow: auto;
    padding: 10px 12px;
    border-radius: 18px;
  }

  .message-box h1 {
    margin-bottom: 6px;
    font-size: clamp(1.35rem, 7vw, 2.1rem);
  }

  .title-card,
  .game-over-card {
    gap: 8px;
    padding: 2px 4px 4px;
  }

  .title-actions {
    gap: 8px;
    margin-top: 2px;
  }

  button {
    min-height: 44px;
    padding: 10px 18px;
  }

  .touch-button {
    width: clamp(58px, 18vw, 76px);
    height: clamp(58px, 18vw, 76px);
    font-size: clamp(1.5rem, 7vw, 2rem);
  }
}

@media (max-width: 640px) and (orientation: portrait) {
  .page-shell {
    overflow: visible;
  }

  .touch-controls {
    min-height: 96px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  body {
    width: 100%;
    min-height: 100dvh;
    overflow: hidden;
    background: #1c1c1c;
  }

  .page-shell {
    width: min(100%, calc(100dvh * 16 / 9));
    height: auto;
    max-width: 100%;
    max-height: 100dvh;
    aspect-ratio: 16 / 9;
    margin: 0 auto;
  }

  .touch-controls {
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    min-height: 0;
    padding: 0;
    align-items: end;
    background: transparent;
    border-top: 0;
    display: flex;
    transform: none;
  }

  .touch-button {
    width: 72px;
    height: 72px;
    font-size: 1.8rem;
  }

  .message-box {
    align-items: start;
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .message-box > div {
    max-height: calc(100dvh - 16px);
    padding: 8px 12px;
    gap: 6px !important;
    border-radius: 14px;
  }

  .message-box > div img {
    width: auto !important;
    max-width: 42vw !important;
    max-height: 15dvh;
    object-fit: contain;
  }

  .message-box h1,
  .message-box h2 {
    margin: 2px 0 4px;
    font-size: clamp(1rem, 4vw, 1.8rem);
  }

  .message-box p {
    margin: 0 0 4px;
    font-size: 0.76rem;
    line-height: 1.15;
  }

  .message-box button {
    min-height: 44px;
    padding: 9px 18px;
  }
}
