* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background: linear-gradient(180deg, #24143d, #15152b);
  font-family: Arial, sans-serif;
  color: white;
}

.game-wrapper {
  width: 100%;
  min-height: 100vh;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden {
  display: none !important;
}

h1 {
  margin-bottom: 2px;
  font-size: clamp(22px, 4vw, 34px);
  color: #ffd54a;
  text-align: center;
  text-shadow: 3px 3px 0 #000;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(16px, 3vw, 22px);
  color: #ff80ab;
  text-align: center;
  text-shadow: 2px 2px 0 #000;
}

.character-screen {
  width: min(900px, 100%);
  margin-top: 30px;
  margin-bottom: 12px;
  padding: 28px;
  background: #23234a;
  border: 3px solid #ffd54a;
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}

.character-screen h1 {
  margin-bottom: 2px;
  font-size: clamp(28px, 5vw, 46px);
  color: #ffd54a;
  text-align: center;
  text-shadow: 3px 3px 0 #000;
}

.character-screen h2 {
  margin-bottom: 20px;
  font-size: clamp(18px, 3vw, 28px);
  color: #ff80ab;
  text-align: center;
  text-shadow: 2px 2px 0 #000;
}

.character-screen h3 {
  margin-bottom: 14px;
  font-size: 24px;
  color: #ffd54a;
  text-shadow: 2px 2px 0 #000;
}

.story-box {
  margin: 0 auto 20px;
  padding: 16px;
  max-width: 760px;
  background: rgba(0, 0, 0, 0.22);
  border: 2px solid rgba(255, 213, 74, 0.55);
  border-radius: 14px;
  line-height: 1.5;
}

.start-tip {
  margin-top: 14px;
  font-size: 14px;
  color: #ffffff;
}

.character-options {
  display: flex;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
}

.character-card {
  width: 240px;
  min-height: 190px;
  padding: 18px 16px;
  border: 3px solid #ffffff;
  border-radius: 18px;
  cursor: pointer;
  color: #ffffff;
  font-family: Arial, sans-serif;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.character-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
}

.character-card strong {
  display: block;
  margin-top: 10px;
  font-size: 24px;
  color: #ffffff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
}

.character-image-box {
  width: 110px;
  height: 110px;
  margin: 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.22);
  border: 3px solid rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.character-select-image {
  width: 130px;
  height: 150px;
  object-fit: cover;
  object-position: top center;
  margin-top: 0;
  image-rendering: auto;
}

.valentina-card {
  background: linear-gradient(180deg, #ff4fa3, #c2185b);
}

.tayna-card {
  background: linear-gradient(180deg, #42a5f5, #1565c0);
}

.top-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.game-action-btn {
  padding: 8px 16px;
  background: #ffd54a;
  color: #15152b;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 0 #b78d00;
}

.game-action-btn:hover {
  transform: translateY(-2px);
}

.game-action-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b78d00;
}

.hud {
  width: min(1200px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 8px 12px;
  background: #23234a;
  border: 3px solid #ffd54a;
  border-radius: 10px;
  font-size: 15px;
  font-weight: bold;
}

#message {
  flex: 1;
  text-align: center;
}

canvas {
  display: block;

  width: min(1200px, 100%);
  height: auto;
  max-height: calc(100vh - 230px);

  image-rendering: pixelated;

  background: transparent;
  border: 5px solid #ffd54a;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.controls {
  width: min(1200px, 100%);
  margin-top: 8px;
  font-size: 14px;
  color: #f3f3f3;
  text-align: center;
}

.mobile-controls {
  display: none;
}

.rotate-warning {
  display: none;
}

.restart-mobile-btn {
  display: none;
}

/* MOBILE DEITADO */
@media (max-width: 900px) and (orientation: landscape) {
  body {
    overflow: hidden;
  }

  .game-wrapper {
    padding: 0;
    min-height: 100vh;
  }

  .character-screen {
    width: 96vw;
    height: 94vh;
    margin-top: 3vh;
    padding: 10px 14px;
    overflow-y: auto;
    border-radius: 16px;
  }

  .character-screen h1 {
    font-size: 28px;
    margin-bottom: 0;
  }

  .character-screen h2 {
    font-size: 17px;
    margin-bottom: 8px;
  }

  .story-box {
    padding: 8px 10px;
    margin-bottom: 10px;
    font-size: 12px;
    line-height: 1.35;
  }

  .character-screen h3 {
    font-size: 19px;
    margin-bottom: 8px;
  }

  .character-options {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 10px;
  }

  .character-card {
    width: 45%;
    min-height: 120px;
    padding: 10px;
    border-radius: 14px;
  }

  .character-image-box {
    width: 72px;
    height: 72px;
  }

  .character-select-image {
    width: 90px;
    height: 110px;
  }

  .character-card strong {
    font-size: 17px;
    margin-top: 6px;
  }

  .start-tip {
    margin-top: 8px;
    font-size: 11px;
  }

  #gameArea h1,
  #gameArea h2,
  .controls {
    display: none;
  }

  canvas {
    width: 100vw;
    height: 100vh;
    max-height: none;

    aspect-ratio: auto;
    background: transparent;

    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .top-buttons {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 40;
    margin: 0;
    display: flex;
    flex-direction: row;
    gap: 6px;
  }

  .game-action-btn {
    padding: 5px 8px;
    font-size: 10px;
    border-radius: 8px;
    opacity: 0.82;
    box-shadow: 0 3px 0 rgba(183, 141, 0, 0.65);
  }

  .hud {
    position: fixed;
    top: 8px;
    left: 210px;
    right: 8px;
    width: auto;
    z-index: 30;

    display: grid;
    grid-template-columns: auto auto auto 1fr;
    align-items: center;
    gap: 8px;

    padding: 5px 8px;
    font-size: 10px;
    line-height: 1.1;

    opacity: 0.9;
    border-width: 2px;
    border-radius: 10px;
  }

  #score,
  #crystals,
  #lives {
    white-space: nowrap;
  }

  #message {
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-controls {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 12px;
    z-index: 30;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px;
    pointer-events: none;
  }

  .jump-btn {
    order: 1;
    width: 78px;
    height: 50px;
    font-size: 12px;
    pointer-events: auto;
  }

  .direction-buttons {
    order: 2;
    display: flex;
    gap: 8px;
    pointer-events: auto;
  }

  .control-btn {
    width: 52px;
    height: 50px;
    font-size: 22px;
  }

  .control-btn,
  .jump-btn {
    border: 2px solid rgba(255, 255, 255, 0.32);
    border-radius: 14px;
    background: rgba(255, 213, 74, 0.28);
    color: rgba(21, 21, 43, 0.88);
    font-weight: bold;
    box-shadow: 0 3px 0 rgba(183, 141, 0, 0.32);
    user-select: none;
    touch-action: none;
    backdrop-filter: blur(1px);
  }

  .control-btn:active,
  .jump-btn:active {
    transform: translateY(2px);
    background: rgba(255, 213, 74, 0.48);
    box-shadow: 0 1px 0 rgba(183, 141, 0, 0.35);
  }

  .restart-mobile-btn {
    position: fixed;
    left: 50%;
    bottom: 82px;
    transform: translateX(-50%);
    z-index: 60;

    padding: 10px 22px;
    border: 2px solid rgba(255, 255, 255, 0.75);
    border-radius: 14px;

    background: rgba(255, 213, 74, 0.88);
    color: #15152b;

    font-size: 13px;
    font-weight: bold;
    font-family: Arial, sans-serif;

    box-shadow: 0 4px 0 rgba(183, 141, 0, 0.75);
    cursor: pointer;
    touch-action: none;
  }

  .restart-mobile-btn.hidden {
    display: none !important;
  }

  .restart-mobile-btn:not(.hidden) {
    display: block;
  }

  .restart-mobile-btn:active {
    transform: translateX(-50%) translateY(3px);
    box-shadow: 0 1px 0 rgba(183, 141, 0, 0.75);
  }
}

/* MOBILE EM PÉ */
@media (max-width: 900px) and (orientation: portrait) {
  .rotate-warning {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, #24143d, #15152b);
    color: white;
    text-align: center;
    padding: 24px;
  }

  body:has(#gameArea:not(.hidden)) .rotate-warning {
    display: flex;
  }

  .rotate-warning div {
    max-width: 320px;
    padding: 24px;
    background: #23234a;
    border: 3px solid #ffd54a;
    border-radius: 20px;
  }

  .rotate-warning h2 {
    margin-bottom: 12px;
    color: #ffd54a;
    font-size: 28px;
  }

  .rotate-warning p {
    margin-bottom: 16px;
    font-size: 16px;
  }

  .rotate-warning span {
    font-size: 48px;
  }

  .character-screen {
    margin-top: 20px;
    padding: 14px;
  }

  .character-options {
    flex-direction: column;
    align-items: center;
  }

  .character-card {
    width: 100%;
    max-width: 260px;
  }

  .hud {
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
  }
}