@font-face {
    font-family: 'DIN';
    src: url('bahnschrift.ttf');
}

html, body {
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: black;
    font-family: Arial, sans-serif;
    color: white;
    width: 100vw;
    height: 100vh;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: black;
    background-size: cover;
    color: white;
    padding: 0;
    box-sizing: border-box;
    height: 100vh;
    width: 100%;
    max-width: 56.25vh;
    position: relative;
    margin: 0 auto;
    outline: white 1px solid; /* For debugging */
}

@media (max-width: 600px) {
    .app-container {
        max-width: 100vw;
    }
    #power-type-title {
        max-width: 100vw;
    }
    #result {
        max-width: 100vw;
    }
    #results-grid {
        max-width: 100vw;
    }
}

.content-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    position: relative; /* Context for absolute positioning */
    box-sizing: border-box;
}

#canvas-container {
    position: absolute;
    top: 50%;
    right: 4%;
    transform: translateY(-50%); /* Center vertically */
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 27.5vh; /* Minimum height for canvas */
    padding: 0;
    overflow: visible;
    z-index: 1000;
    outline: blue 0px solid; /* For debugging */
}

#myCanvas {
    touch-action: none;
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    z-index: 20;
}

#question-top {
    position: absolute;
    top: calc(49% - 11.5vh - 0.5vh); /* Start above canvas, adjust for bottom-alignment */
    max-width: 75%;
    font-size: 1.9vh;
    margin-left:02vh;
    color: white;
    text-align: left;
    white-space: normal;
    word-wrap: break-word;
    z-index: 20;
    outline: red 0px solid; /* For debugging */
    transform: translateY(-100%); /* Bottom-align by shifting up by its full height */
    transform-origin: bottom; /* Ensure transform aligns bottom edge */
    min-height: 2.1vh; /* Prevent collapse if empty */
}

#question-bottom {
    position: absolute;
    top: calc(51% + 11.5vh + 0.5vh); /* Just below canvas */
    max-width: 75%;
    font-size: 1.9vh;
    margin-left: 0vh;
    color: white;
    text-align: left;
    white-space: normal;
    word-wrap: break-word;
    z-index: 20;
    outline: red 0px solid; /* For debugging */
}

#headline {
    position: absolute;
    top: 2%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2vh;
    font-weight: bold;
    color: white;
    text-align: center;
    width: 90%;
    padding: 0.5rem;
    z-index: 10;
    outline: white 0px solid; /* For debugging */
}

#question-counter {
    position: absolute;
    top: 20vh; /* Below headline */
    font-size: 2.1vh;
    color: white;
    text-align: center;
    width: 80%;
    z-index: 10;
    outline: green 0px solid; /* For debugging */
}

#values {
    margin-top: 1.5rem;
    font-weight: bold;
    font-size: 0.9rem;
    min-height: 1.1rem;
    outline: white 0px solid;
}

#result {
    position: absolute; /* Restore absolute positioning */
    bottom: 7vh; /* Pin to bottom of .app-container */
    left: 50%;
    transform: translateX(-50%); /* Center horizontally */
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: black;
    color: white;
    padding: 0;
    box-sizing: border-box;
    width: 100%;
    max-width: 56.25vh; /* Match .app-container */
    height: 100vh; /* Full height to allow bottom positioning */
    font-size: clamp(12px, 2.3vw, 14px);
    outline: purple 0px solid; /* For debugging */
    /*overflow-y: hidden;*/
   /* overflow-x: hidden;*/
}

#power-type-title {
    position: fixed;
    top: 5vh;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 56.25vh;
    text-align: center;
    margin: 0;
    padding: 4px 0;
    font-size: 1.8vh;
    z-index: 20;
}

#chart-container {
    position: absolute;
    top: 8.5vh;
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 0;
    padding: 2px 0;
}

#power-details {
    position: fixed;
    bottom: 38.5vh; /* Reduced from 67vh to move text downward */
    left: 50%;
    transform: translateX(-50%); /* Center horizontally only */
    width: 95%;
    text-align: left;
    padding: 0;
    font-size: 1.7vh;
    z-index: 15;
    box-sizing: border-box;
    letter-spacing: 0.02vh;
    line-height: 1.9vh;
}

#power-details ul {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
}

#power-details li {
    padding: 0;
    margin: 0;
    text-align: left;
}

#results-grid {
    position: absolute;
    bottom: 0vh;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(4, 1.1fr);
    grid-template-rows: repeat(2, 19vh);
    gap: 0;
    box-sizing: border-box;
    min-height: 34vh;
    outline: red 0px solid; /* For debugging, remove after verification */
}

.grid-item {
    background-color: black;
    border: 0px solid white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: clamp(9px, 1.9vw, 12px);
    text-align: center;
    padding: 0;
    margin: 0;
    position: relative;
    line-height: 100%;
    box-sizing: border-box;
    outline: yellow 0px solid;
    cursor: pointer;
}

.grid-item.selected {
    /* No border on the grid item itself */
}

.grid-item.selected img {
    outline: 5px solid white !important; /* Override animation outline */
}

.grid-item img {
    max-width: 50%;
    max-height: 50%;
    object-fit: contain;
    margin-top: 3px;
    animation: flashAndGlow 2s ease-out forwards;
}

.grid-item:nth-child(1) img {
    animation: flashAndGlowLast 2s ease-out forwards; /* Modified for last in sequence */
    animation-delay: 1.2s; /* Longest delay, animates last */
}

