/* ================= Base styles (global) ================= */
body {
  background: #fbfbd7;
  color: #222;
  font-family: monospace;
  line-height: 1.65;
  margin: 0;
  padding: 2em;
}

/* Headings */
h1 {
  font-family: Arial, sans-serif;
  font-size: 2.2em;
  margin-top: 0;
  font-weight: normal;
}

h2, h3, h4 {
  font-family: "Courier New", Courier, monospace;
  margin-top: 2em;
  margin-bottom: 0.5em;
  font-weight: bold;
  line-height: 1.2;
}

/* Paragraphs */
p {
  font-size: 1em;
  margin-bottom: 1.2em;
}

/* Links */
a {
  color: #000;
  text-decoration: none;
  border-bottom: 1px dotted #aaa;
}

a:hover {
  color: #000;
  border-bottom: 1px solid #333;
}

/* Code blocks */
code, pre {
  font-family: "Courier New", Courier, monospace;
  background: #fbfbd7;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-size: 0.95em;
}

pre {
  padding: 1em;
  overflow-x: auto;
  border: 1px solid #ddd;
  border-radius: 5px;
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5em auto;
  border: 1px solid #eee;
  border-radius: 4px;
}

/* ================= Buttons (global) ================= */
button {
  background: black;
  color: white;
  border: 2px solid black;
  padding: 0.5em 1em;
  font-family: monospace;
  font-size: 1em;
  font-weight: normal;
  cursor: pointer;
}

button:hover {
  background: black;
  color: white;
}

/* Icon-style buttons (undo/redo) */
button.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid black;
  font-size: 1.2rem;
  background: black;
  color: white;
}

/* ================= Topbar (universal) ================= */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1em;
  gap: 1em;
}

#topbar h1 {
  flex: 1;
  text-align: center;
  margin: 0;
  font-size: 1.8em;
  font-weight: normal;
}

#topbar-left {
  flex: 0 0 auto;
}

#topbar-right {
  display: flex;
  gap: 0.5em;
  flex: 0 0 auto;
}

#topbar-left button,
#topbar-right button {
  background: black;
  color: white;
  border: 2px solid black;
  padding: 0.5em 1em;
  font-family: monospace;
  font-size: 1em;
  font-weight: normal;
  cursor: pointer;
}

#topbar-left button:hover,
#topbar-right button:hover {
  background: black;
  color: white;
}

/* ================= Filter buttons ================= */
.filter-btn {
  background: black;
  color: white;
  border: 2px solid black;
  padding: 0.5em 1em;
  font-family: monospace;
  font-size: 1em;
  font-weight: normal;
  cursor: pointer;
  margin-right: 0.5em;
}

.filter-btn:hover {
  background: black;
  color: white;
}

.filter-btn.active {
  background: white;
  color: black;
  font-weight: normal;
}

/* ================= Modals ================= */
#authModal, #loginModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 1em;
  box-sizing: border-box;
}

#authModalContent {
  background: white;
  padding: 2em;
  max-width: 400px;
  width: 100%;
  border-radius: 10px;
  position: relative;
  box-sizing: border-box;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

#authModalContent input {
  width: 100%;
  padding: 0.8em;
  margin-bottom: 1em;
  font-size: 1em;
  box-sizing: border-box;
}

#authModalContent button {
  width: 100%;
  padding: 0.8em;
  margin-bottom: 0.5em;
  font-size: 1em;
  cursor: pointer;
  border: 2px solid black;
  background: black;
  color: white;
  border-radius: 5px;
  font-weight: normal;
}

#authModalContent button:hover {
  background: black;
  color: white;
}

#closeAuthModal, #closeModal {
  position: absolute;
  top: 0.5em;
  right: 0.5em;
  width: auto;
  padding: 0.2em 0.5em;
  font-size: 1.2em;
  background: black;
  color: white;
  border-radius: 50%;
  border: 2px solid black;
}

#closeAuthModal:hover, #closeModal:hover {
  background: black;
  color: white;
}

@media (max-width: 350px) {
  #authModalContent {
    padding: 1em;
  }
  #authModalContent input,
  #authModalContent button {
    font-size: 0.9em;
    padding: 0.6em;
  }
}

/* ================= Page-specific ================= */

/* --- Feed page --- */
body.feed-page {
  max-width: 1200px;
  margin: auto;
  padding: 1em;
}

body.feed-page #controls {
  margin-bottom: 1em;
}

body.feed-page #feed {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 10px;
}

body.feed-page .post {
  width: 100%;
  max-width: 600px;
  height: auto;
  margin: auto;
}

body.feed-page .post img {
  width: 100%;
  display: block;
}

body.feed-page .post .words {
  display: none;
  font-size: 0.9em;
  margin-top: 0.5em;
}

/* --- Create page --- */
body.create-page {
  max-width: 800px;
  margin: auto;
  padding: 1em;
}

body.create-page #canvasContainer {
  width: 100%;
  max-width: 800px;
  border: 2px solid #000;
  margin: 1em 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fbfbd7;
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
}

body.create-page canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  image-rendering: optimizeSpeed;
  background: transparent;
}

body.create-page .controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.5em;
}

body.create-page .tool-buttons {
  display: flex;
  gap: 4px;
  align-items: center;
}

body.create-page .tool-btn {
  font-size: 1.2rem;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: 2px solid black;
  background: white;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  font-weight: normal;
}

body.create-page .tool-btn.selected {
  background: black;
  color: white;
}

body.create-page .tool-btn:hover {
  background: white;
  color: black;
}

body.create-page .tool-btn.selected:hover {
  background: black;
  color: white;
}

body.create-page .brush-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 160px;
}

body.create-page input[type="range"] {
  vertical-align: middle;
}

body.create-page label {
  font-size: 0.9em;
  display: block;
  margin-top: 0.75em;
}

body.create-page input[type="text"], 
body.create-page textarea {
  width: 100%;
  margin-top: 0.5em;
  font-family: monospace;
}

body.create-page textarea {
  height: 120px;
}

@media (max-width: 420px) {
  body.create-page .controls { gap: 6px; }
  body.create-page .brush-wrap { width: 100%; justify-content: space-between; }
}

/* --- Search page --- */
body.search-page {
  max-width: 800px;
  margin: auto;
  padding: 1em;
}

/* --- Settings page --- */
body.settings-page {
  max-width: 800px;
  margin: auto;
  padding: 1em;
}

/* ================= Cursor preview ================= */
#cursorPreview {
  position: fixed;
  pointer-events: none;
  border: 1px solid black;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  display: none;
  box-sizing: border-box;
}

/* ================= Responsive topbar ================= */
@media (max-width: 600px) {
  #topbar {
    flex-wrap: wrap;
  }
  
  #topbar h1 {
    order: 1;
    flex: 1 0 100%;
    text-align: center;
    margin-bottom: 0.5em;
  }
  
  #topbar-left {
    order: 2;
  }
  
  #topbar-right {
    order: 3;
    margin-left: auto;
  }
}