/* ============================================================
   Royal Indonesian Chemistry Society — beige notepad theme
   with a Medium-style rich-text editor. Responsive: phone,
   iPad/tablet, desktop.
   ============================================================ */

:root {
  --beige-100: #f7f1e3;   /* page background */
  --beige-200: #efe6d2;   /* cards */
  --beige-300: #e6d8bd;   /* borders / hover */
  --beige-400: #d8c39c;   /* strong border */
  --ink:       #3a3128;   /* main text */
  --ink-soft:  #6b5f4e;   /* muted text */
  --accent:    #7a5c3e;   /* headings / links */
  --accent-dk: #5c4530;
  --paper:     #fdfaf2;   /* writing surface */
  --danger:    #9a4b3b;
  --ok:        #4a7a3e;
  --shadow:    0 2px 6px rgba(90, 70, 45, 0.10),
               0 8px 24px rgba(90, 70, 45, 0.08);
  --radius: 10px;
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --display: "Cormorant Garamond", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* the [hidden] attribute must win over display:flex on the overlays */
[hidden] { display: none !important; }

body {
  font-family: var(--serif);
  color: var(--ink);
  background-color: var(--beige-100);
  background-image:
    radial-gradient(circle at 20% 15%, rgba(216, 195, 156, 0.18), transparent 55%),
    radial-gradient(circle at 85% 80%, rgba(216, 195, 156, 0.14), transparent 55%);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Header ---------- */
.site-header { text-align: center; padding: 42px 20px 22px; }
.crest { font-size: 40px; color: var(--accent); line-height: 1; margin-bottom: 6px; }
.site-header h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(28px, 5vw, 46px);
  letter-spacing: 0.5px;
  color: var(--accent-dk);
  margin: 0;
}
.subtitle {
  font-family: var(--display);
  font-style: italic;
  font-size: 20px;
  color: var(--ink-soft);
  margin: 4px 0 0;
  letter-spacing: 1px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 16px 0;
  border-bottom: 1px solid var(--beige-300);
  max-width: 1080px;
  margin: 0 auto;
}
.tab {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 22px;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--accent); }
.tab.is-active { color: var(--accent-dk); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- Layout ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; }
.view { display: none; }
.view.is-active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.section-head h2 { font-family: var(--display); font-size: 30px; color: var(--accent-dk); margin: 0 0 4px; }
.muted { color: var(--ink-soft); font-style: italic; margin: 0; }

/* ---------- Card grid (essays + notes) ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.card {
  background: var(--beige-200);
  border: 1px solid var(--beige-300);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 20px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 5px;
  background: var(--accent);
  opacity: 0.5;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 14px rgba(90,70,45,.14), 0 14px 34px rgba(90,70,45,.12);
  border-color: var(--beige-400);
}
.card h3 {
  font-family: var(--display);
  font-size: 24px;
  color: var(--accent-dk);
  margin: 0 0 6px;
  line-height: 1.2;
  cursor: pointer;
}
.card h3:hover { color: var(--accent); }
.card .card-date { font-size: 13px; color: var(--ink-soft); font-style: italic; margin: 0 0 10px; }
.card .excerpt {
  color: var(--ink-soft);
  font-size: 16px;
  margin: 0;
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}
.card .card-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.btn-small {
  font-family: var(--serif);
  font-size: 15px;
  background: transparent;
  border: 1px solid var(--beige-400);
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
  color: var(--accent-dk);
  transition: background 0.15s, border-color 0.15s;
}
.btn-small:hover { background: var(--beige-300); }
.btn-small.danger { color: var(--danger); border-color: transparent; }
.btn-small.danger:hover { background: rgba(154,75,59,.08); border-color: rgba(154,75,59,.3); }

.empty-hint { padding: 20px 4px; grid-column: 1 / -1; }

/* ---------- Buttons ---------- */
.btn-primary {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--paper);
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 2px 6px rgba(90,70,45,.2);
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-dk); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-ghost {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--beige-400);
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--beige-200); }

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:hover { color: var(--accent-dk); background: var(--beige-200); }