.grid-item:nth-child(2) img {
    animation-delay: 1.1s;
}

.grid-item:nth-child(3) img {
    animation-delay: 1.0s;
}

.grid-item:nth-child(4) img {
    animation-delay: 0.9s;
}

.grid-item:nth-child(5) img {
    animation-delay: 0.8s;
}

.grid-item:nth-child(6) img {
    animation-delay: 0.7s;
}

.grid-item:nth-child(7) img {
    animation-delay: 0.6s;
}

.grid-item:nth-child(8) img {
    animation-delay: 0.5s; /* Shortest delay, animates first */
}

.grid-item:nth-child(n+9) img {
    animation-delay: 0.5s; /* Same as first in sequence */
}

.grid-item h4 {
    margin: 2px 0;
    font-size: clamp(11px, 1.8vw, 11px); /* Explicitly set to match .grid-item */
}

.grid-item .name {
    margin: 2px 0;
    font-size: clamp(9px, 1.3vw, 9px); /* Explicitly set to match .grid-item */
    letter-spacing: -0.5px;
    position: relative;
    top: -1vh;
}

.grid-item .type {
    margin: 2px 0;
    font-size: clamp(10px, 1.4vw, 10px); /* Explicitly set to match .grid-item */
    position: relative;
    top: -1vh;
}

.grid-item .extra-label {
    margin: 0;
    font-size: clamp(11px, 1.8vw, 11px);
    color: white;
    position: relative;
    top: -9vh;
}

/* Animation keyframes for flash and outline effect (all images except last in sequence) */
@keyframes flashAndGlow {
    0% {
        filter: brightness(5); /* Flash: high intensity */
        outline: 5px silver solid; /* White outline */
    }
    100% {
        filter: brightness(1); /* Back to normal */
        outline: 5px black solid; /* Outline fades to black */
    }
}

/* Animation keyframes for last image in sequence (outline persists) */
@keyframes flashAndGlowLast {
    0% {
        filter: brightness(5); /* Same flash */
        outline: 5px silver solid; /* Same starting outline */
    }
    100% {
        filter: brightness(1); /* Back to normal */
        outline: 5px silver solid; /* Outline remains white */
    }
}

#controls {
    position: fixed; /* Anchor to viewport */
    bottom: 1vh; /* Pin to the bottom of the viewport */
    left: 50%;
    transform: translateX(-50%); /* Center horizontally */
    display: flex;
    justify-content: center;
    align-items: center;
    width: 48vh;
    max-width: 85vw; /* Ensure responsiveness */
    padding: 0.5vh 0;
    box-sizing: border-box;
    z-index: 1000; /* Increased to ensure it’s above other elements */
    background-color: black; /* Ensure visibility against content */
    outline: white 0px solid; /* Keep for debugging if needed */
}

button {
    padding: 1.2vh 1.5vw;
    font-size: 2.5vh;
    min-height: 7vh;
    min-width: 20vh;
    max-width: 20vh;
    border: 1px solid white;
    background-color: black;
    color: white;
    cursor: pointer;
    border-radius: 0.5vh;
    box-sizing: border-box;
    text-align: center;
    flex: 0 1 auto;
    margin: 0 0.5vh;
    transition: background-color 0.2s, color 0.2s;
    outline: orange 0px solid;
    -webkit-tap-highlight-color: transparent;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.5);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button:hover:not(:disabled) {
    background-color: white;
    color: black;
}

img {
    outline: white 0px solid;
}

.red-text {
  color: white;
}

/* Disable tap highlight on all elements */
* {
  -webkit-tap-highlight-color: transparent; /* iOS Safari, Android WebKit */
  -webkit-tap-highlight-color: rgba(0,0,0,0); /* Older Android */
  -moz-tap-highlight-color: transparent; /* Older Firefox Android (rare) */
  tap-highlight-color: transparent; /* Future support */
}

/* Optional: Remove focus outline (use with care) */
*:focus {
  outline: none;
}

.share-modal {
  position: fixed;
  top: 0; left: 0; right:0; bottom:0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.share-modal-content {
  background: #202020;
  padding: 1.5rem;
  border-radius: 0 !important;
  max-width: 90%;
  width: 320px;
  text-align: center;
  position: relative;
}
.share-close {
  position: absolute;
  top: 0rem;
  right: 0.50rem;
  font-size: 1.5rem;
  cursor: pointer;
}
.share-links a {
  display: inline-block;
  margin: 0.5rem;
  text-decoration: none;
  color: #0366d6;
  font-size: 1rem;
}

#share-btn {
    position: absolute;
    bottom: 0; /* Align to bottom of chart-container */
    left: 0; /* Align to left edge of chart-container */
    transform: translateY(100%); /* Move below the chart */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 0.75rem;
    font-size: 1rem;
    border: 1px solid white;
    background-color: black;
    color: white;
    cursor: pointer;
    border-radius: 0;
    box-sizing: border-box;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}

.retake-btn {
    position: absolute;
    bottom: 0; /* Align to bottom of chart-container */
    right: 0; /* Align to right edge of chart-container */
    transform: translateY(100%); /* Move below the chart */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 0.75rem;
    font-size: 1rem;
    border: 1px solid white;
    background-color: black;
    color: white;
    cursor: pointer;
    border-radius: 0;
    box-sizing: border-box;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}

/* Hover effects */
#share-btn:hover:not(:disabled), .retake-btn:hover:not(:disabled) {
    background-color: white;
    color: black;
}