/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-text: #1e1e2e;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-danger: #ef4444;
  --color-success: #22c55e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --font: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.6;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  border: none;
  border-radius: var(--radius);
  padding: .5rem 1.2rem;
  transition: background .15s, opacity .15s;
}
button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

input, textarea {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  outline: none;
  width: 100%;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color .15s;
}
input:focus, textarea:focus {
  border-color: var(--color-primary);
}

/* ===== Layout ===== */
#app {
  min-height: 100vh;
}

.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* ===== Home ===== */
.home-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  max-width: 420px;
  margin: 4rem auto 0;
}

.home-card h1 {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: .4rem;
  color: var(--color-text-muted);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  width: 100%;
  padding: .65rem;
  font-size: 15px;
  margin-top: .25rem;
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }

.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  width: 100%;
  padding: .65rem;
  font-size: 15px;
  margin-top: .5rem;
}
.btn-secondary:hover:not(:disabled) { background: #f0f0ff; }

.error-msg {
  color: var(--color-danger);
  font-size: 13px;
  margin-top: .4rem;
}

.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1.25rem 0;
}

/* ===== Thread header ===== */
.thread-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.thread-header h2 {
  font-size: 1rem;
  font-weight: 600;
  flex: 1 1 auto;
  color: var(--color-text-muted);
}

.thread-header h2 span {
  color: var(--color-text);
  font-family: monospace;
  font-size: 1.1rem;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: .35rem .75rem;
  font-size: 13px;
}
.btn-icon:hover { background: var(--color-bg); }

/* ===== Post list ===== */
.post-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding-bottom: 10rem; /* space for fixed form */
}

/* ===== Post item ===== */
.post-item {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.post-meta {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  margin-bottom: .4rem;
  flex-wrap: wrap;
}

.post-no {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-primary);
  background: #ede9fe;
  border-radius: 4px;
  padding: 0 5px;
}

.post-author {
  font-weight: 600;
  font-size: 14px;
}

.post-date {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-left: auto;
}

.post-body {
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
}

/* attachments */
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .75rem;
}

.attachment-img {
  max-width: 200px;
  max-height: 160px;
  border-radius: 6px;
  cursor: pointer;
  object-fit: cover;
  border: 1px solid var(--color-border);
}

.attachment-video {
  max-width: 320px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

/* reactions */
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .75rem;
}

.reaction-btn {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: .2rem .65rem;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: .3rem;
  transition: background .15s, border-color .15s;
}
.reaction-btn:hover { background: #e0e7ff; border-color: var(--color-primary); }
.reaction-btn.optimistic { border-color: var(--color-primary); background: #e0e7ff; }

.reaction-count {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* ===== Post form (fixed bottom) ===== */
.post-form-wrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
  z-index: 100;
}

.post-form-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.post-form-row {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
}

.post-form-row textarea {
  flex: 1;
  resize: none;
  min-height: 60px;
  max-height: 160px;
}

.char-counter {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: right;
}
.char-counter.over { color: var(--color-danger); }

.btn-submit {
  background: var(--color-primary);
  color: #fff;
  padding: .5rem 1.1rem;
  white-space: nowrap;
}
.btn-submit:hover:not(:disabled) { background: var(--color-primary-hover); }

.btn-attach {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  padding: .45rem .75rem;
  font-size: 18px;
  line-height: 1;
}
.btn-attach:hover { border-color: var(--color-primary); color: var(--color-primary); }

/* ===== Attachment picker ===== */
.attachment-picker {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: center;
}

.attachment-thumb {
  position: relative;
  width: 56px;
  height: 56px;
}

.attachment-thumb img,
.attachment-thumb video {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

.attachment-thumb .remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--color-danger);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  line-height: 1;
}

.progress-bar-wrap {
  width: 100%;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 2px;
}

.progress-bar {
  height: 100%;
  background: var(--color-primary);
  transition: width .1s;
}

/* ===== Spinner ===== */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: .4rem;
  z-index: 200;
  pointer-events: none;
}

.toast {
  background: #1e1e2e;
  color: #fff;
  border-radius: var(--radius);
  padding: .6rem 1.2rem;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  animation: toastIn .2s forwards, toastOut .3s 2.7s forwards;
  white-space: nowrap;
}

.toast.toast-error { background: var(--color-danger); }
.toast.toast-success { background: var(--color-success); }

@keyframes toastIn {
  to { opacity: 1; }
}
@keyframes toastOut {
  to { opacity: 0; }
}

/* ===== Name row ===== */
.form-name-row {
  display: flex;
  gap: .5rem;
  align-items: center;
}

.form-name-row input {
  flex: 1;
  max-width: 180px;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .post-date { display: none; }
  .attachment-img { max-width: 140px; }
  .attachment-video { max-width: 240px; }
}
