:root {
  --primary: #8b5a2b; 
  --primary-light: #c19a6b;
  --accent: #ffd700; 
  --bg-parchment: #fdf6e3; 
  --bg-dark: #2c1e16; 
  --text-main: #2b1f16;
  --text-inverse: #fdf6e3;
  --font-story: 'Georgia', serif;
  --font-ui: 'Inter', system-ui, sans-serif;
  --shadow-magic: 0 4px 20px rgba(255, 215, 0, 0.3);
  --shadow-book: 0 10px 30px rgba(0, 0, 0, 0.5);
}

body {
  margin: 0; padding: 0;
  font-family: var(--font-story);
  background: radial-gradient(circle at center, #4a3424 0%, var(--bg-dark) 100%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex; justify-content: center; align-items: center;
  overflow: hidden;
}

button {
  font-family: var(--font-ui);
  background: var(--primary);
  color: var(--text-inverse);
  border: 1px solid var(--primary-light);
  padding: 10px 20px; border-radius: 8px;
  cursor: pointer; font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

button:hover { background: var(--primary-light); transform: translateY(-2px); box-shadow: var(--shadow-magic); }
button:active { transform: translateY(0); }
button:disabled { background: #555; color: #888; cursor: not-allowed; box-shadow: none; transform: none; border-color: #444; }

input[type="text"], select {
  font-family: var(--font-ui);
  padding: 10px 15px; border: 2px solid var(--primary-light);
  border-radius: 8px; outline: none; transition: border-color 0.3s;
  background: rgba(253, 246, 227, 0.9); color: var(--text-main);
}
input[type="text"]:focus { border-color: var(--accent); box-shadow: var(--shadow-magic); }

.app-container {
  width: 100%; max-width: 1200px; height: 90vh;
  background: var(--bg-parchment); border-radius: 16px;
  box-shadow: var(--shadow-book);
  display: flex; flex-direction: column; overflow: hidden; position: relative;
  background-image: 
    linear-gradient(to right, rgba(0,0,0,0.05) 0%, transparent 5%, transparent 95%, rgba(0,0,0,0.05) 100%),
    linear-gradient(to bottom, rgba(0,0,0,0.05) 0%, transparent 5%, transparent 95%, rgba(0,0,0,0.05) 100%);
}

.header { padding: 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid var(--primary-light); background: rgba(139, 90, 43, 0.1); }
.header h1 { font-size: 24px; color: var(--primary); margin: 0; text-shadow: 1px 1px 2px rgba(255,255,255,0.5); }
.nav-buttons { display: flex; gap: 10px; }
.main-content { flex: 1; display: flex; position: relative; }

/* Home Screen */
.home-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; }
.story-card { background: white; padding: 30px; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); text-align: center; border: 2px solid var(--primary-light); transition: transform 0.3s ease, box-shadow 0.3s ease; cursor: pointer; }
.story-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-magic); border-color: var(--accent); }
.story-card h2 { color: var(--primary); margin-bottom: 15px; font-size: 32px; }

/* Editor Interface */
.editor-view { display: flex; width: 100%; height: 100%; }
.story-panel { flex: 1; padding: 40px; overflow-y: auto; border-right: 2px solid var(--primary-light); display: flex; flex-direction: column; }
.story-text { font-size: 22px; line-height: 1.8; flex: 1; }
.page-controls { margin-top: 20px; display: flex; justify-content: space-between; align-items: center; }
.canvas-panel { flex: 1; display: flex; flex-direction: column; background: #eae3d3; position: relative; }
.canvas-toolbar { padding: 15px; background: var(--primary); display: flex; gap: 10px; align-items: center; }
.drawing-area { flex: 1; position: relative; display: flex; justify-content: center; align-items: center; overflow: hidden; }
.drawing-area canvas { background: white; box-shadow: 0 0 10px rgba(0,0,0,0.1); cursor: crosshair; }

/* AI Prompt Panel */
.ai-prompt-panel { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(253, 246, 227, 0.95); padding: 10px 20px; border-radius: 20px; box-shadow: var(--shadow-book); display: flex; gap: 10px; border: 1px solid var(--accent); z-index: 10; }
.ai-prompt-panel input { width: 300px; }
.loader { border: 4px solid #f3f3f3; border-top: 4px solid var(--accent); border-radius: 50%; width: 24px; height: 24px; animation: spin 1s linear infinite; display: inline-block; margin-left: 10px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Reader View */
.reader-view { display: flex; width: 100%; height: 100%; justify-content: center; align-items: center; background: var(--bg-dark); }
.book-spread { display: flex; width: 90%; height: 90%; background: var(--bg-parchment); border-radius: 8px; box-shadow: inset 0 0 20px rgba(0,0,0,0.1), var(--shadow-book); }
.book-page-left { flex: 1; padding: 40px; border-right: 1px solid #ccc; display: flex; flex-direction: column; justify-content: center; box-shadow: inset -10px 0 20px rgba(0,0,0,0.05); }
.book-page-right { flex: 1; padding: 40px; display: flex; flex-direction: column; justify-content: center; align-items: center; box-shadow: inset 10px 0 20px rgba(0,0,0,0.05); }
.book-illustration { max-width: 100%; max-height: 100%; object-fit: contain; border: 2px solid var(--primary-light); padding: 10px; background: white; }
.book-page-number { text-align: center; margin-top: 20px; font-size: 14px; color: #666; }
.reading-nav { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 20px; background: rgba(0,0,0,0.5); padding: 10px 20px; border-radius: 30px; }
