/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1410;
  --surface: #2a2018;
  --text: #e8dcc8;
  --text-dim: #8a7a62;
  --accent: #c8a96e;
  --shelf-wood: #5c3d1e;
  --shelf-wood-dark: #3d2810;
  --shadow: rgba(0,0,0,0.5);
}

html { height: 100%; }

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid #3a2e20;
  background: var(--surface);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

header h1 {
  font-size: 1.5rem;
  font-weight: normal;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.header-actions { display: flex; gap: 10px; }

/* ── View toggle ── */
.view-toggle {
  display: flex;
  background: #1a1410;
  border: 1px solid #3a2e20;
  border-radius: 3px;
  overflow: hidden;
}

.view-btn {
  background: none;
  border: none;
  border-radius: 0;
  color: var(--text-dim);
  padding: 2px 7px;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.view-btn:hover { background: #2a2018; color: var(--text); opacity: 1; }
.view-btn.active { background: #2a2018; color: var(--accent); }

/* ── Buttons ── */
button {
  cursor: pointer;
  border: none;
  border-radius: 4px;
  padding: 7px 16px;
  font-family: inherit;
  font-size: 0.85rem;
  transition: opacity 0.15s;
}
button:hover { opacity: 0.85; }

.btn-primary   { background: var(--accent); color: #1a1410; font-weight: bold; }
.btn-secondary { background: #3a2e20; color: var(--text); }
.btn-success   { background: #4a7c4a; color: #fff; }
.btn-danger    { background: #7c3a3a; color: #fff; }

/* ── Shelf strip ── */
#shelf-zone {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid #3a2e20;
  background: var(--surface);
  flex-shrink: 0;
}

.shelf-content-row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  flex: 1;
}

.shelf-books {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
}

.shelf-plank {
  height: 14px;
  width: 100%;
  display: block;
  flex-shrink: 0;
}

.shelf-zone-label {
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 6px 16px 2px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.shelf-sort-label {
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  opacity: 0.7;
}

#shelf-order-toggle {
  display: flex;
  background: #1a1410;
  border: 1px solid #3a2e20;
  border-radius: 3px;
  overflow: hidden;
}

.shelf-order-btn {
  background: none;
  border: none;
  border-radius: 0;
  color: var(--text-dim);
  padding: 2px 7px;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.shelf-order-btn:hover { background: #2a2018; color: var(--text); opacity: 1; }
.shelf-order-btn.active { background: #2a2018; color: var(--accent); }

#shelf-svg {
  width: 100%;
  height: 100px;
  display: block;
}

.shelf-books.drop-active {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: rgba(200,169,110,0.06);
  transition: background 0.1s, box-shadow 0.1s;
}

#zone-wontdo.drop-active {
  box-shadow: inset 0 0 0 2px #7c3a3a;
  background: rgba(124,58,58,0.10);
  transition: background 0.1s, box-shadow 0.1s;
}

/* ── Main layout ── */
main {
  display: grid;
  grid-template-columns: 1fr 2fr;
  flex: 1;
  min-height: 0;
}

.zone {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.zone-label {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 14px 20px 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

#pile-svg, #wontdo-svg {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
  touch-action: none;
}

#shelf-svg {
  touch-action: none;
}

/* SVG book cursor */
.book-group { cursor: grab; }

/* ── Modals ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 50;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}

.modal.hidden { display: none; }
#modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid #3a2e20;
  border-radius: 8px;
  padding: 28px 32px;
  min-width: 380px;
  max-width: 480px;
  pointer-events: all;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
}

.modal-box h2 {
  font-size: 1.1rem;
  font-weight: normal;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: 20px;
}

.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.modal-box input[type="text"],
.modal-box select {
  background: #1a1410;
  border: 1px solid #3a2e20;
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s;
}

.modal-box input[type="text"]:focus,
.modal-box select:focus { border-color: var(--accent); }

.timing-toggle {
  display: flex;
  background: #1a1410;
  border: 1px solid #3a2e20;
  border-radius: 4px;
  overflow: hidden;
  width: fit-content;
}

.timing-btn {
  background: none;
  border: none;
  border-radius: 0;
  color: var(--text-dim);
  padding: 5px 18px;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  transition: background 0.15s, color 0.15s;
}

.timing-btn:hover { background: #2a2018; color: var(--text); opacity: 1; }
.timing-btn.selected { background: #2a2018; color: var(--accent); }

.size-picker { display: flex; flex-wrap: wrap; gap: 6px; }

.size-btn {
  background: #1a1410;
  border: 1px solid #3a2e20;
  color: var(--text-dim);
  padding: 5px 10px;
  font-size: 0.78rem;
  border-radius: 3px;
  font-family: inherit;
}

.size-btn.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(200,169,110,0.1);
}

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

/* ── Categories list ── */
#categories-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  max-height: 220px;
  overflow-y: auto;
}

.category-row { display: flex; align-items: center; gap: 10px; }
.category-row input[type="text"] { flex: 1; }
.category-row input[type="color"] {
  width: 36px; height: 28px; border: none;
  border-radius: 3px; cursor: pointer; padding: 0; background: none;
}
.category-row .btn-danger { padding: 5px 10px; font-size: 0.75rem; }

.category-select-row { display: flex; gap: 6px; align-items: center; }
.category-select-row select { flex: 1; }

.btn-new-cat {
  background: #3a2e20;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  width: 28px; height: 28px;
  font-size: 1.1rem; line-height: 1; padding: 0; flex-shrink: 0;
}

.inline-new-cat { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.inline-new-cat.hidden { display: none; }
.inline-new-cat input[type="text"] {
  flex: 1; background: #1a1410; border: 1px solid var(--accent);
  border-radius: 4px; color: var(--text); font-family: inherit;
  font-size: 0.9rem; padding: 6px 8px; outline: none;
}
.inline-new-cat input[type="color"] {
  width: 32px; height: 28px; border: none;
  border-radius: 3px; cursor: pointer; padding: 0; background: none; flex-shrink: 0;
}
.inline-new-cat .btn-primary { flex-shrink: 0; }

.new-category-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.new-category-row input[type="text"] {
  flex: 1; background: #1a1410; border: 1px solid #3a2e20;
  border-radius: 4px; color: var(--text); font-family: inherit;
  font-size: 0.9rem; padding: 7px 10px; outline: none;
}
.new-category-row input[type="color"] {
  width: 36px; height: 32px; border: none;
  border-radius: 3px; cursor: pointer; padding: 0; background: none;
}

/* ── Pomodoro clock (on shelf) ── */
#pomodoro-widget { flex-shrink: 0; margin-right: 10px; }

#pom-face-wrap {
  position: relative;
  width: 90px;
  height: 120px;
}

#pomodoro-svg {
  display: block;
  position: absolute;
  top: 0; left: 0;
  cursor: pointer;
}

#pomodoro-plaque {
  position: absolute;
  left: 12px; right: 12px;
  top: 80px;
  text-align: center;
  font-size: 0.52rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  line-height: 1.4;
  transition: color 0.15s;
}
#pomodoro-plaque:hover                        { color: var(--accent); }
#pomodoro-plaque.running                      { color: #c87070; font-size: 0.8rem; letter-spacing: 0.03em; }
#pomodoro-plaque.paused                       { font-size: 0.8rem; letter-spacing: 0.03em; }
#pomodoro-plaque.done                         { color: var(--accent); animation: pom-pulse 1s infinite; }

@keyframes pom-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

#pom-controls {
  position: absolute;
  left: 0; right: 0;
  top: 103px;
  display: flex;
  justify-content: center;
  gap: 8px;
}
#pom-controls.hidden { display: none; }
#pom-controls button {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
  opacity: 0.65;
  transition: color 0.15s, opacity 0.15s;
}
#pom-controls button:hover { opacity: 1; }
#pom-cancel-btn:hover { color: #c87070; }

#pomodoro-picker {
  position: absolute;
  top: 122px;
  left: 0;
  z-index: 150;
  background: var(--surface);
  border: 1px solid #3a2e20;
  border-radius: 4px;
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 90px;
}
#pomodoro-picker.hidden { display: none; }

.pom-presets { display: flex; gap: 4px; }

.pom-preset {
  flex: 1;
  background: #1a1410;
  border: 1px solid #3a2e20;
  color: var(--text-dim);
  padding: 3px 0;
  font-size: 0.7rem;
  border-radius: 3px;
  font-family: inherit;
}
.pom-preset.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(200,169,110,0.1);
}
.pom-preset:hover { opacity: 0.85; }

