:root {
    --primary-color: #2196f3;
    --bg-color: #f5f5f5;
    --text-color: #333;
    --header-height: 60px;
    --editor-width: 100%;
    /* Responsive */
    --editor-max-width: 800px;
    /* Fold unfolded approx */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

.screen {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    background: white;
}

/* Login */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.btn-google {
    margin-top: 20px;
    padding: 10px 20px;
    background: #4285f4;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-weight: 500;
}

/* Header */
.app-header,
.editor-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.editor-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-icon {
    font-size: 24px;
    border: none;
    background: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon.small {
    width: 30px;
    height: 30px;
    font-size: 18px;
    background: #f0f0f0;
    margin: 0 5px;
}

.btn-icon:hover {
    background-color: #f0f0f0;
}

.pagination-controls {
    display: flex;
    align-items: center;
    font-weight: 500;
}

/* Note List */
.note-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
}

.note-card {
    aspect-ratio: 3/4;
    background: white;
    border-radius: 5px 10px 10px 5px;
    /* Rounded right corners */
    box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.15);
    padding: 15px;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    position: relative;
    border-left: 12px solid rgba(0, 0, 0, 0.1);
    /* Binding spine effect */
}

.note-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 1px 0 2px rgba(0, 0, 0, 0.1);
}

.note-card:active {
    transform: scale(0.98);
}

.note-card h3 {
    font-size: 16px;
    margin-bottom: 5px;
    z-index: 1;
    background: rgba(255, 255, 255, 0.8);
    padding: 2px 5px;
    border-radius: 4px;
    align-self: flex-start;
}

/* Note Card Previews */
.note-card .preview {
    flex: 1;
    margin-top: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    position: relative;
    overflow: hidden;
}

.note-card.lined .preview {
    background-image: linear-gradient(#bbb 1px, transparent 1px);
    background-size: 100% 20px;
    margin-top: 15px;
}

.note-card.unlined .preview {
    background-color: #fff;
    background-image: radial-gradient(#aaa 1.5px, transparent 1.5px);
    background-size: 15px 15px;
    background-position: 0 0, 7.5px 7.5px;
}

.note-card.unlined .preview::after {
    content: '✏️';
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 20px;
    opacity: 0.5;
}

.note-card.lined .preview::after {
    content: '📝';
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 20px;
    opacity: 0.5;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: white;
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 400px;
}

.modal input[type="text"],
.modal select {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 5px;
}

.cover-options {
    display: flex;
    border: none;
    padding: 0;
    cursor: pointer;
}

.cover-option.selected {
    border-color: var(--primary-color);
    transform: scale(1.1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

button {
    padding: 8px 16px;
    border-radius: 5px;
    border: none;
    cursor: pointer;
}

button.primary {
    background: var(--primary-color);
    color: white;
}

/* Editor & Canvas */
.editor-container {
    flex: 1;
    overflow-y: auto;
    background: #e0e0e0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 30px;
    padding-bottom: 30px;
}

.note-page {
    width: 95%;
    max-width: var(--editor-max-width);
    aspect-ratio: 1/1.414;
    min-height: 800px;
    background-color: white !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    border: 1px solid #ccc;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.note-page.lined {
    background-image: linear-gradient(#e0e0e0 1px, transparent 1px);
    background-size: 100% 30px;
    padding-top: 30px;
}

.note-page.unlined {
    cursor: text;
}

.line-row {
    min-height: 30px;
    height: auto;
    line-height: 30px;
    padding: 0 20px;
    outline: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 2px 5px;
}

.line-row:focus {
    background-color: rgba(33, 150, 243, 0.05);
}

.page-content {
    width: 100%;
    min-height: 100%;
    line-height: 30px;
    font-size: 18px;
    outline: none;
    white-space: pre-wrap;
    padding: 0 20px;
    font-family: inherit;
    color: inherit;
    background: transparent;
    display: block;
}

.page-content div {
    margin: 0;
    padding: 0;
    line-height: 30px;
    min-height: 30px;
}

/* Drawing Controls */
.tool-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 2px 5px;
}

.tool-btn.active {
    background-color: #e0e0e0;
    border-color: #ccc;
}

.color-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.color-btn.active {
    transform: scale(1.1);
    /* Bring to front for drawing */
}

/* Text Block Selection & Handles */
.text-block {
    position: absolute;
    min-width: 100px;
    min-height: 40px;
    outline: none;
    white-space: pre-wrap;
    z-index: 5;
    padding: 5px;
    font-family: 'Nanum Pen Script', cursive;
    font-size: 30px;
}

.text-block.selected {
    border: 1px dashed #007bff;
    z-index: 100;
}

.resize-handle,
.rotate-handle,
.move-handle {
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: none;
    z-index: 20;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    border: 2px solid white;
}

.text-block.selected .resize-handle,
.text-block.selected .rotate-handle,
.text-block.selected .move-handle {
    display: block;
}

.resize-handle {
    bottom: -12px;
    right: -12px;
    cursor: se-resize;
    background-color: #007bff;
}

.rotate-handle {
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    cursor: grab;
    background-color: #28a745;
}

.move-handle {
    top: -12px;
    left: -12px;
    cursor: move;
    background-color: #ff9800;
}