html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

/* Blur background content when Bootstrap modal is shown */
body.modal-open .puzzle-nav,
body.modal-open .container {
  filter: blur(10px);
  transition: filter 0.3s ease;
}

/* Blur background content when phrase info modal is shown */
body.phrase-info-open .puzzle-nav,
body.phrase-info-open .container {
  filter: blur(10px);
  transition: filter 0.3s ease;
}

/* Puzzle Type Navigation */
.puzzle-nav {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1100;
}

.puzzle-nav-container {
  position: relative;
}

.puzzle-nav-toggle {
  background: #007bff;
  color: white;
  border: none;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
}

.puzzle-nav-toggle:hover {
  background: #0056b3;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.puzzle-nav-toggle:focus {
  outline: 2px solid #0056b3;
  outline-offset: 2px;
}

.puzzle-nav-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.puzzle-nav-menu {
  position: absolute;
  top: 52px;
  left: 0;
  min-width: 180px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  overflow: hidden;
}

.puzzle-nav-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.puzzle-nav-user {
  padding: 12px 16px;
  color: #007bff;
  font-weight: 600;
  border-bottom: 2px solid #007bff;
  background: #f8f9fa;
  font-size: 0.95rem;
}

.puzzle-nav-link {
  display: block;
  padding: 12px 16px;
  color: #333;
  text-decoration: none;
  transition: all 0.2s ease;
  border-bottom: 1px solid #f0f0f0;
  font-weight: 500;
}

.puzzle-nav-link:last-child {
  border-bottom: none;
}

.puzzle-nav-link:hover {
  background: #f8f9fa;
  color: #007bff;
  padding-left: 20px;
}

.puzzle-nav-link:active {
  background: #e9ecef;
}

.puzzle-nav-button {
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
}