#pom-start {
  width: 100%;
  background: var(--accent);
  color: #1a1410;
  font-weight: bold;
  padding: 4px 0;
  font-size: 0.75rem;
  border-radius: 3px;
  font-family: inherit;
  border: none;
}

/* ── Minimal theme ── */
body.theme-minimal {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-dim: #777777;
  --accent: #333333;
  --shadow: rgba(0,0,0,0.08);
}

body.theme-minimal main                { background: var(--surface); }
body.theme-minimal header              { border-bottom-color: #dddad4; }
body.theme-minimal #shelf-zone        { border-bottom-color: #dddad4; }
body.theme-minimal #shelf-order-toggle { background: #f0ece4; border-color: #d4d0c8; }
body.theme-minimal .shelf-order-btn:hover  { background: #e8e4dc; }
body.theme-minimal .shelf-order-btn.active { background: #e8e4dc; }
body.theme-minimal .view-toggle        { background: #f0ece4; border-color: #d4d0c8; }
body.theme-minimal .view-btn:hover     { background: #e8e4dc; }
body.theme-minimal .view-btn.active    { background: #e8e4dc; }
body.theme-minimal .btn-secondary      { background: #ebe7df; color: #333333; }
body.theme-minimal .modal-box          { border-color: #dddad4; }
body.theme-minimal .modal-box input[type="text"],
body.theme-minimal .modal-box select   { background: #f5f3ef; border-color: #d4d0c8; color: #1a1a1a; }
body.theme-minimal .modal-box input[type="text"]:focus,
body.theme-minimal .modal-box select:focus { border-color: #333333; }
body.theme-minimal .timing-toggle      { background: #f0ece4; border-color: #d4d0c8; }
body.theme-minimal .timing-btn:hover   { background: #e8e4dc; }
body.theme-minimal .timing-btn.selected { background: #e8e4dc; color: #333333; }
body.theme-minimal .size-btn           { background: #f0ece4; border-color: #d4d0c8; }
body.theme-minimal .size-btn.selected  { background: rgba(0,0,0,0.06); border-color: #333333; color: #333333; }
body.theme-minimal .inline-new-cat input[type="text"],
body.theme-minimal .new-category-row input[type="text"] { background: #f5f3ef; color: #1a1a1a; border-color: #d4d0c8; }
body.theme-minimal .btn-new-cat        { background: #ebe7df; color: #333333; border-color: #333333; }
body.theme-minimal .btn-primary        { color: #ffffff; }
body.theme-minimal #pom-start          { color: #ffffff; }
body.theme-minimal .shelf-books.drop-active {
  box-shadow: inset 0 0 0 2px #333333;
  background: rgba(0,0,0,0.04);
}
body.theme-minimal #pomodoro-plaque    { color: #777777; }
body.theme-minimal #pomodoro-picker    { border-color: #d4d0c8; }
body.theme-minimal .pom-preset         { background: #f0ece4; border-color: #d4d0c8; }
body.theme-minimal .pom-preset.selected { background: rgba(0,0,0,0.05); border-color: #333333; color: #333333; }

/* ── Mobile ── */
@media (max-width: 700px) {
  header {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  header h1 { font-size: 1.1rem; }
  .header-actions { gap: 6px; flex-wrap: wrap; }
  .header-actions button { padding: 5px 10px; font-size: 0.78rem; }

  #shelf-svg { height: 80px; }
  #pomodoro-widget { display: none; }

  main {
    display: flex;
    flex-direction: column;
  }
  #zone-pile   { order: 1; flex: 1; min-height: 0; }
  #zone-wontdo { order: 2; height: 120px; flex-shrink: 0; border-top: 1px solid #3a2e20; }
  body.theme-minimal #zone-wontdo { border-top-color: #dddad4; }

  .modal-box {
    min-width: 0;
    width: calc(100vw - 32px);
    max-width: none;
    padding: 20px 16px;
  }

  .modal-actions { gap: 6px; }
  .modal-actions button { padding: 6px 10px; font-size: 0.8rem; }
}
