
/* Handwriting Mode Styles */
.handwriting-overlay {
    display: none; /* Hidden by default to avoid legacy popup issues */
    /* Removed fixed position legacy styles */
}

.handwriting-overlay.hidden {
    display: none !important;
}

.handwriting-board {
    background-color: #fff;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 400px; /* Increased to fit larger canvas */
    max-width: 95%;
}

.board-header {
    width: 100%;
    display: flex;
    justify-content: center; /* Centered since close button is removed */
    align-items: center;
    font-size: 1.2rem;
    color: var(--primary-color);
    font-weight: bold;
}

.grid-style-select {
    font-size: 0.9rem;
    padding: 2px 25px 2px 8px; /* Extra right padding for arrow */
    margin-left: 10px;
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    background-color: #fff;
    cursor: pointer;
    min-width: 85px;
}

/* Close icon styles removed */

#handwriting-canvas {
    border: 2px solid var(--primary-color);
    border-radius: 5px;
    background-color: #fff8dc; /* Consistent with input bg */
    cursor: crosshair;
    touch-action: none; /* Prevent scrolling while writing */
    background-size: 100% 100%;
    
    /* Responsive Canvas */
    width: 360px; /* Default width matching HTML */
    max-width: 100%; /* Scale down on small screens */
    height: auto; /* Allow height to adjust */
    aspect-ratio: 1 / 1; /* Maintain square shape */
}

/* Grid Styles */
/* Mi-character grid (米字格) - Default */
#handwriting-canvas.grid-mizige {
    background-image: 
        linear-gradient(to right, transparent 49.5%, rgba(200, 0, 0, 0.1) 49.5%, rgba(200, 0, 0, 0.1) 50.5%, transparent 50.5%), /* Vertical */
        linear-gradient(to bottom, transparent 49.5%, rgba(200, 0, 0, 0.1) 49.5%, rgba(200, 0, 0, 0.1) 50.5%, transparent 50.5%), /* Horizontal */
        linear-gradient(45deg, transparent 49.5%, rgba(200, 0, 0, 0.1) 49.5%, rgba(200, 0, 0, 0.1) 50.5%, transparent 50.5%), /* Diagonal 1 */
        linear-gradient(-45deg, transparent 49.5%, rgba(200, 0, 0, 0.1) 49.5%, rgba(200, 0, 0, 0.1) 50.5%, transparent 50.5%); /* Diagonal 2 */
}

/* Four-line grid (四线格) - Interpreted as Pinyin grid lines for now, or maybe they meant Tianzige? */
/* Given the context is Hanzi, they likely mean Tianzige (Cross grid) which divides the box into 4 squares */
/* But if they strictly want "Four Lines" (Horizontal), I can add that too. */
/* Let's stick to Tianzige (Cross) as the standard alternative to Mizige */
#handwriting-canvas.grid-tianzige {
    background-image: 
        linear-gradient(to right, transparent 49.5%, rgba(200, 0, 0, 0.1) 49.5%, rgba(200, 0, 0, 0.1) 50.5%, transparent 50.5%), /* Vertical */
        linear-gradient(to bottom, transparent 49.5%, rgba(200, 0, 0, 0.1) 49.5%, rgba(200, 0, 0, 0.1) 50.5%, transparent 50.5%); /* Horizontal */
}

.hw-candidates {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start; /* Better for reading list */
    align-content: flex-start;
    gap: 8px;
    min-height: 60px;
    max-height: 200px; /* Limit height to allow scrolling */
    overflow-y: auto;
    width: 100%;
    padding: 5px;
    border: 1px solid #eee;
    border-radius: 5px;
    background-color: #fafafa;
}

.candidate-char {
    width: 2em;
    height: 2em;
    line-height: 2em;
    text-align: center;
    border: 1px solid var(--secondary-color);
    border-radius: 5px;
    cursor: pointer;
    background-color: #fdf5e6;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.candidate-char:hover {
    background-color: var(--primary-color);
    color: #fff;
    transform: scale(1.1);
}

.board-controls {
    display: flex;
    gap: 15px;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap; /* Allow wrapping if buttons are too wide */
}

/* Split Layout for Handwriting Mode */
body.mode-handwriting .game-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 40px;
}

body.mode-handwriting .game-main-panel {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Transform overlay to side panel */
body.mode-handwriting .handwriting-overlay {
    position: sticky !important;
    top: 100px;
    width: auto !important;
    height: auto !important;
    background-color: transparent !important;
    display: block !important; /* Always show in layout flow */
    z-index: 10;
}

/* Handle visibility/interactivity in side-panel mode */
body.mode-handwriting .handwriting-overlay.hidden {
    /* Show it but dimmed to indicate inactivity */
    display: block !important;
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(100%);
}

body.mode-handwriting .handwriting-board {
    box-shadow: none;
    border: 2px solid var(--secondary-color);
    width: 400px; /* Fixed width for the panel */
    margin: 0;
}

/* Responsive: stack on small screens */
@media (max-width: 900px) {
    body.mode-handwriting .game-layout {
        flex-direction: column;
        align-items: center;
    }
    
    body.mode-handwriting .handwriting-board {
        width: 100%;
        max-width: 400px;
        margin-top: 20px;
    }
}

/* Stroke Order Modal Styles */
.stroke-modal-content {
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stroke-order-container {
    width: 300px;
    height: 300px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin: 20px 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.stroke-controls {
    display: flex;
    justify-content: center;
    margin-top: 10px;
}

.stroke-text-display {
  margin-top: 15px;
  padding: 15px;
  background-color: #f9f9f9;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  font-size: 1.1rem;
  color: #333;
  line-height: 1.6;
  text-align: left;
  width: 100%;
  box-sizing: border-box;
}

.stroke-title {
  font-weight: bold;
  margin-bottom: 10px;
  display: block;
  font-size: 1.2rem;
  color: #2c3e50;
  border-bottom: 2px solid #ddd;
  padding-bottom: 5px;
}

.stroke-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stroke-step {
  display: block;
  padding: 5px 10px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

@media (max-width: 480px) {
    .handwriting-board {
        padding: 10px;
        width: 98%;
    }
}