@media (max-width: 576px) {
  .puzzle-nav {
    top: 8px;
    left: 8px;
  }

  .puzzle-nav-toggle {
    width: 40px;
    height: 40px;
  }

  .puzzle-nav-icon {
    font-size: 1.3rem;
  }

  .puzzle-nav-menu {
    top: 48px;
    min-width: 160px;
  }

  .puzzle-nav-user {
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .puzzle-nav-link {
    padding: 10px 14px;
    font-size: 0.95rem;
  }
}

:root {
    --box-size: 40px;
    --font-size: 2rem;
    --space-width: 12px;
    --space-height: 40px;
}

.word-group {
    display: inline-flex;
    flex-wrap: nowrap;
    justify-content: center;
    margin-bottom: 8px;
}

.board {
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.space {
    display: inline-block;
    width: var(--space-width);
    height: var(--space-height);
    vertical-align: middle;
    transition: width 0.2s;
}

.fortune-selected-container {
    background: #f8f9fa;
    display: inline-block;
    min-width: 70%;
    max-width: 90%;
    transition: box-shadow 0.3s ease;
}

.fortune-selected-text {
    font-size: 1.5rem;
    letter-spacing: 1px;
    word-break: break-word;
    transition: transform 0.2s ease, color 0.3s ease;
}

    .fortune-selected-text.updated {
        animation: phrasePop 0.4s ease;
    }

@keyframes phrasePop {
    0% {
        transform: scale(1);
        color: #198754;
    }

    40% {
        transform: scale(1.15);
        color: #28a745;
    }

    100% {
        transform: scale(1);
        color: #198754;
    }
}

/* On mobile, keep it readable but compact */
@media (max-width: 576px) {
    .fortune-selected-text {
        font-size: 1.2rem;
    }
}

.circular-chart {
    width: 100%;
    height: 100%;
}

.circle {
    transition: stroke-dasharray 1s linear;
    stroke-linecap: round;
}

@media (min-width: 992px) {
    .space {
        width: 12px; /* Slightly larger space for desktops */
    }
}

@media (max-width: 576px) {
    .space {
        width: 12px;
        height: var(--box-size);
    }

    .board {
        gap: 4px;
    }

    .word-group {
        margin-bottom: 4px;
    }
}

.word.selected {
    background-color: #28a745 !important;
    color: white !important;
}

.letter-box {
    width: var(--box-size);
    height: var(--box-size);
    margin: 2px;
    border: 2px solid #333;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size);
    background: #fff;
    box-sizing: border-box;
}

    .letter-box input {
        width: 100%;
        height: 100%;
        border: none;
        padding: 0;
        margin: 0;
        text-align: center;
        font-size: inherit; /* will follow var(--font-size) */
        background: transparent;
        outline: none;
        box-sizing: border-box;
    }

    .letter-box.fixed {
        background: #007bff;
        color: white;
        font-weight: bold;
    }

    .letter-box input::placeholder {
        color: #004400;
    }

.fixed {
    pointer-events: none;
}

.hidden {
    color: #003300;
}

.category {
    margin-top: 30px;
    font-size: 1.5rem;
    color: #9370DB;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.clue-0 {
    background-color: #228B22 !important;
    border: 2px solid black !important;
}

.clue-1 {
    background-color: #b59f3b !important;
    border: 2px dashed black !important;
}

.clue-2 {
    background-color: #91a3b0 !important;
    border: 2px dotted black !important;
}

.round {
    margin-bottom: 16px;
}

.round-title {
    font-weight: bold;
    margin-bottom: 4px;
}

.word {
    display: inline-block;
    margin: 4px;
    padding: 8px 12px;
    border-radius: 4px;
    background-color: #eee;
    cursor: pointer;
    font-weight: bold;
    user-select: none;
    transition: 0.2s ease-in-out;
}

    .word:hover {
        background-color: #ddd;
    }

    .word.selected {
        background-color: #28a745;
        color: white;
    }

    .word.disabled {
        background-color: #ccc;
        cursor: not-allowed;
    }

.fortune-intro {
    background-color: #f5fff5;
    border: 2px solid #28a745;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
    text-align: center;
    font-family: sans-serif;
}

    .fortune-intro h2 {
        margin-top: 0;
        font-size: 1.8em;
    }

    .fortune-intro p {
        font-size: 1.2em;
        margin: 0.5em 0;
    }

.win-anim {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 1050;
    animation: pulseGlow 1s ease-in-out infinite alternate;
    width: 100vw;
    max-width: 420px;
    display: flex;
    justify-content: center;
}

@keyframes pulseGlow {
    from {
        box-shadow: 0 0 10px #28a745;
    }

    to {
        box-shadow: 0 0 30px #28a745;
    }
}

.hidden {
    display: none;
}

.fortune-anim {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 3rem;
    font-weight: bold;
    padding: 30px;
    background: linear-gradient(45deg, gold, deeppink, purple);
    background-size: 300% 300%;
    color: white;
    border-radius: 20px;
    text-align: center;
    animation: fortuneFlash 2s ease-in-out infinite, bounce 1s infinite;
    z-index: 2000;
    box-shadow: 0 0 25px rgba(255, 255, 255, 0.8);
}

@keyframes fortuneFlash {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translate(-50%, 0);
    }

    50% {
        transform: translate(-50%, -20px);
    }
}

.starburst {
    position: fixed;
    width: 10px;
    height: 10px;
    background: yellow;
    border-radius: 50%;
    animation: explode 1s ease-out forwards;
    z-index: 2001;
    pointer-events: none;
}

    .starburst.color-red {
        background: #ff3b3b;
    }

    .starburst.color-yellow {
        background: #ffe066;
    }

    .starburst.color-blue {
        background: #6a89cc;
    }

    .starburst.color-green {
        background: #28a745;
    }

    .starburst.color-pink {
        background: #ff6f91;
    }

    .starburst.color-purple {
        background: #9370DB;
    }

    .starburst.color-orange {
        background: #ff9800;
    }

    .starburst.color-cyan {
        background: #00bcd4;
    }

    .starburst.color-white {
        background: #fff;
    }

@keyframes explode {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(5) translateY(-200px);
        opacity: 0;
    }
}

@keyframes explode-starburst {
    0% {
        transform: scale(1) translate(0, 0);
        opacity: 1;
    }

    100% {
        transform: scale(2) translate(var(--x), var(--y));
        opacity: 0;
    }
}

.letter-box.editable.active {
    border-color: #28a745;
    box-shadow: 0 0 0 2px #28a74533;
}

@media (max-width: 576px) {
    .fortune-anim {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 95vw;
        max-width: 98vw;
        font-size: 2rem;
        padding: 16px;
    }
}

@media (max-width: 576px) {
    .virtual-keyboard-fixed {
        padding-left: 12px;
        padding-right: 12px;
        margin-left: 0;
        margin-right: 0;
        box-sizing: border-box;
        width: 100vw;
        left: 0;
        right: 0;
    }

    .vk-row {
        max-width: 100vw;
        width: 100vw;
        margin: 0;
        padding: 0;
    }

    .virtual-keyboard-fixed .vk-key,
    .virtual-keyboard-fixed .vk-key-second,
    .virtual-keyboard-fixed .vk-wide {
        min-width: 24px !important;
        min-height: 36px !important;
        font-size: 1rem !important;
        margin-left: 2px !important;
        margin-right: 2px !important;
    }
}

.virtual-keyboard-fixed {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100vw;
    background: #f8f9fa;
    z-index: 1000;
    padding: 12px 0 8px 0;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
}