/* ---------- Status banner ---------- */
.status { border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; font-size: 15px; }
.status.error { background: #f6e2dc; color: #8a3a2a; border: 1px solid #e0b9ac; }

/* ============================================================
   Rich content (rendered essay / note bodies)
   ============================================================ */
.rich-content { color: var(--ink); font-size: 18px; line-height: 1.8; }
.rich-content p { margin: 0 0 1em; }
.rich-content h2 { font-family: var(--display); font-size: 30px; color: var(--accent-dk); margin: 1em 0 .4em; }
.rich-content h3 { font-family: var(--display); font-size: 24px; color: var(--accent-dk); margin: 1em 0 .4em; }
.rich-content blockquote {
  margin: 1em 0;
  padding: 6px 20px;
  border-left: 4px solid var(--accent);
  color: var(--ink-soft);
  font-style: italic;
  background: rgba(216,195,156,.15);
}
.rich-content ul, .rich-content ol { margin: 0 0 1em; padding-left: 1.6em; }
.rich-content li { margin: .3em 0; }
.rich-content a { color: var(--accent); text-decoration: underline; }
.rich-content b, .rich-content strong { color: var(--accent-dk); }

/* ============================================================
   Reader modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(58, 49, 40, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 60;
  animation: fade 0.2s ease;
}
.modal {
  background: var(--paper);
  border: 1px solid var(--beige-400);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(58,49,40,.35);
  max-width: 720px; width: 100%;
  padding: 40px 44px 46px;
  position: relative;
}
.modal h2 { font-family: var(--display); font-size: 34px; color: var(--accent-dk); margin: 0 0 4px; }
.reader-date { margin: 0 0 20px; font-size: 14px; }
.modal-close {
  position: absolute; top: 14px; right: 18px;
  font-size: 26px; line-height: 1;
  color: var(--ink-soft); background: transparent; border: none;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { color: var(--accent-dk); background: var(--beige-200); }

/* ============================================================
   Medium-style editor
   ============================================================ */
.editor-backdrop {
  position: fixed; inset: 0;
  background: rgba(58, 49, 40, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 30px 16px; overflow-y: auto; z-index: 70;
  animation: fade 0.2s ease;
}
.editor-panel {
  background: var(--paper);
  border: 1px solid var(--beige-400);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(58,49,40,.4);
  max-width: 760px; width: 100%;
  padding: 22px 30px 26px;
  display: flex; flex-direction: column;
}
.editor-topbar { display: flex; align-items: center; justify-content: space-between; }
.editor-topbar h2 { font-family: var(--display); font-size: 24px; color: var(--accent-dk); margin: 0; }
.editor-close { font-size: 26px; }

.editor-title {
  width: 100%;
  font-family: var(--display);
  font-size: 30px;
  font-weight: 600;
  color: var(--accent-dk);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--beige-300);
  padding: 12px 2px;
  margin: 8px 0 6px;
}
.editor-title::placeholder { color: var(--beige-400); }
.editor-title:focus { outline: none; border-bottom-color: var(--accent); }

/* toolbar */
.toolbar {
  position: sticky; top: 0;
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px;
  padding: 8px 0;
  background: var(--paper);
  border-bottom: 1px solid var(--beige-300);
  z-index: 2;
}
.tb-btn {
  font-family: var(--serif);
  font-size: 16px;
  min-width: 38px; height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  display: inline-flex; align-items: center; justify-content: center;
}
.tb-btn:hover { background: var(--beige-200); }
.tb-btn.is-active { background: var(--beige-300); border-color: var(--beige-400); color: var(--accent-dk); }
.tb-sep { width: 1px; height: 24px; background: var(--beige-300); margin: 0 4px; }

/* writing surface */
.editor-body {
  min-height: 300px;
  margin-top: 14px;
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.8;
  color: var(--ink);
  outline: none;
}
.editor-body:empty::before {
  content: attr(data-placeholder);
  color: var(--beige-400);
  font-style: italic;
}
/* apply the same rich styling inside the editor */
.editor-body p { margin: 0 0 .8em; }
.editor-body h2 { font-family: var(--display); font-size: 30px; color: var(--accent-dk); margin: .6em 0 .3em; }
.editor-body h3 { font-family: var(--display); font-size: 24px; color: var(--accent-dk); margin: .6em 0 .3em; }
.editor-body blockquote {
  margin: .8em 0; padding: 6px 18px;
  border-left: 4px solid var(--accent);
  color: var(--ink-soft); font-style: italic;
  background: rgba(216,195,156,.15);
}
.editor-body ul, .editor-body ol { padding-left: 1.6em; margin: 0 0 .8em; }
.editor-body a { color: var(--accent); text-decoration: underline; }

.editor-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-top: 20px; flex-wrap: wrap;
}
.editor-status { font-style: italic; color: var(--ink-soft); font-size: 15px; }
.editor-buttons { display: flex; gap: 10px; margin-left: auto; }

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 30px 20px 40px;
  color: var(--ink-soft);
  font-style: italic;
  font-size: 15px;
  border-top: 1px solid var(--beige-300);
  margin-top: 20px;
}

/* ============================================================
   Responsive — iPad / tablet
   ============================================================ */
@media (max-width: 1024px) {
  .page { padding: 26px 24px 60px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .editor-panel { max-width: 680px; }
}

/* iPad portrait & smaller tablets */
@media (max-width: 820px) {
  body { font-size: 18px; }
  .site-header { padding: 34px 20px 18px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .tb-btn { min-width: 42px; height: 42px; }   /* bigger touch targets */
  .modal, .editor-panel { padding: 30px 26px; }
}

/* ---------- Phone ---------- */
@media (max-width: 560px) {
  body { font-size: 17px; }
  .page { padding: 20px 14px 50px; }
  .site-header { padding: 26px 16px 14px; }
  .section-head { flex-direction: column; align-items: stretch; }
  .section-head .btn-primary { width: 100%; }
  .card-grid { grid-template-columns: 1fr; }
  .tabs { gap: 4px; }
  .tab { padding: 10px 16px; font-size: 17px; }

  .modal { padding: 26px 18px 30px; border-radius: 0; min-height: 100vh; }
  .modal-backdrop { padding: 0; }
  .modal h2 { font-size: 28px; }

  .editor-backdrop { padding: 0; }
  .editor-panel { border-radius: 0; min-height: 100vh; padding: 18px 16px 24px; }
  .editor-title { font-size: 26px; }
  .toolbar { gap: 2px; }
  .tb-btn { min-width: 40px; height: 44px; font-size: 15px; padding: 0 8px; }
  .editor-body { font-size: 18px; }
  .editor-actions { flex-direction: column; align-items: stretch; }
  .editor-buttons { margin-left: 0; }
  .editor-buttons .btn-primary, .editor-buttons .btn-ghost { flex: 1; }
}

/* respect notches on iPhone/iPad */
@supports (padding: max(0px)) {
  .editor-panel, .modal {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
}
