@font-face {
    font-family: 'SamdungDaeHan';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408@1.0/YoonChildfundkoreaDaeHan.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'SamdungMinGuk';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408@1.0/YoonChildfundkoreaMinGuk.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'SamdungManSeh';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408@1.0/YoonChildfundkoreaManSeh.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
}

:root {
    --bg-color: #f7f3e8; /* Old paper color */
    --line-color: #b0c4de; /* Notebook line color */
    --text-color: #333;
    --border-color: #555;
    --accent-color: #ff6b6b; /* Crayon red */
    --font-primary: 'SamdungDaeHan', cursive;
}

body {
    font-family: var(--font-primary);
    background-color: #fff9e6; /* Soft yellow background */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    background-image: 
        radial-gradient(circle, #e0e0e0 1px, transparent 1px),
        radial-gradient(circle, #e0e0e0 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
}

.diary-container {
    width: 100%;
    max-width: 600px;
    background-color: var(--bg-color);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 
        0 4px 15px rgba(0,0,0,0.1),
        inset 0 0 50px rgba(0,0,0,0.05); /* Vignette effect */
    border: 2px dashed var(--border-color);
    position: relative;
    overflow: hidden;
}

/* Paper texture overlay (optional) */
.diary-container::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url('data:image/svg+xml;utf8,<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><filter id="noise"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="3" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noise)" opacity="0.1"/></svg>');
    pointer-events: none;
    z-index: 10;
}

.home-link {
    text-decoration: none;
    display: block;
}

header h1 {
    text-align: center;
    font-size: 2.5rem;
    color: var(--accent-color);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    border-bottom: 3px double var(--line-color);
    padding-bottom: 10px;
    cursor: pointer;
    transition: transform 0.2s;
}

header h1:hover {
    transform: scale(1.05);
}

.date-input {
    display: flex;
    justify-content: center;
    gap: 15px;
    font-size: 1.2rem;
    margin-bottom: 20px;
}

.image-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

.drawing-controls {
    width: 100%;
    background-color: #fff;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-items: center;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.05);
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-group label {
    font-weight: bold;
    font-size: 0.9rem;
    color: #666;
}

.tool-btn {
    font-size: 0.9rem;
    padding: 5px 12px;
}

.tool-btn.active {
    background-color: var(--accent-color);
    color: white;
    border-color: white;
    transform: rotate(-2deg) scale(1.05);
}

.color-palette {
    display: flex;
    gap: 5px;
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #ddd;
    cursor: pointer;
    transition: transform 0.1s;
}

.color-swatch:hover, .color-swatch.active {
    transform: scale(1.2);
    border-color: #333;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.canvas-container {
    width: 100%;
    aspect-ratio: 4/3;
    border: 3px solid #333;
    background-color: #fff;
    position: relative;
    overflow: hidden;
    cursor: crosshair;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.1);
}

/* Ensure canvas and upload area overlap correctly */
.upload-area {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #888;
    pointer-events: none; /* Let clicks pass through to canvas if needed, but we toggle display */
    z-index: 10;
    background-color: rgba(255,255,255,0.5); /* Semi-transparent if canvas has content */
}

canvas {
    display: block; /* Always block, controlled by visibility or clearing */
    width: 100%;
    height: 100%;
    touch-action: none; /* Prevent scrolling while drawing */
}

#brush-guide {
    position: absolute;
    pointer-events: none;
    border: 1px solid #333;
    border-radius: 50%;
    display: none;
    z-index: 100;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
    background-color: rgba(255, 255, 255, 0.1);
}

.text-section {
    position: relative;
    width: 524px; /* 13 columns * 40px + 2px border + 2px extra for safety */
    margin: 0 auto 20px auto; /* Center in container */
    min-height: 404px; /* 10 rows * 40px + border */
    background-color: #fff;
    border: 2px solid var(--line-color);
    padding: 0;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
    overflow: hidden; /* Hide scrollbars if possible */
}

/* The actual grid lines background can be on the container or the display div */
/* Let's put it on the container for simplicity */
.text-section {
    background-image: 
        linear-gradient(var(--line-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--line-color) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: -1px -1px; /* Align grid lines */
}

/* The text section container */
.text-section {
    position: relative;
    width: 524px; /* 13 columns * 40px + borders */
    margin: 0 auto 20px auto;
    min-height: 404px; /* 10 rows * 40px + borders */
    background-color: #fff;
    border: 2px solid var(--line-color);
    /* Grid lines background */
    background-image: 
        linear-gradient(var(--line-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--line-color) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: -1px -1px;
}

/* The visual text renderer (Grid of cells) */
#diary-grid-display {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 1; /* Below textarea */
    pointer-events: none;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
}

.grid-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'SamdungDaeHan', cursive;
    font-size: 24px;
    color: var(--text-color);
    width: 40px;
    height: 40px;
    /* border: 1px solid red; debug */
}

/* The input area overlay */
textarea {
    position: relative;
    z-index: 2; /* On top to receive input */
    width: 100%;
    height: 100%;
    min-height: 400px;
    background: transparent;
    border: none;
    outline: none;
    
    /* Font settings - using SamdungDaeHan for placeholder/input visibility */
    font-family: 'SamdungDaeHan', cursive; 
    /* Note: We keep monospace metrics logic in mind, but user wants this font. 
       We might need to adjust letter-spacing if alignment drifts, 
       but primarily they want the 'look'. 
       The invisible text approach used monospace. 
       If we show text directly, we use the font directly. */
    font-size: 24px; 
    line-height: 40px; 
    letter-spacing: 0; /* Reset spacing for natural font flow, or tune it */
    padding: 0; 
    margin: 0;
    padding-left: 20px; /* Slight offset to match grid center approx */
    padding-top: 4px; /* Vertical alignment */
    
    color: transparent; /* Keep transparent if using grid-display sync */
    /* Wait, user asked for font change on "placeholder". 
       If textarea is transparent, placeholder is also transparent? 
       Usually yes. 
       The previous fix RE-ENABLED grid-display for the content.
       So the textarea ITSELF is transparent.
       BUT the placeholder needs to be visible when empty.
    */
    caret-color: var(--accent-color);
    resize: none;
    overflow-y: hidden;
    white-space: pre-wrap; 
    word-break: break-all;
    display: block;
}

textarea::placeholder {
    color: #aaa;
    font-family: 'SamdungDaeHan', cursive;
    opacity: 1; /* Ensure visibility */
}

/* If the user wants the INPUT to be this font, we rely on the grid-display div which ALREADY uses SamdungDaeHan. 
   So we just need to ensure the placeholder (which is in the textarea) is visible and styled.
*/

.diary-footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

button {
    font-family: var(--font-primary);
    font-size: 1.2rem;
    padding: 10px 20px;
    border: 2px solid #333;
    background-color: #fff;
    cursor: pointer;
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px; /* Squiggly border */
    transition: all 0.2s;
}

button:hover {
    transform: rotate(-2deg) scale(1.05);
    background-color: var(--accent-color);
    color: white;
    border-color: white;
}

/* Mobile responsiveness */
@media (max-width: 600px) {
    .diary-container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
}