.vk-row {
    max-width: 420px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.virtual-keyboard-fixed .vk-key {
    flex: 1 1 0;
    min-width: 40px;
    min-height: 48px;
    font-size: 1.3rem;
    text-align: center;
}

.virtual-keyboard-fixed .vk-wide {
    min-width: 64px;
    font-size: 1.3rem;
    font-weight: bold;
}

.virtual-keyboard-fixed .vk-vowel {
    color: #888 !important;
    background: #e9ecef !important;
    border-color: #bbb !important;
    cursor: not-allowed !important;
    opacity: 0.7;
}

.virtual-keyboard-fixed .btn-outline-success {
    border-width: 2px;
    font-weight: bold;
}

.virtual-keyboard-fixed .btn-outline-secondary:disabled,
.virtual-keyboard-fixed .btn-outline-success:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.vk-row-second .vk-key-second {
    min-width: 46px; /* slightly wider for 9 keys to fill the row */
}

.clues-container {
    max-height: 120px; /* Show at least 3 clues */
    overflow-y: auto;
    margin-bottom: 8px;
    padding-right: 4px;
    background: #f8f9fa;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.clue-small {
    font-size: 0.95rem;
    padding: 4px 8px;
    margin-bottom: 4px;
    max-width: 350px;
    min-height: 28px;
    line-height: 1.2;
}

@media (max-width: 576px) {
    .clues-container {
        max-height: 90px;
        padding-right: 2px;
    }

    .clue-small {
        font-size: 0.85rem;
        max-width: 95vw;
        min-height: 24px;
        padding: 2px 4px;
    }
}

.word-group-small .letter-box {
    width: 28px !important;
    font-size: 1.2rem !important;
}

@media (max-width: 576px) {
    .word-group-small .letter-box {
        width: 22px !important;
        font-size: 1rem !important;
    }
}

.clue-legend {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8f9fa;
    border-radius: 6px;
    padding: 2px 0;
}

.legend-box {
    border: 1px solid #bbb;
}

.fortune-header {
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.10);
    margin-top: 12px;
}

.fortune-title {
    font-weight: 800;
    font-size: 2em;
    letter-spacing: 1px;
    margin-bottom: 0.5em;
    font-family: 'Segoe UI', 'Arial', sans-serif;
}

.fortune-instruction {
    font-size: 1.08em;
    font-weight: 500;
    margin-bottom: 0;
}

@media (max-width: 576px) {
    .fortune-header {
        border-radius: 10px;
        margin-top: 6px;
    }

    .fortune-title {
        font-size: 1.2em;
    }

    .fortune-instruction {
        font-size: 0.98em;
    }
}

/* Phrase Info Modal Styles */
.phrase-info-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.phrase-info-content {
    background: white;
    border-radius: 12px;
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.phrase-info-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 12px 12px 0 0;
    text-align: center;
}

.phrase-info-header h3 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.phrase-info-body {
    padding: 24px;
}

.phrase-info-definition {
    background: #f8f9fa;
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    border-left: 4px solid #667eea;
    line-height: 1.6;
    font-size: 1.05rem;
}

.phrase-info-url {
    padding: 12px;
    background: #e8f4f8;
    border-radius: 6px;
    margin-top: 12px;
}

.phrase-info-url a {
    color: #0066cc;
    text-decoration: none;
    font-weight: 500;
    word-break: break-all;
}

.phrase-info-url a:hover {
    text-decoration: underline;
}

.phrase-info-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #dee2e6;
}

.phrase-info-counter {
    font-size: 0.95rem;
    color: #6c757d;
    font-weight: 600;
}

.phrase-info-close {
    background: #28a745;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.phrase-info-close:hover {
    background: #218838;
}

.phrase-info-nav-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

.phrase-info-nav-btn:hover {
    background: #5568d3;
}

.phrase-info-nav-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Rules modal responsive footer */
@media (max-width: 576px) {
    #rulesModal .modal-footer {
        flex-direction: column;
        gap: 10px;
    }
    
    #rulesModal .modal-footer button {
        width: 100%;
        margin: 0;
    }
}

@media (max-width: 576px) {
    .phrase-info-modal {
        padding: 10px;
    }
    
    .phrase-info-content {
        max-height: 90vh;
    }
    
    .phrase-info-header h3 {
        font-size: 1.3rem;
    }
    
    .phrase-info-body {
        padding: 16px;
    }
    
    .phrase-info-definition {
        font-size: 0.95rem;
        padding: 12px;
    }
    
    .phrase-info-nav {
        flex-direction: column;
        gap: 10px;
    }
    
    .phrase-info-nav-btn,
    .phrase-info-close {
        width: 100%;
    }
}
