* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary-color: #8b4513;
  --primary-hover: #6d3610;
  --secondary-color: #d2691e;
  --bg-color: #f5e6d3;
  --page-color: #fffef5;
  --page-shadow: #e8d4b8;
  --text-color: #3d2914;
  --text-muted: #8b7355;
  --border-color: #c9a66b;
  --error-color: #c0392b;
  --success-color: #27ae60;
  --book-cover: #654321;
  --book-spine: #4a3016;
}

body {
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  background: linear-gradient(135deg, #d4a574 0%, #c19a6b 50%, #b8860b 100%);
  color: var(--text-color);
  min-height: 100vh;
  line-height: 1.6;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================
   Header & Navigation
   ========================================== */

.app-header {
  background: var(--book-cover);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.app-title {
  color: #f5deb3;
  font-size: 1.75rem;
  font-weight: 700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.nav-buttons {
  display: flex;
  gap: 0.5rem;
}

.nav-btn {
  background: transparent;
  border: 2px solid #c19a6b;
  color: #f5deb3;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav-btn.active {
  background: #c19a6b;
  color: var(--book-cover);
  font-weight: 600;
}

/* ==========================================
   Main Content & Pages
   ========================================== */

.main-content {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem 2rem;
}

.page {
  display: none;
  width: 100%;
  max-width: 1200px;
}

.page.active {
  display: block;
}

/* ==========================================
   Diary Viewer (Japanese Summer Diary Style)
   ========================================== */

.diary-viewer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  height: calc(100vh - 180px);
  min-height: 500px;
}

.nav-arrow {
  background: var(--book-cover);
  border: none;
  color: #f5deb3;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  font-size: 1.75rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.nav-arrow:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(1.1);
}

.nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.diary-card {
  flex: 1;
  background: var(--page-color);
  border-radius: 4px;
  box-shadow: 
    0 10px 40px rgba(0, 0, 0, 0.3),
    0 0 0 6px var(--book-cover);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Use full available height */
  height: 100%;
  max-height: 800px;
}

.diary-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.empty-message {
  color: var(--text-muted);
  text-align: center;
  margin: auto;
  font-style: italic;
  font-size: 1.1rem;
  padding: 2rem;
}

/* Japanese Summer Diary Entry Styles */
.diary-entry {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Date header - horizontal, right-aligned like traditional */
.diary-entry .date-header {
  background: linear-gradient(to bottom, #f0e6d3, var(--page-color));
  padding: 0.5rem 1rem;
  border-bottom: 2px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
}

.diary-entry .date {
  font-size: 0.95rem;
  color: var(--text-color);
  font-weight: 500;
}

.diary-entry .weather {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Top half - Image area */
.diary-entry .image-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  border-bottom: 3px solid var(--border-color);
  background: 
    linear-gradient(to right, transparent 0%, transparent 100%),
    repeating-linear-gradient(
      transparent,
      transparent 28px,
      #e8dcc8 28px,
      #e8dcc8 29px
    );
  min-height: 0;
  overflow: hidden;
}

.diary-entry .image-section img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15);
  object-fit: contain;
  cursor: pointer;
}

/* Bottom half - Vertical text area */
.diary-entry .text-section {
  flex: 1;
  padding: 1rem;
  overflow: hidden;
  /* Grid lines for writing */
  background: 
    repeating-linear-gradient(
      to left,
      transparent,
      transparent 28px,
      #e8dcc8 28px,
      #e8dcc8 29px
    );
  display: flex;
  justify-content: flex-end;
}

.diary-entry .caption {
  /* Vertical writing mode - right to left */
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 1.1rem;
  line-height: 2;
  color: var(--text-color);
  white-space: pre-wrap;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem;
  max-height: 100%;
  /* Traditional Japanese font if available */
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "MS Mincho", serif;
}

.page-indicator {
  text-align: center;
  margin-top: 0.75rem;
  color: #f5deb3;
  font-size: 0.9rem;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

/* ==========================================
   Post Page
   ========================================== */

.post-container {
  background: var(--page-color);
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  margin: 0 auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.post-container h2 {
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--primary-color);
}

.image-upload-area {
  display: block;
  border: 3px dashed var(--border-color);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.5);
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-upload-area:hover {
  border-color: var(--primary-color);
  background: rgba(139, 69, 19, 0.05);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.upload-icon {
  font-size: 3rem;
  line-height: 1;
}

.image-preview {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
}

.image-preview.hidden {
  display: none;
}

/* ==========================================
   Settings Page
   ========================================== */

.settings-container {
  background: var(--page-color);
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  margin: 0 auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.settings-container h2 {
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--primary-color);
}

/* ==========================================
   Form Elements
   ========================================== */

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-color);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.15);
}

.input-with-button {
  display: flex;
  gap: 0.5rem;
}

.input-with-button input {
  flex: 1;
}

/* ==========================================
   Buttons
   ========================================== */

.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary-color);
  color: white;
  width: 100%;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.small {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  background: var(--secondary-color);
  color: white;
}

.btn.large {
  padding: 1rem 2rem;
  font-size: 1.1rem;
}

/* ==========================================
   Status Messages
   ========================================== */

.status-message {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: center;
}

.status-message:empty {
  display: none;
}

.status-message.error {
  background: #fdecea;
  color: var(--error-color);
  border: 1px solid #f5c6cb;
}

.status-message.success {
  background: #d4edda;
  color: var(--success-color);
  border: 1px solid #c3e6cb;
}

.status-message.loading {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.pubkey-info {
  margin-top: 1rem;
  padding: 0.75rem;
  background: rgba(139, 69, 19, 0.1);
  border-radius: 8px;
  font-family: monospace;
  font-size: 0.8rem;
  word-break: break-all;
  color: var(--text-muted);
}

.pubkey-info:empty {
  display: none;
}

.help-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.help-text a {
  color: var(--primary-color);
  text-decoration: underline;
}

.help-text a:hover {
  color: var(--primary-hover);
}

.connection-status {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.connection-status:empty {
  display: none;
}

.connection-status.connected {
  background: #d4edda;
  color: var(--success-color);
}

.connection-status.disconnected {
  background: #fff3cd;
  color: #856404;
}

.connection-status.error {
  background: #fdecea;
  color: var(--error-color);
}

/* ==========================================
   Responsive Design
   ========================================== */

@media (max-width: 900px) {
  .diary-viewer {
    gap: 0.5rem;
    height: calc(100vh - 160px);
  }

  .nav-arrow {
    width: 45px;
    height: 45px;
    font-size: 1.4rem;
  }

  .diary-card {
    max-height: none;
  }

  .diary-entry .caption {
    font-size: 1rem;
    line-height: 1.8;
  }
}

@media (max-width: 600px) {
  .app-header {
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .nav-buttons {
    width: 100%;
    justify-content: center;
  }

  .nav-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  .main-content {
    padding: 0.5rem;
  }

  .diary-viewer {
    gap: 0.25rem;
    height: calc(100vh - 140px);
    min-height: 400px;
  }

  .nav-arrow {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }

  .diary-card {
    border-radius: 2px;
  }

  .diary-entry .image-section {
    padding: 0.5rem;
  }

  .diary-entry .text-section {
    padding: 0.5rem;
  }

  .post-container,
  .settings-container {
    padding: 1.5rem;
  }
}
